The Bug:
Players can change the color of a wolf's collar even if they're not its owner.
It's important to note that this concept is exclusive to wolves and cannot be seen with cats. This issue isn't present with cats because the isOwnedBy() method is called appropriately with this entity, therefore preventing other players from being able to interact with them.
Steps to Reproduce:
- Obtain any color dye and summon a wolf that is not your owner by using the command provided below.
/summon minecraft:wolf ~ ~ ~ {Owner:"Notch"}
- Attempt to change the color of the wolf's collar by using the dye.
- Take note as to whether or not players can change the color of a wolf's collar even if they're not its owner.
Observed Behavior:
Players can change the color of a wolf's collar even if they're not its owner.
Expected Behavior:
Players would not be able to change the color of a wolf's collar if they're not its owner.
Code Analysis:
Code analysis by Avoma can be found below.
The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.
public class Wolf extends TamableAnimal implements NeutralMob { ... public InteractionResult mobInteract(Player player, InteractionHand interactionHand) { ItemStack itemstack = player.getItemInHand(interactionHand); Item item = itemstack.getItem(); if (this.level.isClientSide) { ... } else { if (this.isTame()) { ... DyeColor dyecolor = ((DyeItem)item).getDyeColor(); if (dyecolor != this.getCollarColor() && this.isOwnedBy(player)) { this.setCollarColor(dyecolor); if (!player.getAbilities().instabuild) { itemstack.shrink(1); } return InteractionResult.SUCCESS; } ...
If we look at the above class, we can see that there are two checks that are carried out before allowing the color of a wolf's collar to be changed. One of these checks is to see if the wolf is tamed and the other is to see if the player is holding a dye that's not already the same color as the wolf's collar at the time of the interaction. If these two requirements are met, the color of the wolf's collar can be changed. The game doesn't check if the player carrying out the interaction is the wolf's owner before allowing the color of its collar to be changed, therefore resulting in this problem occurring.
Fix:
Simply altering the appropriate existing "if" statement within this piece of code to check if the player carrying out the interaction is the wolf's owner before allowing the color of its collar to be changed will resolve this problem.
if (dyecolor != this.getCollarColor())
if (dyecolor != this.getCollarColor() && this.isOwnedBy(player))
- relates to
-
MC-220469 You cannot use items while looking at wolves owned by other players
- Resolved