KubeJS-Mods / KubeJS

https://kubejs.com
GNU Lesser General Public License v3.0
305 stars 90 forks source link

Script is grabbing the wrong array on launch, but works properly on reload #752

Closed aaronhowser1 closed 9 months ago

aaronhowser1 commented 9 months ago

Minecraft Version

1.19.2

KubeJS Version

kubejs-forge-1902.6.2-build.45

Rhino Version

rhino-forge-1902.2.2-build.280

Architectury Version

architectury-6.5.85-forge

Forge/Fabric Version

Forge 43.3.5

Describe your issue

So I have a lists.js that has the arrays customItems, jeiOnlyItems, jeiItems, and itemsToRemove.

The script emi.js makes a json file for use with the mod EMI. The json is output to the client.log for testing purposes.

image

That's definitely not right. Even aside from the fact that everything has repeating NBT and is air for some reason, all of those have the nbt hone/gild_5.

The thing is, that's in the added section of the json. That part of the json only gets things added to it via an iterator on customItems in emi.js. customItems doesn't HAVE anything with the nbt hone/gild_5 in it. jeiOnlyItems does. That array is never even LOADED by emi.js.

After doing F3+T however, it works fine! What gives? image

Crash report/logs

No response

pietro-lopes commented 9 months ago

Those consts are outside any event and it is too soon for modded items, hence why only Minecraft items shows up. You need to load it lazily or come up with some function to load those variable just before you use them

aaronhowser1 commented 9 months ago

Would replacing const thing = [] with function getThing() { return [] } work?

aaronhowser1 commented 9 months ago

It looks like it did! Tyvm

ChiefArug commented 9 months ago

KubeJS should log a warning about getting an ingredient before all items are registered. This is the second issue where this happened

aaronhowser1 commented 9 months ago

Technically isn't the NBT thing still an issue though? There's no reason it should have the gild whatever nbt in the add place since no item with that is in the list being iterated over for the add place

ChiefArug commented 9 months ago

I suspect that might be a mod mistakenly attaching nbt to empty items.

aaronhowser1 commented 9 months ago

That specific NBT is the NBT of one of the items in the other list, though. It's not just some arbitrary random NBT, it's a direct match

ChiefArug commented 9 months ago

Probably something being cached weirdly then. I don't think its much of an issue unless you can reproduce it in more normal circumstances.