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

You can use tridents enchanted with riptide while riding entities

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.16.5, 21w14a, 21w15a, 21w16a, 21w17a, 21w18a, 21w19a, 21w20a, 1.17 Pre-release 4, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1 Pre-release 3, 1.17.1 Release Candidate 1, 1.17.1, 21w37a, 1.18.1, 22w05a, 22w06a, 1.18.2, 1.19, 1.19.1, 1.19.2, 22w43a, 1.19.3, 1.19.4, 1.20.1, 24w20a, 1.21, 1.21.3
    • Community Consensus
    • Player

      The Bug:

      You can use tridents enchanted with riptide while riding entities and in some cases, this can damage the entity you're riding.

      Steps to Reproduce:

      1. Set the weather to "rain" and give yourself a trident enchanted with riptide by using the command provided below.
        /give @s minecraft:trident[minecraft:enchantments={levels:{"minecraft:riptide":3}}]
      2. Ride any entity and attempt to throw the riptide trident.
      3. Take note as to whether or not you can use tridents enchanted with riptide while riding entities.

      Observed Behavior:

      You can use riptide tridents.

      Expected Behavior:

      You would not be able to use riptide tridents.

      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.item.TridentItem.java
      public class TridentItem extends Item implements Vanishable {
         ...
         public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand interactionHand) {
            ItemStack itemstack = player.getItemInHand(interactionHand);
            if (itemstack.getDamageValue() >= itemstack.getMaxDamage() - 1) {
               return InteractionResultHolder.fail(itemstack);
            } else if (EnchantmentHelper.getRiptide(itemstack) > 0 && !player.isInWaterOrRain()) {
               return InteractionResultHolder.fail(itemstack);
            } else {
               player.startUsingItem(interactionHand);
               return InteractionResultHolder.consume(itemstack);
            }
         }
         ...

      If we look at the above class, we can see that there are two checks that are carried out before allowing the player to use a trident enchanted with riptide. One of these is to check if the player is actually holding a trident enchanted with riptide and the other is to check if they are in water or rain. The game doesn't check if the player is currently riding an entity before allowing them to throw a trident enchanted with riptide in the rain, therefore resulting in this problem occurring.

      Fix:

      Simply altering the appropriate existing "if" statement within this piece of code to check if the player is a passenger before allowing them to throw a trident enchanted with riptide in the rain, will resolve this problem. We can achieve this through the use of the isPassenger() boolean.

      Current "if" statement:
      else if (EnchantmentHelper.getRiptide(itemstack) > 0 && !player.isInWaterOrRain())
      Fixed "if" statement:
      else if (EnchantmentHelper.getRiptide(itemstack) > 0 && !player.isInWaterOrRain() || player.isPassenger())

        1. MC-222949.mp4
          5.70 MB
        2. MC-222949 - Current Code.png
          MC-222949 - Current Code.png
          42 kB
        3. MC-222949 - Fixed Code.png
          MC-222949 - Fixed Code.png
          42 kB
        4. MC-222949.png
          MC-222949.png
          1.22 MB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            8 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              CHK: