mojira.dev
MC-273411

"block_experience" enchantment effect doesn't affect XP dropped

In the attached enchantment json, I have "mob_experience" and "block_experience" being increased, even at high values the blocks still drop the same amount of XP.

 

When I copy the vanilla silk-touch enchantment, this also doesn't affect it.

 

Therefore, Silk Touch must also not work correctly and uses some other method of configuring the XP drop

 

 

Linked issues

Attachments

Comments 6

[Mod] Jingy

Please provide a functional datapack to be able to reproduce this issue, rather than the .json on it's own.
Additionally, what is the expected result/xp value, and what is returned instead?

Curtis Phillips

Attached the reproduction datapack.

 

Expected result is `mob_experience` and `block_experience` yielding more XP than the default that is dropped.

`mob_experience` works and XP dropped increases from mobs increases,

`block_experience` does not affect the XP dropped by blocks at all. Even copying the vanilla Silk Touch json, where `block_experience` is present and sets the value to 0, does not affect the XP dropped from blocks.

[Mod] Jingy

I'm still a bit lost on what exactly I'm looking for, by "blocks" which ones specifically are you referring to, and what is the expected level of XP you get from the blocks to compare to the result?

Clear steps to reproduce are really necessary here to be able to confirm the issue. An exact step-by-step guide would be much appreciated. 🙂

Curtis Phillips

Sorry trying my best to explain it.

In vanilla, Diamond Ore should yield about 3-7 XP when mined without Silk Touch.

The effect component `minecraft:block_experience` is supposed to change the value for the "Amount of experience awarded for breaking a block"

The bug is that `minecraft:block_experience` doesn't actually affect the XP dropped.

 

In the provided datapack example I have an enchantment "Learned", that is supposed to increase the XP awarded for killing mobs and for breaking blocks. It is supposed to increase the XP dropped by 10 per level, up to level 3. This works fine for `minecraft:mob_experience`; however, for `minecraft:block_experience` there is no change in how much XP is dropped when breaking the block.

Steps to reproduce:

  • Add datapack to world

  • Enchant helmet with Learned enchantment level 3, expected output would be +30 XP per mob killed and per block broken (If it drops XP)

  • Kill mob without wearing the helmet to see base XP gained

  • Clear XP/Levels

  • Equip Enchanted Helmet

  • Kill mob to see how much XP is gained through the enchantment

  • Clear XP/Levels

  • Break diamond ore without wearing the helmet using a non-silk touch pickaxe to see base XP gained

  • Clear XP/Levels

  • Equip Enchanted Helmet

  • Break diamond ore using a non-silk touch pickaxe to see base XP gained through the enchantment

  • Note, no increase to how much XP the diamond ore drops on being broken

Furthermore, copying the exact code for the vanilla Silk Touch enchantment (Which sets the value of XP dropped to 0) and using that also does not affect the XP dropped from blocks.

So the code for XP drops is somewhere else for Silk Touch, and is not reliant on the effect component `minecraft:block_experience`

Shadows_of_Fire

The cause of this issue lies in how the `block_experience` component is checked.  The component is only checked on the main hand item (the tool) of the breaking player.  The OP is attempting to make a Helmet Enchantment containing this component, which means it will never be accessed by the enchantment logic.

The entrypoint for enchantment-modified experience is Block#tryDropExperience, which only retains the context of the tool that was used to break the block.  To allow this component to work on items other than the tool, this function will need to accept the Entity who broke the block,

The components `ammo_use` and `projectile_piercing` share the same issue (only being applicable on the used bow instead of all gear slots).

Technically `repair_with_xp` and `item_damage` also share the same behavior, but I believe those two are working-as-intended, since those components should not impact other items.

[Mod] Jingy

I would say that this then may be related to MC-267944. While not exact, the two issues describe similar behavior of enchantments not working on slots that they were not designed for.
With that being said, I can confirm the issue in 1.21.

Curtis Phillips

(Unassigned)

Community Consensus

Platform

Normal

Data Packs, Enchantments

1.21

Retrieved