Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6342

TROPICAL_FISH_BUCKET isSimilar returns true when it should not

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • git-Spigot-138d451-085fe67 (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT)
    • Yes

      Example code (compiled version is attached):

      @Override
      public void onEnable() {
         ItemStack fish1 = new ItemStack(Material.TROPICAL_FISH_BUCKET);
         ItemStack fish2 = new ItemStack(Material.TROPICAL_FISH_BUCKET);
         TropicalFishBucketMeta meta1 = (TropicalFishBucketMeta) fish1.getItemMeta();
         TropicalFishBucketMeta meta2 = (TropicalFishBucketMeta) fish2.getItemMeta();
         meta1.setPatternColor(DyeColor.BLUE);
         meta1.setPattern(TropicalFish.Pattern.BLOCKFISH);
         meta1.setBodyColor(DyeColor.BROWN);
         meta2.setPatternColor(DyeColor.BLUE);
         meta2.setPattern(TropicalFish.Pattern.BRINELY);
         meta2.setBodyColor(DyeColor.BROWN);
         fish1.setItemMeta(meta1);
         fish2.setItemMeta(meta2);
         System.out.println(fish1);
         System.out.println(fish2);
         System.out.println(fish1.isSimilar(fish2));
      }
      

      This prints:

      [00:12:41 INFO]: ItemStack{TROPICAL_FISH_BUCKET x 1, TROPICAL_FISH_BUCKET_META:{meta-type=TROPICAL_FISH_BUCKET, fish-variant=185336577}}
      [00:12:41 INFO]: ItemStack{TROPICAL_FISH_BUCKET x 1, TROPICAL_FISH_BUCKET_META:{meta-type=TROPICAL_FISH_BUCKET, fish-variant=185336832}}
      [00:12:41 INFO]: true
      

      The items are clearly not similar but yet isSimilar returns true. I had a look at the code, but I could not identify the issues on first glance.

      However there seems to be a different issue in the equalsCommon method as well:

      return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant())
              && entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : entityTag == null;
      

      should be:

      return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant())
              && entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : that.entityTag == null;
      

      EDIT: Now I know what the issue is. Missing brackets. The correct version should be:

      return (hasVariant() ? that.hasVariant() && this.variant.equals(that.variant) : !that.hasVariant())
              && (entityTag != null ? that.entityTag != null && this.entityTag.equals(that.entityTag) : that.entityTag == null);
      

       

            Unassigned Unassigned
            Gerrygames Gero Cammans
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: