CommandHelper

CommandHelper

46.5k Downloads

False BlockState default values (also enforced after set_pinv(pinv()) )

Nilleke opened this issue ยท 3 comments

commented

CommandHelper seems to retrieve default BlockState values for unspecified states when at least one state is specified, and enforces them after a set_pinv(pinv()).

Tested on:

CommandHelper-3.3.5-b309
Purpur-1.19.3-b1895


Test item without BlockState:

/give @s bee_nest

This is a normal bee nest without honey level or forced facing direction.
pinv() returns:

{meta: null, name: BEE_NEST, qty: 1}

after set_pinv(pinv()) it still returns the same information and the item works the same

Test item with BlockState:

/give @s bee_nest{BlockStateTag:{honey_level:5}}

This places a bee nest with honey level 5 and respects the direction the player is facing.
However pinv() returns:

{meta: {blockdata: {block: bee_nest, facing: north, honey_level: 5}, display: null, enchants: {}, flags: {}, flowerlocation: null, lore: null, model: null, modifiers: null, repair: 0}, name: BEE_NEST, qty: 1}

This falsely claims the facing direction is forced to north.
After doing set_pinv(pinv()) it still returns the same information but the added default values (like facing: north) are actually enforced, any value that was specified previously (like honey_level) is kept.

commented

There doesn't appear to be a (supported) way to fix this. There is a method to "ignoreUnspecified" states, but that only applies to when we're creating a new BlockData from a string, like via Bukkit.createBlockData().

Also, for future reference, the issue is with both getting AND setting BlockDataMeta. Getting BlockDataMeta will always have default values with no easy way to filter them. (was thinking about generating default BlockData and then comparing states, but that's not trivial and doesn't fix the other problem) Setting BlockDataMeta will always insert default values into the item. (can confirm with /data get entity @s) I can't think of a way to fix this without digging into NBT again.

For now it's all or nothing with BlockDataMeta.

commented

This was fixed for setting BlockData meta in 1.21.3. It's still a problem for getting BlockData meta, but I've been revisiting the problem.

commented

Now getting only existing states works in 1.20.6+ and setting only existing states works in 1.21.3+. Could backport these fixes with more reflection, but I don't know if I'm up for it given all the other things on my plate.