Goat eating sounds aren't played when feeding them the last item of wheat within a stack
The Bug:
Goat eating sounds aren't played when feeding them the last item of wheat within a stack.
Steps to Reproduce:
- Obtain two pieces of what and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a piece of wheat and take note of how goat eating sounds are played.
- Feed the other goat the remaining piece of wheat and listen closely as you do this.
- Take note as to whether or not goat eating sounds are played when feeding them the last item of wheat within a stack.
Observed Behavior:
Goat eating sounds aren't played.
Expected Behavior:
Goat eating sounds would be played.
Code Analysis:
Code analysis by Apollo can be found below.
The following is based on a decompiled version of Minecraft 1.20.1 using MCP-Reborn.
public class Goat extends Animal { ... public InteractionResult mobInteract(Player player, InteractionHand interactionHand) { ItemStack itemstack = player.getItemInHand(interactionHand); if (itemstack.is(Items.BUCKET) && !this.isBaby()) { player.playSound(this.getMilkingSound(), 1.0F, 1.0F); ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, Items.MILK_BUCKET.getDefaultInstance()); player.setItemInHand(interactionHand, itemstack1); return InteractionResult.sidedSuccess(this.level().isClientSide); } else { InteractionResult interactionresult = super.mobInteract(player, interactionHand); if (interactionresult.consumesAction() && this.isFood(itemstack)) { this.level().playSound((Player)null, this, this.getEatingSound(itemstack), SoundSource.NEUTRAL, 1.0F, Mth.randomBetween(this.level().random, 0.8F, 1.2F)); } return interactionresult; } } ...
In the Goat.java class there is the Goat#mobInteract method. We see two important methods; super#mobInteract which is a method of a superclass called Animal. This method handles the decrementing of the held itemstack's amount.
The problem with the line after Goat#mobInteract is that we check if the itemstack is food via the method this#isFood, but since the player has one of that itemstack, the method removes that last amount, and then checks if the itemstack is food. Then it would return false as the itemstack is now AIR. Therefore the eating sound doesn't emit globally.
Fix:
To fix this, we can temporarily store a variable called flag which saves the itemstack's value of being food or not in a true or false matter. Then we can handle the mob interaction using super#mobInteract and then use the stored variable, flag, in our "if" statement.
} else { InteractionResult interactionresult = super.mobInteract(player, interactionHand); if (interactionresult.consumesAction() && this.isFood(itemstack)) { this.level().playSound((Player)null, this, this.getEatingSound(itemstack), SoundSource.NEUTRAL, 1.0F, Mth.randomBetween(this.level().random, 0.8F, 1.2F)); } return interactionresult; }
} else { boolean flag = this.isFood(itemstack); InteractionResult interactionresult = super.mobInteract(p_149379_, p_149380_); if (interactionresult.consumesAction() && flag) { this.level().playSound((Player)null, this, this.getEatingSound(itemstack), SoundSource.NEUTRAL, 1.0F, Mth.randomBetween(this.level().random, 0.8F, 1.2F)); } return interactionresult; }
Created Issue:
The sounds of goats eating cannot be heard when feeding them the last pieces of wheat within stacks
The Bug:
The sounds of screaming goats or regular goats eating cannot be heard when feeding them the last pieces of wheat within stacks.
Steps to Reproduce:
- Obtain two pieces of wheat and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a singular piece of wheat and take note of how the sounds of goats eating can be heard.
- Feed the other goat the last piece of wheat, and listen closely as you do this.
- Take note as to whether or not the sounds of goats eating can be heard when feeding them the last pieces of wheat within stacks.
Observed Behavior:
No sound can be heard.
Expected Behavior:
The sounds of goats eating would be heard when feeding them the last pieces of wheat within stacks.
The Bug:
The sounds of screaming goats or regular goats eating cannot be heard when feeding them the last pieces of wheat within stacks.
Steps to Reproduce:
- Obtain two pieces of wheat and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a singular piece of wheat and take note of how the sounds of goats eating can be heard.
- Feed the other goat the last piece of wheat, and listen closely as you do this.
- Take note as to whether or not the sounds of goats eating can be heard when feeding them the last pieces of wheat within stacks.
Observed Behavior:
No sound can be heard.
Expected Behavior:
Thesounds of goats eatingwould be heard when feeding them the last pieces of wheat within stacks.The Bug:
The sounds of screaming goats or regular goats eating cannot be heard when feeding them the last pieces of wheat within stacks.
Steps to Reproduce:
- Obtain two pieces of wheat and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a singular piece of wheat and take note of how the sounds of goats eating can be heard.
- Feed the other goat the last piece of wheat, and listen closely as you do this.
- Take note as to whether or not the sounds of goats eating can be heard when feeding them the last pieces of wheat within stacks.
Observed Behavior:
No sound can be heard.
Expected Behavior:
A sound would be heard when feeding them the last pieces of wheat within stacks.
The Bug:
The sounds of screaming goats or regular goats eating cannot be heard when feeding them the last pieces of wheat within stacks.
Steps to Reproduce:
- Obtain two pieces of wheat and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a singular piece of wheat and take note of how the sounds of goats eating can be heard.
- Feed the other goat the last piece of wheat
,and listen closely as you do this.- Take note as to whether or not the sounds of goats eating can be heard when feeding them the last pieces of wheat within stacks.
Observed Behavior:
No sound can be heard.
Expected Behavior:
A sound would be heard when feeding them the last pieces of wheat within stacks.
The Bug:
The sounds of screaminggoats or regular goats eating cannot be heard when feeding them the lastpiecesof wheat within stacks.Steps to Reproduce:
- Obtain two pieces of wh
eat and ensure that they occupy the same hotbar slot.- Summon two goats and switch into survival mode.
- Feed one of the goats a
singularpiece of wheat and take note of howthe sounds ofgoatseatingcan be heard.- Feed the other goat the
lastpiece of wheat and listen closely as you do this.- Take note as to whether or not
the sounds ofgoatseatingcan be heard when feeding them the lastpiecesof wheat within stacks.Observed Behavior:
No sound can be heard.Expected Behavior:
Asound would beheard when feeding them the last pieces of wheat within stacks.The Bug:
Goat eating sounds aren't played when feeding them the last item of wheat within a stack.
Steps to Reproduce:
- Obtain two pieces of what and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a piece of wheat and take note of how goat eating sounds are played.
- Feed the other goat the remaining piece of wheat and listen closely as you do this.
- Take note as to whether or not goat eating sounds are played when feeding them the last item of wheat within a stack.
Observed Behavior:
Goat eating sounds aren't played.
Expected Behavior:
Goat eating sounds would be played.
The sounds of goatseatingcannot be heard when feeding them the lastpiecesof wheat within stacksGoat eating sounds aren't played when feeding them the last item of wheat within a stack
relates to
The Bug:
Goat eating sounds aren't played when feeding them the last item of wheat within a stack.
Steps to Reproduce:
- Obtain two pieces of what and ensure that they occupy the same hotbar slot.
- Summon two goats and switch into survival mode.
- Feed one of the goats a piece of wheat and take note of how goat eating sounds are played.
- Feed the other goat the remaining piece of wheat and listen closely as you do this.
- Take note as to whether or not goat eating sounds are played when feeding them the last item of wheat within a stack.
Observed Behavior:
Goat eating sounds aren't played.
Expected Behavior:
Goat eating sounds would be played.
Code Analysis:
Code analysis by Apollo can be found below.
The following is based on a decompiled version of Minecraft 1.20.1 using MCP-Reborn.
net.minecraft.world.entity.animal.Goat.javapublic class Goat extends Animal { ... public InteractionResult mobInteract(Player player, InteractionHand interactionHand) { ItemStack itemstack = player.getItemInHand(interactionHand); if (itemstack.is(Items.BUCKET) && !this.isBaby()) { player.playSound(this.getMilkingSound(), 1.0F, 1.0F); ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, Items.MILK_BUCKET.getDefaultInstance()); player.setItemInHand(interactionHand, itemstack1); return InteractionResult.sidedSuccess(this.level().isClientSide); } else { InteractionResult interactionresult = super.mobInteract(player, interactionHand); if (interactionresult.consumesAction() && this.isFood(itemstack)) { this.level().playSound((Player)null, this, this.getEatingSound(itemstack), SoundSource.NEUTRAL, 1.0F, Mth.randomBetween(this.level().random, 0.8F, 1.2F)); } return interactionresult; } } ...In the Goat.java class there is the Goat#mobInteract method. We see two important methods; super#mobInteract which is a method of a superclass called Animal. This method handles the decrementing of the held itemstack's amount.
The problem with the line after Goat#mobInteract is that we check if the itemstack is food via the method this#isFood, but since the player has one of that itemstack, the method removes that last amount, and then checks if the itemstack is food. Then it would return false as the itemstack is now AIR. Therefore the eating sound doesn't emit globally.
Fix:
To fix this, we can temporarily store a variable called flag which saves the itemstack's value of being food or not in a true or false matter. Then we can handle the mob interaction using super#mobInteract and then use the stored variable, flag, in our "if" statement.
Current "else" statement:} else { InteractionResult interactionresult = super.mobInteract(player, interactionHand); if (interactionresult.consumesAction() && this.isFood(itemstack)) { this.level().playSound((Player)null, this, this.getEatingSound(itemstack), SoundSource.NEUTRAL, 1.0F, Mth.randomBetween(this.level().random, 0.8F, 1.2F)); } return interactionresult; }Fixed "else" statement:} else { boolean flag = this.isFood(itemstack); InteractionResult interactionresult = super.mobInteract(p_149379_, p_149380_); if (interactionresult.consumesAction() && flag) { this.level().playSound((Player)null, this, this.getEatingSound(itemstack), SoundSource.NEUTRAL, 1.0F, Mth.randomBetween(this.level().random, 0.8F, 1.2F)); } return interactionresult; }
Relates to MC-244739.

Relates to
MC-260219.Cannot reproduce in 24w39a.
This issue was present in 1.21.1 but no longer occurs in 24w33a. This issue has been fixed in 24w33a.