Valid scripts not registering
Dandas52 opened this issue ยท 2 comments
Issue description
I have recently come across an issue where valid scripts are simply not applied in-game, despite not outputting any errors and initializing correctly. Currently, I have encountered this bug three times. In the first instance, scripts for Mystical Agriculture and Overloaded broke down completely, while other scripts were working fine. I was able to fix it in this case by backdating Crafttweaker to 7/1, which resolved the issue in later versions after re-updating.
In the second instance, my scripts for RFTools stopped functioning after all syntax errors were resolved. This is odd, as the incorrect script was clearly being read and outputting errors as expected, but once it was fixed, the recipe changes simply did not apply. I tried backdating again to fix it, but this did not work.
In the third instance, I have been consistently unable to use the jei.hideItem function, despite having the latest version of JEITweaker installed and ensuring that mods.jei was imported. This is true for all items, vanilla and modded - the script does not give an error, but neither does it hide the intended item.
Below, I have attached three logs. The first is the non-functioning script I am using, the second is the CraftTweaker log showing that the script is read and initialized properly, and the third is a /CT Recipes log which shows that despite this, my item (the RFTools Environmental Controller) keeps its default recipe.
Script: https://pastebin.com/YLZJ196E
Crafttweaker: https://pastebin.com/hdhfzCmJ
CT Recipes Log: https://pastebin.com/q03ksLDP
Steps to reproduce
No response
Script used
The crafttweaker.log file
Minecraft version
1.16
Forge version
36.1.32
CraftTweaker version
7.1.0.349 (But breaks on earlier versions as well)
Other relevant information
No response
The latest.log file
In your apotheosis.zs
file you are trying to access a recipe that does not exist:
[20:10:27.587][DONE][CLIENT][ERROR] No recipe found with name: "apotheosis:endshelf" in type: "crafting"
That exception stops script execution at that point in time, so most likely your other scripts that modify the recipe just haven't been loaded before it aborts there.
Sorry that this took so long to get to, basically the issue is that scripts run on both the Server thread and the Client thread.
In single player, if you change a value on the server thread, the client thread has that updated value (it's a singleton), so in this case, when the script is loaded on the server, it gets the recipe by the name, and replaces it, so it now has a different name.
Then when the script is loaded on the client, it can't find a recipe with that name because the server changed the name already.
In the future (1.17) scripts won't load twice in single player, making that change now would be a bit to much of a breaking change for my liking.
In the mean time, I have added:
#snip side server
#snip end
So you could do:
import crafttweaker.api.recipe.Replacer;
import crafttweaker.api.tag.MCTag;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.recipes.WrapperRecipe;
#snip side client
println("I am on the client!");
#snip end
#snip side server
println("I am on the server!");
Replacer.forRecipes(smoker.getRecipeByName("minecraft:baked_potato_from_smoking")).replace(<item:minecraft:potato>, <item:minecraft:diamond>).execute();
#snip end
println("I am on both!");
Which will fix your issue for now.
Anything in between a #snip side server
and #snip end
is removed from the script before it is loaded by the compiler.