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:
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={"minecraft:riptide":3}]
Ride any entity and attempt to throw the riptide trident.
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 @unknown 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())
Linked issues
is duplicated by 1
Attachments
Comments 4
On bedrock edition this is fixed by making riptide not work at all when riding an entity. You are able to charge, when you let go of right click, it will not work.
This ticket closely relates to MC-248106.
Following on from my code analysis, I've double-checked my proposed fix and I can confidently confirm that it's fully functioning and works as expected, so I've attached two screenshots to this report, one of which shows the current code and the other that shows the fixed code. I feel this information may be quite insightful hence my reasoning for providing it. 🙂
[media][media]
Can confirm