diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java index 76b2d29e..2f8833e9 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.ability.magic.spell.effect; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.entity.Living; +import com.minelittlepony.unicopia.entity.effect.EffectUtils; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.item.enchantment.UEnchantments; @@ -61,12 +62,10 @@ public interface AttractionUtils { return Pony.of(entity).map(pony -> { double force = 0.75; - if (pony.getCompositeRace().canUseEarth()) { + if (EffectUtils.hasExtraDefenses(pony.asEntity())) { + force /= 12; + } else if (pony.getCompositeRace().canUseEarth()) { force /= 2; - - if (pony.asEntity().isSneaking()) { - force /= 6; - } } else if (pony.getCompositeRace().canFly()) { force *= 2; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/EffectUtils.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/EffectUtils.java index 14372955..dff45f27 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/EffectUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/EffectUtils.java @@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.entity.effect; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectInstance; public interface EffectUtils { static boolean isPoisoned(LivingEntity entity) { @@ -15,4 +16,26 @@ public interface EffectUtils { static boolean isChangingRace(LivingEntity entity) { return entity.getStatusEffects().stream().anyMatch(effect -> effect.getEffectType() instanceof RaceChangeStatusEffect); } + + static boolean hasExtraDefenses(LivingEntity entity) { + return entity.hasStatusEffect(UEffects.FORTIFICATION); + } + + static boolean applyStatusEffect(LivingEntity entity, StatusEffect effect, boolean apply) { + if (entity.getWorld().isClient) { + return false; + } + boolean has = entity.hasStatusEffect(effect); + if (has != apply) { + if (has) { + if (entity.getStatusEffect(effect).getDuration() == StatusEffectInstance.INFINITE) { + entity.removeStatusEffect(effect); + } + } else { + entity.addStatusEffect(new StatusEffectInstance(effect, StatusEffectInstance.INFINITE, 0, false, false, true)); + } + return true; + } + return false; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java new file mode 100644 index 00000000..7adc3654 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java @@ -0,0 +1,33 @@ +package com.minelittlepony.unicopia.entity.effect; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectCategory; + +public class SimpleStatusEffect extends StatusEffect { + + private final boolean instant; + + public SimpleStatusEffect(StatusEffectCategory category, int color, boolean instant) { + super(category, color); + this.instant = instant; + } + + @Override + public void applyUpdateEffect(LivingEntity entity, int amplifier) { + + } + + @Override + public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) { + + } + + @Override + public final boolean isInstant() { + return instant; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/UEffects.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/UEffects.java index 00b51dd6..83feb060 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/UEffects.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/UEffects.java @@ -15,7 +15,8 @@ public interface UEffects { * When affecting an entity, will give them a random chance to reproduce or duplicate themselves when they die. */ StatusEffect CORRUPT_INFLUENCE = register("corrupt_influence", new CorruptInfluenceStatusEffect(0x00FF00)); - StatusEffect PARALYSIS = register("paralysis", new StatusEffect(StatusEffectCategory.HARMFUL, 0) {}); + StatusEffect PARALYSIS = register("paralysis", new SimpleStatusEffect(StatusEffectCategory.HARMFUL, 0, false)); + StatusEffect FORTIFICATION = register("fortification", new SimpleStatusEffect(StatusEffectCategory.BENEFICIAL, 0x000077, false)); /** * Side-effect of wearing the alicorn amulet. * Causes the player to lose grip on whatever item they're holding. diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java index 8bbccdef..b1efa4a6 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java @@ -6,6 +6,8 @@ import java.util.function.Predicate; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; +import com.minelittlepony.unicopia.entity.effect.EffectUtils; +import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.mob.UEntityAttributes; import com.minelittlepony.unicopia.util.Tickable; @@ -87,6 +89,7 @@ public class PlayerAttributes implements Tickable { @Override public void tick() { ATTRIBUTES.forEach(attribute -> attribute.update(pony)); + EffectUtils.applyStatusEffect(pony.asEntity(), UEffects.FORTIFICATION, pony.getCompositeRace().canUseEarth() && pony.asEntity().isSneaking()); } record ToggleableAttribute(EntityAttributeModifier modifier, List attributes, Predicate test) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 07a13cec..b8f30cd5 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -21,6 +21,7 @@ import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.entity.*; import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance; import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; +import com.minelittlepony.unicopia.entity.effect.EffectUtils; import com.minelittlepony.unicopia.entity.effect.MetamorphosisStatusEffect; import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect; import com.minelittlepony.unicopia.entity.effect.UEffects; @@ -700,18 +701,17 @@ public class Pony extends Living implements Copyable, Update } } - if (!cause.isIn(DamageTypeTags.BYPASSES_SHIELD) + if (EffectUtils.hasExtraDefenses(entity) + && !cause.isIn(DamageTypeTags.BYPASSES_SHIELD) && !cause.isOf(DamageTypes.MAGIC) && !cause.isIn(DamageTypeTags.IS_FIRE) && !cause.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY) && !cause.isOf(DamageTypes.THORNS) && !cause.isOf(DamageTypes.FREEZE)) { - if (getCompositeRace().canUseEarth() && entity.isSneaking()) { - amount /= (cause.isOf(DamageTypes.MOB_PROJECTILE) ? 3 : 2) * (entity.getHealth() < 5 ? 3 : 1); + amount /= (cause.isOf(DamageTypes.MOB_PROJECTILE) ? 3 : 2) * (entity.getHealth() < 5 ? 3 : 1); - return Optional.of(amount); - } + return Optional.of(amount); } return Optional.empty(); } @@ -727,7 +727,7 @@ public class Pony extends Living implements Copyable, Update public float onImpact(float distance, float damageMultiplier, DamageSource cause) { distance = super.onImpact(distance, damageMultiplier, cause); - if (getCompositeRace().canUseEarth() && entity.isSneaking()) { + if (EffectUtils.hasExtraDefenses(entity)) { double radius = distance / 10; if (radius > 0) { EarthPonyStompAbility.spawnEffectAround(entity, entity.getSteppingPos(), radius, radius); @@ -750,7 +750,7 @@ public class Pony extends Living implements Copyable, Update } } - if (getCompositeRace().canFly() || (getCompositeRace().canUseEarth() && entity.isSneaking())) { + if (getCompositeRace().canFly() || EffectUtils.hasExtraDefenses(entity)) { distance -= 5; } } diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 86c642e4..dcacc971 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -406,6 +406,7 @@ "effect.unicopia.corrupt_influence": "Corrupt Influence", "effect.unicopia.paralysis": "Paralysis", "effect.unicopia.butter_fingers": "Butterfingers", + "effect.unicopia.fortification": "Fortification", "effect.unicopia.change_race_earth": "Earth Pony Metamorphosis", "effect.unicopia.change_race_unicorn": "Unicorn Metamorphosis", diff --git a/src/main/resources/assets/unicopia/textures/mob_effect/fortification.png b/src/main/resources/assets/unicopia/textures/mob_effect/fortification.png new file mode 100644 index 00000000..106e3a2f Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/mob_effect/fortification.png differ