Querz / mcaselector

A tool to select chunks from Minecraft worlds for deletion or export.
MIT License
3.26k stars 177 forks source link

A non-null return value causes custom NBT change script to fail to run #506

Open Cynthia7979 opened 2 weeks ago

Cynthia7979 commented 2 weeks ago

Describe the bug It seems that apply(ChunkData data), before(), and after() will not be run at all if anything is returned by one of them.

To Reproduce

  1. Open any valid Minecraft save
  2. Select any chunk
  3. Go to 'Tools > Change fields'
  4. Click on 'Script'
  5. Edit the script so any of the three functions returns something other than null. For example: return 1;
  6. Click 'OK'
  7. No confirmation dialog appears, nor is any log written to the log file (even with debug messages enabled). No chunk data is changed.

Expected behavior Depending on the nature of what caused the bug, I would expect either of these behaviors:

  1. The program executes all of the methods regularly even if a non-null value was returned by any of the methods. Or,
  2. If any return statement is entered into any of the functions, then after clicking on 'OK' while having the "Script" tab open, an error should be shown in a message dialog and be printed to the log file. The error message should indicate that the code was not executed because it contained a return statement.

Screenshots and other files Screenshots and log will probably not tell much since the bug is the absence of log or error message. Here's them anyway:

mcaselector.log image image image image mcaselector.log

Environment (please complete the following information):

Additional context Would greatly appreciate it if there can be some sort of documentation for modifying chunk NBT via custom script. The Custom field is helpful but does not allow importing libraries, and I still haven't figured out how you're supposed to use the Script field yet 😅

arvitus commented 2 days ago

First of all, this is a user error :) If a function, that is supposed to return nothing, returns something nevertheless, the code won't compile and therefore cannot be executed. I don't really think a warning is needed here as this is just based on wrong syntax assumptions, but maybe it would help some people.

Sadly there is not much documentation about the custom filter scripts yet. Apart from the custom filter tutorial I wrote a while back there is barely any, if not none. But I created a repo with some useful examples and am planning to add more filters over time and make it a place for everyone to share their examples. Currently there are a few examples for filters and modifiers. You can check them out here. And if you still need help, you can check out the Discord Server and ask for help there.

Hope that helps :)

Cynthia7979 commented 2 days ago

Thanks! The custom filter tutorial was of some help, though it does not fully apply to NBT change use cases. I will check out the examples you linked!