NullPointerException might be thrown if you have event.remove/replaceItem. The more events, the higher the chance.
Waoweens opened this issue ยท 12 comments
Minecraft Version
1.19.2
KubeJS Version
1902.6.0-build.101
Rhino Version
1902.2.1-build.242
Architectury Version
6.3.49
Forge/Fabric Version
Fabric Loader 0.14.9, Fabric API 0.64.0+1.19.2
Describe your issue
If you have event.remove or event.replaceItem, there is a chance that a NullPointerException might be thrown. The more events you have, the more likely that a NullPointerException will be thrown.
(other events might be affected, haven't tested yet)
Steps to reproduce
- Add the affected event into ServerEvents.recipes
- spam
/reload
- you might get a NullPointerException
- add more affected events
- spam
/reload
- repeat until the difference is noticable
- see that the chances of getting a NullPointerException is higher
Video
2022-11-04.23-09-09.mp4
Crash report/logs
If the item does not exist, you can add a small delay (or slow down the program) and it will not throw the error
without delay:
// loop 1000 times
for(let i = 0; i < 1000; i++) {
// minecraft:abcd and minecraft:efgh are not real items
event.replaceInput({}, `minecraft:abcd`, `minecraft:efgh`)
}
// /reload
// Error occured while handling event 'ServerEvents.recipes': Wrapped java.lang.NullPointerException (server_scripts:file.js#line)
with delay:
// loop 1000 times
for(let i = 0; i < 1000; i++) {
// minecraft:abcd and minecraft:efgh are not real items
event.replaceInput({}, `minecraft:abcd`, `minecraft:efgh`)
// count to 100 for a little delay
for(let i = 0; i < 100; i++) { let b = i + 1 }
}
// /reload
// Reloaded with no KubeJS Errors!
but if the item does exist, it will throw the error regardless
// loop 1000 times
for(let i = 0; i < 1000; i++) {
/// minecraft:cobblestone and minecraft:stone are real items
event.replaceInput({}, `minecraft:cobblestone`, `minecraft:stone`)
// count to 100 for a little delay
for(let i = 0; i < 100; i++) { let b = i + 1 }
}
// /reload
// Error occured while handling event 'ServerEvents.recipes': Wrapped java.lang.NullPointerException (server_scripts:file.js#line)
Thank you for the debug code, this is most likely concurrency related issue, the recipe event tries to do things in parallel to speed up operations. I will see if changing to regular iteration fixes it
I've the same issue for the remove (I guess it's the same for replaceInput), it's caused while we pass only one filter.
For my example I try to remove all recipes that ouput a certain item, but it does not work until I specify another filter, like the type or the mod.
In my test, I didn't need to spam or to add many recipe remove like @Waoweens show us, just this only remove event.remove({ output: 'mythicmetals:steel_block' })
throw the error.
https://discord.com/channels/303440391124942858/986996456860839976/1042094158455771186
...but it does not work until I specify another filter, like the type or the mod.
@Zifiv thank you so much!!! this works perfectly (though it is still a workaround). we can finally release our modpack now
here are my modifications to the aof unification script
// line 183 or so
for (let id in itemIdToUnified) {
let unified = itemIdToUnified[id];
let idModid = id.split(":")[0];
let unifiedModid = unified.split(":")[0];
event.replaceInput({mod: idModid, mod: unifiedModid}, id, unified);
event.replaceOutput({}, id, unified);
}
I'm having issues in Create 1.19 even when a mod and type is specified. I've tried lots of combinations, none seem to work:
event.remove({id: "create:copper_sheet"})
event.replaceInput({mod: "create"}, "create:copper_sheet", "modern_industrialization:copper_plate")
event.replaceOutput({mod: "create"}, "create:copper_sheet", "modern_industrialization:copper_plate")
event.replaceOutput({id: "create:copper_ingot"}, "create:copper_sheet", "modern_industrialization:copper_plate")
event.replaceOutput({id: "create:pressing/copper_ingot"}, "create:copper_sheet", "modern_industrialization:copper_plate")
event.replaceOutput({type: "create:pressing"}, "create:copper_sheet", "modern_industrialization:copper_plate")
The log also seems to showing absolutely nothing for the corresponding lines, as if kubejs is skipping them.
FYI the above STILL doesn't work if the modpack loads quickly.
So, depending on how fast the computer runs and loading times, scripts can get loaded or not.
This is ridiculous.
After two months I'm still unable to edit recipes.
Every time I relaunch the game, KubeJS ignores the scripts, and only manually reloading them through "/kubejs reload server_scripts" loads them correctly.
Even something simple like this one fails to load:
event.remove({type: 'minecraft:crafting_shaped', output: '#minecraft:beds'})
event.replaceInput({type: "minecraft:crafting_shaped", output: "modern_industrialization:highly_advanced_machine_casing"}, "modern_industrialization:chromium_plate", "geghilarity:tungstensteel_plate")
event.replaceInput({type: "modern_industrialization:assembler", output: "modern_industrialization:highly_advanced_machine_casing"}, "modern_industrialization:chromium_plate", "geghilarity:tungstensteel_plate")
These scripts aren't getting loaded. What I'm supposed to do? @MaxNeedsSnacks
What does it mean "replaceInput / replaceOutput needs explicit integration in 1.19 to stop us from having to guess inputs / outputs from recipe JSONs directly" ?
What can I do to have scripts loaded properly. Modifying recipes is a basic functionality. What I'm supposed to do if they behave erratically and some at random don't get loaded?
Point me to some kind of solution that actually works, please.
Also, these same scripts load on 1.18.2, this is something that has been broken on 1.19.2 and has been ignored for two months. I understand I'm not ftb-something and I have no leverage, but then what?