Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-197241

Players can change the color of a wolf's collar even if they're not its owner

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 23w12a
    • 1.16.1, 1.16.3, 1.16.4, 20w46a, 20w48a, 20w51a, 21w06a, 21w08a, 21w08b, 21w11a, 1.17, 1.17.1, 21w41a, 1.18.1, 1.18.2, 22w19a, 1.19, 1.19.2, 1.19.3, 1.19.4
    • Confirmed
    • Items, Mob behaviour
    • Normal
    • Gameplay

      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:

      1. Obtain any color dye and summon a wolf that is not your owner by using the command provided below.
        /summon minecraft:wolf ~ ~ ~ {Owner:"Notch"}
      2. Attempt to change the color of the wolf's collar by using the dye.
      3. 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.

      net.minecraft.world.entity.animal.Wolf.java
      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.

      Current "if" statement:
      if (dyecolor != this.getCollarColor())
      Fixed "if" statement:
      if (dyecolor != this.getCollarColor() && this.isOwnedBy(player))

        1. MC-197241.mp4
          2.99 MB
          [Mod] Avoma
        2. MC-197241 - Current Code.png
          57 kB
          [Mod] Avoma
        3. MC-197241 - Fixed Code.png
          58 kB
          [Mod] Avoma

            SystemInvecklare [Mojang] SystemInvecklare
            Avoma [Mod] Avoma
            Votes:
            10 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: