KubeJS-Mods / KubeJS

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

Block Entity inventory inputfilter dont work with custom items #801

Open DevDyna opened 8 months ago

DevDyna commented 8 months ago

Minecraft Version

1.20.1

KubeJS Version

kubejs-forge-2001.6.4-build.138

Rhino Version

rhino-forge-2001.2.2-build.18

Architectury Version

architectury-9.2.14-forge

Forge/Fabric Version

Forge - 47.2.20

Describe your issue

when used on .inventory() a custom item as input filter , it deny all items included input filter script used:

StartupEvents.registry("item", (event) => {
  event.create("kubejs:star")
})
StartupEvents.registry("block", (event) => {
  event.create('block_id').blockEntity((be) => {
      be.inventory(9, 1, 'kubejs:star');
      be.rightClickOpensInventory();
  })
})

Crash report/logs

No response

ChiefArug commented 8 months ago

Looks like the callback gets called immediately, which causes the string to try resolve into an Item immediately, which fails to catch custom items (and probably most modded items too) cause the registry events are still processing. https://github.com/KubeJS-Mods/KubeJS/blob/d1aad04f13c69c1470b9dfab5c821f9fccf68e32/common/src/main/java/dev/latvian/mods/kubejs/block/BlockBuilder.java#L760-L765 To fix this the callback should be stored instead and only called when the block entity type is being created/registered (which is guaranteed to happen after item reg). It can't be called in block reg cause that happens before item reg (due to BlockItems needing a Block reference).