Skip to content

Commit

Permalink
Fix Ring of the Mantle overriding other Haste sources
Browse files Browse the repository at this point in the history
(fixes #4632)
  • Loading branch information
TheRealWormbo committed May 6, 2024
1 parent 037e21c commit 4c141cb
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,44 @@

public class RingOfTheMantleItem extends BaubleItem {

public static final int MANA_COST = 5;
public static final int HASTE_AMPLIFIER = 1; // Haste 2

public RingOfTheMantleItem(Properties props) {
super(props);
}

@Override
public void onWornTick(ItemStack stack, LivingEntity entity) {
if (entity instanceof Player player && !player.level().isClientSide) {
int manaCost = 5;
boolean hasMana = ManaItemHandler.instance().requestManaExact(stack, player, manaCost, false);
boolean hasMana = ManaItemHandler.instance().requestManaExact(stack, player, MANA_COST, false);
if (!hasMana) {
onUnequipped(stack, player);
} else {
if (player.getEffect(MobEffects.DIG_SPEED) != null) {
player.removeEffect(MobEffects.DIG_SPEED);
}

player.addEffect(new MobEffectInstance(MobEffects.DIG_SPEED, Integer.MAX_VALUE, 1, true, true));
onEquipped(stack, player);
}

if (player.attackAnim == 0.25F) {
ManaItemHandler.instance().requestManaExact(stack, player, manaCost, true);
ManaItemHandler.instance().requestManaExact(stack, player, MANA_COST, true);
}
}
}

@Override
public void onEquipped(ItemStack stack, LivingEntity living) {
boolean hasMana = living instanceof Player player
&& ManaItemHandler.instance().requestManaExact(stack, player, MANA_COST, false);
MobEffectInstance effect = living.getEffect(MobEffects.DIG_SPEED);
if (hasMana && (effect == null || effect.getAmplifier() < HASTE_AMPLIFIER
|| effect.getAmplifier() == HASTE_AMPLIFIER && !effect.isInfiniteDuration())) {
living.addEffect(new MobEffectInstance(MobEffects.DIG_SPEED, MobEffectInstance.INFINITE_DURATION, HASTE_AMPLIFIER, true, true));
}
}

@Override
public void onUnequipped(ItemStack stack, LivingEntity living) {
MobEffectInstance effect = living.getEffect(MobEffects.DIG_SPEED);
if (effect != null && effect.getAmplifier() == 1) {
if (effect != null && effect.getAmplifier() == HASTE_AMPLIFIER && effect.isInfiniteDuration()) {
living.removeEffect(MobEffects.DIG_SPEED);
}
}
Expand Down

0 comments on commit 4c141cb

Please sign in to comment.