KubeJS

KubeJS

69M Downloads

Unexpected behavior when modifying tool tier level

zaeonNineZero opened this issue ยท 5 comments

commented

Minecraft Version

1.19.2

KubeJS Version

kubejs-forge-1902.6.0-build.142, appeared as early as build.138

Rhino Version

rhino-forge-1902.2.2-build.264

Architectury Version

architectury-6.4.62-forge

Forge/Fabric Version

Forge 43.2.3

Describe your issue

Whenever a tool's mining/harvest level is modified in the Item Modification event, it is always set to mining level 2, or the same as an iron pickaxe.

This script aims to change the mining level of the golden pickaxe to 1, which should make it behave like a stone pickaxe:

ItemEvents.modification(event => {
  event.modify('minecraft:golden_pickaxe', item => {
    item.tier = tierOptions => {
	  tierOptions.level = 1
	}
  })
})

However in-game it behaves as though its mining level was set to 2, allowing it to mine gold, diamond, etc. As the KubeJS 6.0 wiki has no documentation on the item modification event, I cannot verify if this is a script error on my end, although it doesn't appear to be that way.

To reproduce

  1. Load the above script in KubeJS.
  2. Place a block of gold or diamond ore (or any other block that needs an iron tool).
  3. Give yourself a golden pickaxe and mine the block you placed. It will behave as though it were mined by an iron tool, including dropping its associated item loot.
commented

With some further testing, this also occurs with tierOptions.level = 3 as well, which normally should make the golden pickaxe from the code above able to mine obsidian and netherite. As above, this is not the case - it still behaves as though its mining level is set to 2.

commented

I have not. I tested it on build.142 and the issue persists. I am fairly certain that this is a bug and not a user-end coding error.

commented

were you able to figure out the solution?

commented

I ran into this problem too. Poking around in the source, it looks like there are 2 ways to do this in 1.19.2 build 142. The first is to modify the item inline:

ItemEvents.modification(event => {
	events.modify('minecraft:golden_pickaxe', item => {
		item.setTier(tier => {
			tier.level = 1
		})
	})
})

The other way is still semi-accurate on the wiki: where you create a tier template and then assign the template to the item:

ItemEvents.toolTierRegistry(event => {
	event.add('ironsuperspeed', tier => {
		tier.speed = 40
	})
})

ItemEvents.modification(event => {
	event.modify('minecraft:iron_pickaxe', item => {
		item.tier = 'ironsuperspeed'
	})
})

However, this 2nd approach is less than ideal, as it always copies the base values of an Iron-tier tool. As such, I have a request for the mod devs:

It would be great to be able to define the baseline tier to copy from when creating a new tool tier. Something like this would copy the baseline gold tier, but change the level it mines at:

ItemEvents.toolTierRegistry(event => {
	event.copy('stonegold', 'gold', tier => {
		tier.level = 1
	})
})
commented

Tried the first approach and it worked. Looks like either the syntax changed for KubeJS 6, or I interpreted the syntax wrong to begin with. Either way, the issue is effectively resolved now.