From 8b71579539db288bbe63a8cd9f7f51dd9c7b44b4 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 30 Sep 2024 15:17:29 +0100 Subject: [PATCH] Update status effects --- .../effect/ButterfingersStatusEffect.java | 3 +- .../effect/CorruptInfluenceStatusEffect.java | 37 ++++++++----------- .../effect/FoodPoisoningStatusEffect.java | 16 +++++--- .../effect/SeaponyGraceStatusEffect.java | 2 +- .../entity/effect/SimpleStatusEffect.java | 15 ++------ .../effect/SunBlindnessStatusEffect.java | 21 ++++------- 6 files changed, 40 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/ButterfingersStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/ButterfingersStatusEffect.java index 8674ee36..e0134649 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/ButterfingersStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/ButterfingersStatusEffect.java @@ -22,13 +22,14 @@ public class ButterfingersStatusEffect extends StatusEffect { } @Override - public void applyUpdateEffect(LivingEntity entity, int amplifier) { + public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { amplifier = MathHelper.clamp(amplifier, 0, 5); final int scale = 500 + (int)(((5 - amplifier) / 5F) * 900); if (entity.getWorld().random.nextInt(scale / 4) == 0) { applyInstantEffect(null, null, entity, amplifier, entity.getWorld().random.nextInt(scale)); } + return true; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java index d7624a54..a62848fe 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java @@ -1,38 +1,36 @@ package com.minelittlepony.unicopia.entity.effect; -import java.util.UUID; - -import org.jetbrains.annotations.Nullable; - import com.minelittlepony.unicopia.Owned; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.entity.Equine; import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.damage.UDamageTypes; -import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.entity.attribute.EntityAttributes; -import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Identifier; import net.minecraft.world.WorldEvents; -public class CorruptInfluenceStatusEffect extends StatusEffect { +public class CorruptInfluenceStatusEffect extends SimpleStatusEffect { + static final Identifier CORRUPTION_MODIFIER_ID = Unicopia.id("corruption_modifier"); + CorruptInfluenceStatusEffect(int color) { - super(StatusEffectCategory.NEUTRAL, color); - addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 15, EntityAttributeModifier.Operation.ADD_VALUE); - addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 10, EntityAttributeModifier.Operation.ADD_VALUE); + super(StatusEffectCategory.NEUTRAL, color, false); + addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, CORRUPTION_MODIFIER_ID, 15, EntityAttributeModifier.Operation.ADD_VALUE); + addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, CORRUPTION_MODIFIER_ID, 10, EntityAttributeModifier.Operation.ADD_VALUE); } @Override - public void applyUpdateEffect(LivingEntity entity, int amplifier) { + public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { if (entity.getWorld().isClient) { - return; + return true; } if (entity instanceof HostileEntity mob) { @@ -41,14 +39,14 @@ public class CorruptInfluenceStatusEffect extends StatusEffect { if (nearby > 1) { if (Equine.of(entity).filter(eq -> eq instanceof Owned o && o.getMaster() != null).isPresent()) { - return; + return false; } if (entity.getWorld().random.nextInt(2000) != 0) { - return; + return true; } } else if (entity.getWorld().random.nextInt(200) != 0) { - return; + return true; } reproduce(mob); @@ -57,11 +55,8 @@ public class CorruptInfluenceStatusEffect extends StatusEffect { } else if (entity.age % 2000 == 0) { entity.damage(Living.living(entity).damageOf(UDamageTypes.ALICORN_AMULET), 2); } - } - @Override - public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) { - applyUpdateEffect(target, amplifier); + return true; } @Override @@ -81,11 +76,11 @@ public class CorruptInfluenceStatusEffect extends StatusEffect { float maxHealthDifference = mob.getMaxHealth() - clone.getMaxHealth(); clone.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 900000, 2)); clone.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH) - .addPersistentModifier(new EntityAttributeModifier(UUID.randomUUID(), "Corruption Strength Modifier", maxHealthDifference + 1, EntityAttributeModifier.Operation.ADD_VALUE)); + .addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, maxHealthDifference + 1, EntityAttributeModifier.Operation.ADD_VALUE)); } if (clone.getAttributes().hasAttribute(EntityAttributes.GENERIC_ATTACK_DAMAGE)) { clone.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE) - .addPersistentModifier(new EntityAttributeModifier(UUID.randomUUID(), "Corruption Damage Modifier", mob.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE)); + .addPersistentModifier(new EntityAttributeModifier(CORRUPTION_MODIFIER_ID, mob.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE) + 1, EntityAttributeModifier.Operation.ADD_VALUE)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java index 34938c4f..e3e6c97c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.USounds; +import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.FoodComponent; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -13,6 +14,7 @@ import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.registry.RegistryKeys; import net.minecraft.sound.SoundCategory; import net.minecraft.util.TypedActionResult; @@ -23,12 +25,12 @@ public class FoodPoisoningStatusEffect extends StatusEffect { } @Override - public void applyUpdateEffect(LivingEntity entity, int amplifier) { + public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { if (entity.getWorld().isClient) { - return; + return true; } - boolean showParticles = entity.getStatusEffect(this).shouldShowParticles(); + boolean showParticles = entity.getStatusEffect(entity.getRegistryManager().get(RegistryKeys.STATUS_EFFECT).getEntry(this)).shouldShowParticles(); if (!entity.hasStatusEffect(StatusEffects.NAUSEA) && entity.getRandom().nextInt(12) == 0) { entity.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, showParticles, false)); @@ -39,8 +41,10 @@ public class FoodPoisoningStatusEffect extends StatusEffect { } if (EffectUtils.isPoisoned(entity) && entity.getRandom().nextInt(12) == 0 && !entity.hasStatusEffect(StatusEffects.POISON)) { - StatusEffects.POISON.applyUpdateEffect(entity, 1); + StatusEffects.POISON.value().applyUpdateEffect(entity, 1); } + + return true; } @Override @@ -56,9 +60,9 @@ public class FoodPoisoningStatusEffect extends StatusEffect { public static TypedActionResult apply(ItemStack stack, PlayerEntity user) { @Nullable - FoodComponent food = stack.getItem().getFoodComponent(); + FoodComponent food = stack.get(DataComponentTypes.FOOD); - if (food == null || !user.canConsume(food.isAlwaysEdible()) || !user.hasStatusEffect(UEffects.FOOD_POISONING)) { + if (food == null || !user.canConsume(food.canAlwaysEat()) || !user.hasStatusEffect(UEffects.FOOD_POISONING)) { return TypedActionResult.pass(stack); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/SeaponyGraceStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/SeaponyGraceStatusEffect.java index 46eee096..7cad75ca 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SeaponyGraceStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SeaponyGraceStatusEffect.java @@ -64,7 +64,7 @@ public class SeaponyGraceStatusEffect { if (!stateBroken.isIn(UTags.Blocks.ANGERS_GUARDIANS)) { return; } - StructureStart start = sw.getStructureAccessor().getStructureContaining(pos, StructureKeys.MONUMENT); + StructureStart start = sw.getStructureAccessor().getStructureContaining(pos, key -> key == StructureKeys.MONUMENT); if (start.getStructure() == null) { return; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java index 7adc3654..f6a0fa1c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SimpleStatusEffect.java @@ -1,11 +1,10 @@ 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; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; public class SimpleStatusEffect extends StatusEffect { @@ -16,14 +15,8 @@ public class SimpleStatusEffect extends StatusEffect { 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) { - + protected RegistryEntry getEntry(Entity entity) { + return entity.getRegistryManager().get(RegistryKeys.STATUS_EFFECT).getEntry(this); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java index 57f91ed4..f30752d4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java @@ -1,7 +1,5 @@ package com.minelittlepony.unicopia.entity.effect; -import org.jetbrains.annotations.Nullable; - import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate; @@ -10,40 +8,35 @@ import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.MeteorlogicalUtil; -import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffects; -public class SunBlindnessStatusEffect extends StatusEffect { +public class SunBlindnessStatusEffect extends SimpleStatusEffect { public static final int MAX_DURATION = 250; SunBlindnessStatusEffect(int color) { - super(StatusEffectCategory.NEUTRAL, color); + super(StatusEffectCategory.NEUTRAL, color, false); } @Override - public void applyUpdateEffect(LivingEntity entity, int amplifier) { - StatusEffectInstance state = entity.getStatusEffect(this); + public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { + StatusEffectInstance state = entity.getStatusEffect(getEntry(entity)); if (state == null || isSunImmune(entity)) { - return; + return false; } if (entity.age % 15 == 0) { if (!hasSunExposure(entity)) { - entity.setStatusEffect(new StatusEffectInstance(this, (int)(state.getDuration() * 0.8F), Math.max(1, amplifier - 1), true, false), entity); + entity.setStatusEffect(new StatusEffectInstance(getEntry(entity), (int)(state.getDuration() * 0.8F), Math.max(1, amplifier - 1), true, false), entity); } else { entity.damage(Living.living(entity).damageOf(amplifier == 2 ? UDamageTypes.SUN : UDamageTypes.SUNLIGHT), amplifier / 5F); } } - } - @Override - public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) { - applyUpdateEffect(target, amplifier); + return true; } @Override