KubeJS

KubeJS

69M Downloads

NullPointerException might be thrown if you have event.remove/replaceItem. The more events, the higher the chance.

Waoweens opened this issue ยท 19 comments

commented

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

  1. Add the affected event into ServerEvents.recipes
  2. spam /reload
  3. you might get a NullPointerException
  4. add more affected events
  5. spam /reload
  6. repeat until the difference is noticable
  7. see that the chances of getting a NullPointerException is higher

Video

2022-11-04.23-09-09.mp4

Crash report/logs

https://mclo.gs/HnCl12Y

commented

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)
commented

Is this with just KubeJS + dependencies?

commented

Yes, no other mods

commented

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

commented

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

commented

...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);
}
commented

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")

iloil

The log also seems to showing absolutely nothing for the corresponding lines, as if kubejs is skipping them.

commented

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.

commented

I forgot to say, this ended up working (until the next problem):

ul;o;

commented

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?

commented

After several hours editing recipes, looking for nonsensical causes of the bugs, and failing at dealing with too many wood types and unusable tags... We found the most elegant and also stupid solution:

yiluilty

"It just works."

Thanks to Kanzaji in discord for helping with all this.

commented

Was this issue ever addressed... or even looked at?

commented

Ah, sems like it cannot be disabled on 1.18.

commented

Soo .
Is it fcked or can i do something else idk ?

commented

Soo . Is it fcked or can i do something else idk ?

There are some workarounds above, but that's probably about it. :/

commented

Soo . Is it fcked or can i do something else idk ?

There are some workarounds above, but that's probably about it. :/

Thing is it doesnt just error for me it kicks the players ( the devs for now ) when reloading

The recipe still works but players get kicked

Error message is inconsistent sometimes NullPOinter sometimes concurrent

commented

are you gonna fix this like ever ?

commented

You can disable concurrent recipe stuff in kubejs/config/common.properties

commented

You can disable concurrent recipe stuff in kubejs/config/common.properties

I only have these :

#KubeJS Common Properties
#Sat Dec 07 19:18:28 CET 2024
announceReload=true
debugInfo=false
disableClassFilter=false
hideServerScriptErrors=false
packmode=default
printRemappedClasses=false
serverOnly=false

and these for client

#KubeJS Client Properties
#Fri Dec 06 23:26:10 CET 2024
backgroundColor=2E3440
barBorderColor=ECEFF4
exportAtlases=false
menuBackgroundBrightness=64
disableRecipeBook=false
title=
barColor=ECEFF4
overrideColors=false
fmlLogColor=ECEFF4
showTagNames=false
fmlMemoryColor=ECEFF4
menuBackgroundScale=32.0
menuInnerBackgroundBrightness=32

('m in 1802 version)