The Bug:
Drinking honey bottles increases "minecraft.used:minecraft.honey_bottle" by a value of two and runs the "minecraft:consume_item" advancement trigger twice.
Steps to Reproduce:
Create a scoreboard objective for tracking the use of a honey bottle and set it to display on the sidebar by using the commands provided below.
/scoreboard objectives add UseHoneyBottle minecraft.used:minecraft.honey_bottle
/scoreboard objectives setdisplay sidebar UseHoneyBottle
Obtain a honey bottle and drink it.
Take note as to whether or not drinking honey bottles increases "minecraft.used:minecraft.honey_bottle" by a value of two and runs the "minecraft:consume_item" advancement trigger twice.
Observed Behavior:
"minecraft.used:minecraft.honey_bottle" increases by a value of two and the "minecraft:consume_item" advancement trigger runs twice.
Expected Behavior:
"minecraft.used:minecraft.honey_bottle" would be increased by a value of one and the "minecraft:consume_item" advancement trigger would only be run once.
Code Analysis:
Code analysis by @unknown can be found in this comment.
Linked issues
is duplicated by 4
Attachments
Comments 9
Can confirm in 21w16a. I'd like to request ownership of this ticket since the current reporter has been inactive since July 2020. I'm willing to provide all of the necessary information and will keep this report updated.
Code analysis (Yarn mappings)
Honey bottles are a custom item with a food component. The HoneyBottleItem
class triggers the criterion in its implementation of the Item#finishUsing
method:
@Override
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
super.finishUsing(stack, world, user);
if (user instanceof ServerPlayerEntity serverUser) {
Criteria.CONSUME_ITEM.trigger(serverUser, stack); // custom item trigger
serverUser.incrementStat(Stats.USED.getOrCreateStat(this));
}
}
However, the base implementation of the Item#finishUsing
method already triggers the criterion for foods through the player's implementation of the LivingEntity#eatFood
method:
@Override
public ItemStack eatFood(World world, ItemStack stack) {
this.getHungerManager().eat(stack.getItem(), stack);
this.incrementStat(Stats.USED.getOrCreateStat(stack.getItem()));
world.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5f, world.random.nextFloat() * 0.1f + 0.9f);
if (this instanceof ServerPlayerEntity serverPlayer) {
Criteria.CONSUME_ITEM.trigger(serverPlayer, stack); // food trigger
}
return super.eatFood(world, stack);
}
One recommended fix is to simply remove the unnecessary criterion trigger from the HoneyBottleItem
class.
Can confirm in 20w46a.