From a8d5e45f0e8e42d293ef3c3d40e34c80e20f3733 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 30 Aug 2023 21:47:20 +0100 Subject: [PATCH] Avoid breaking the alicorn amulet, rather just remove its effects when its fully degraded --- .../unicopia/entity/player/PlayerPhysics.java | 7 ++++++- .../java/com/minelittlepony/unicopia/item/AmuletItem.java | 2 +- .../minelittlepony/unicopia/item/PegasusAmuletItem.java | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 431e58ed..42127f67 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -463,7 +463,12 @@ public class PlayerPhysics extends EntityPhysics implements Tickab } if (entity.getWorld().random.nextInt(damageInterval) == 0) { - stack.damage(minDamage + entity.getWorld().random.nextInt(50), entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST)); + int damageLeft = stack.getMaxDamage() - stack.getDamage(); + int damageApplied = Math.min(damageLeft - 1, minDamage + entity.getWorld().random.nextInt(50)); + + if (damageApplied > 0) { + stack.damage(damageApplied, entity, e -> e.sendEquipmentBreakStatus(EquipmentSlot.CHEST)); + } } if (!getFlightType().canFly()) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java index d02d0041..5011e727 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AmuletItem.java @@ -85,7 +85,7 @@ public class AmuletItem extends WearableItem implements ChargeableItem { return stack.getItem() == this && (!isChargable() || ChargeableItem.getEnergy(stack) > 0); } - public boolean isApplicable(LivingEntity entity) { + public final boolean isApplicable(LivingEntity entity) { return isApplicable(getForEntity(entity)); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/PegasusAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/PegasusAmuletItem.java index 65cdb292..371ceb36 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/PegasusAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/PegasusAmuletItem.java @@ -25,6 +25,11 @@ public class PegasusAmuletItem extends AmuletItem implements ItemTracker.Trackab } + @Override + public boolean isApplicable(ItemStack stack) { + return stack.getDamage() < stack.getMaxDamage() - 1 && super.isApplicable(stack); + } + @Override public int getDefaultCharge() { return getMaxCharge() / 2;