KubeJS (Old)

KubeJS (Old)

3M Downloads

.getInventory() breaks in 1.18

Qualia765 opened this issue · 2 comments

commented

System info

I am using windows.
Mods on 1.18 version:

Forge - 39.0.8
kubejs-forge-1801.4.1-build.271.jar
architectury-3.4.9.jar
create-mc1.18.1_v0.4c.jar
flywheel-forge-1.18-0.5.1.jar
jei-1.18.1-9.2.1.69.jar
kubejs-create-1801.2.0-build.14.jar
rhino-forge-1800.1.7-build.94.jar
Xaeros_Minimap_21.23.1_Forge_1.18.jar
XaerosWorldMap_1.19.1_Forge_1.18.jar

Mods on 1.16 version:

Forge - 36.2.20
architectury-1.28.48.jar
create-mc1.16.5_v0.3.2g.jar
flywheel-1.16-0.2.5.jar
jei-1.16.5-7.7.1.144.jar
kubejs-forge-1605.3.19-build.258.jar
kubejs-create-1605.1.4-build.12.jar
rhino-forge-1605.1.5-build.75.jar

I was testing this on linux mint on 1.18 with about the same mods and I think it was working, however i am have not conduced any testing since knowledge of this bug.

Test

If I use in a script in the server_scripts folder

onEvent('block.left_click', event => {
	if (event.getFacing() == 'up')//this is to prevent the trigger upon release of the mouse
		return
    console.log('word1')
    console.log(event.block.getInventory(Direction.UP))
    console.log('word2')
})

Then in game, I left click the top face of a grass block then a chest with a singular iron block in the center.

What I expect (what correctly occurs on 1.16):

In the server log:

[22:09:44] [INFO ] server_scripts:recipes.js:4: word1
[22:09:44] [INFO ] server_scripts:recipes.js:5: null
[22:09:44] [INFO ] server_scripts:recipes.js:6: word2
[22:09:47] [INFO ] server_scripts:recipes.js:4: word1
[22:09:47] [INFO ] server_scripts:recipes.js:5: [Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, 'minecraft:iron_block', Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty, Item.empty] [dev.latvian.kubejs.item.InventoryJS]
[22:09:47] [INFO ] server_scripts:recipes.js:6: word2

What occurs in 1.18

[22:14:10] [INFO ] server_scripts:recipes.js:534: word1
[22:14:10] [INFO ] server_scripts:recipes.js:536: word2
[22:14:10] [INFO ] server_scripts:recipes.js:535: null
[22:14:13] [INFO ] server_scripts:recipes.js:534: word1

Conclusion

It appears as though that when ever .getInventory() is run on a tile entity it stops the remainder of the script from functioning.

commented

(1) The fact that it stops printing after console.log(event.block.getInventory(Direction.UP)) is because getInventory may return null (which is different from the string "null", mind you, which is why console.log('' + event.block.getInventory(Direction.UP)) for instance worked properly), which I'm assuming neither the logger nor ServerJS.tell (which I used for testing instead) properly handle.

(2) Currently, the left click event on Forge seems to be getting fired twice (actually in three different scenarios, but for the purposes of this issue, only two cases really matter) — once when the player starts breaking a block, and once when they stop / "abort". This is what's causing the duplicate events here; and I'm not entirely sure whether this is intentional on Forge's part or not, since they don't offer mods any way to discern which of the two actions the player is performing.

(3) Generally speaking, you should be checking whether your event is firing on the logical server by using event.server (check if this is null or not), the only reason that checking for a direction ""works"" here is because the abort block destroy packet triggering the event is always sent with Direction.DOWN

commented

Still an issue i see