From 7e2ff3fc074d6c279b945abcbe18ceb7e347e48d Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 19 Aug 2021 16:30:05 +0200 Subject: [PATCH] Players wearing the alicorn amulet will have a corrupting influence on entities that are around them --- .../client/ClientInteractionManager.java | 4 +- .../unicopia/client/gui/UHud.java | 5 +- .../effect/CorruptInfluenceStatusEffect.java | 84 +++++++++++++++++++ .../effect/FoodPoisoningStatusEffect.java | 50 +++++++++++ .../effect/SunBlindnessStatusEffect.java | 8 +- .../unicopia/entity/effect/UEffects.java | 28 ++----- .../unicopia/entity/effect/UPotions.java | 4 +- .../unicopia/entity/player/Pony.java | 3 +- .../unicopia/item/AlicornAmuletItem.java | 6 ++ 9 files changed, 157 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java create mode 100644 src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java diff --git a/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java index b190fe6b..4720282d 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ClientInteractionManager.java @@ -8,7 +8,7 @@ import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.client.sound.LoopingSoundInstance; import com.minelittlepony.unicopia.client.sound.MotionBasedSoundInstance; -import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect; +import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.player.PlayerPhysics; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.dummy.DummyClientPlayerEntity; @@ -53,7 +53,7 @@ public class ClientInteractionManager extends InteractionManager { SoundManager soundManager = client.getSoundManager(); if (type == SOUND_EARS_RINGING && source instanceof LivingEntity) { - soundManager.play(new LoopingSoundInstance<>((LivingEntity)source, e -> e.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE), USounds.ENTITY_PLAYER_EARS_RINGING, 1F, 1F)); + soundManager.play(new LoopingSoundInstance<>((LivingEntity)source, e -> e.hasStatusEffect(UEffects.SUN_BLINDNESS), USounds.ENTITY_PLAYER_EARS_RINGING, 1F, 1F)); } else if (type == SOUND_BEE && source instanceof BeeEntity) { soundManager.playNextTick( ((BeeEntity)source).hasAngerTime() diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java index 0f42078f..05b81900 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -13,6 +13,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.SpellType; import com.minelittlepony.unicopia.client.KeyBindingsHandler; import com.minelittlepony.unicopia.entity.behaviour.Disguise; import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect; +import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.player.Pony; import com.mojang.blaze3d.systems.RenderSystem; @@ -151,10 +152,10 @@ public class UHud extends DrawableHelper { protected void renderViewEffects(Pony pony, MatrixStack matrices, int scaledWidth, int scaledHeight, float tickDelta) { - boolean hasEffect = client.player.hasStatusEffect(SunBlindnessStatusEffect.INSTANCE); + boolean hasEffect = client.player.hasStatusEffect(UEffects.SUN_BLINDNESS); if (hasEffect || (pony.getSpecies() == Race.BAT && SunBlindnessStatusEffect.hasSunExposure(client.player))) { - float i = hasEffect ? (client.player.getStatusEffect(SunBlindnessStatusEffect.INSTANCE).getDuration() - tickDelta) / SunBlindnessStatusEffect.MAX_DURATION : 0; + float i = hasEffect ? (client.player.getStatusEffect(UEffects.SUN_BLINDNESS).getDuration() - tickDelta) / SunBlindnessStatusEffect.MAX_DURATION : 0; float pulse = (1 + (float)Math.sin(client.player.age / 108F)) * 0.25F; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java new file mode 100644 index 00000000..029ac555 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/CorruptInfluenceStatusEffect.java @@ -0,0 +1,84 @@ +package com.minelittlepony.unicopia.entity.effect; + +import org.jetbrains.annotations.Nullable; + +import com.minelittlepony.unicopia.Owned; +import com.minelittlepony.unicopia.entity.Equine; +import com.minelittlepony.unicopia.util.MagicalDamageSource; + +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.StatusEffectType; +import net.minecraft.entity.mob.HostileEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.WorldEvents; + +public class CorruptInfluenceStatusEffect extends StatusEffect { + CorruptInfluenceStatusEffect(int color) { + super(StatusEffectType.NEUTRAL, color); + addAttributeModifier(EntityAttributes.GENERIC_ATTACK_DAMAGE, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 120, EntityAttributeModifier.Operation.ADDITION); + addAttributeModifier(EntityAttributes.GENERIC_ATTACK_SPEED, "6D706448-6A60-4F59-BE8A-C23A6DD2C7A9", 10, EntityAttributeModifier.Operation.ADDITION); + } + + @SuppressWarnings("unchecked") + @Override + public void applyUpdateEffect(LivingEntity entity, int amplifier) { + + if (entity.world.isClient) { + return; + } + + if (entity instanceof HostileEntity) { + + int nearby = 0; + + for (Entity i : entity.world.getOtherEntities(entity, entity.getBoundingBox().expand(40))) { + if (i.getType() == entity.getType()) { + nearby++; + } + } + + if (nearby > 1) { + if (Equine.of(entity).filter(eq -> eq instanceof Owned && ((Owned)eq).getMaster() != null).isPresent()) { + return; + } + + if (entity.world.random.nextInt(2000) != 0) { + return; + } + } else if (entity.world.random.nextInt(200) != 0) { + return; + } + + HostileEntity mob = (HostileEntity)entity; + + HostileEntity clone = (HostileEntity)mob.getType().create(mob.world); + clone.copyPositionAndRotation(entity); + + Equine.of(clone).ifPresent(eq -> { + ((Owned)eq).setMaster(mob); + }); + mob.world.spawnEntity(clone); + + if (!mob.isSilent()) { + mob.world.syncWorldEvent((PlayerEntity)null, WorldEvents.ZOMBIE_INFECTS_VILLAGER, mob.getBlockPos(), 0); + } + } else if (entity.age % 20 == 0) { + entity.damage(MagicalDamageSource.ALICORN_AMULET, 2); + } + + } + + @Override + public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) { + applyUpdateEffect(target, amplifier); + } + + @Override + public boolean canApplyUpdateEffect(int duration, int amplifier) { + return duration > 0; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java new file mode 100644 index 00000000..11c2ae9c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/FoodPoisoningStatusEffect.java @@ -0,0 +1,50 @@ +package com.minelittlepony.unicopia.entity.effect; + +import org.jetbrains.annotations.Nullable; + +import com.minelittlepony.unicopia.util.MagicalDamageSource; + +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.StatusEffectType; +import net.minecraft.entity.effect.StatusEffects; + +public class FoodPoisoningStatusEffect extends StatusEffect { + + FoodPoisoningStatusEffect(int color) { + super(StatusEffectType.HARMFUL, color); + } + + @Override + public void applyUpdateEffect(LivingEntity entity, int amplifier) { + + StatusEffectInstance nausea = entity.getStatusEffect(StatusEffects.NAUSEA); + if (nausea == null) { + StatusEffectInstance foodEffect = entity.getStatusEffect(this); + nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), + foodEffect.getAmplifier(), + true, + foodEffect.shouldShowParticles(), + false + ); + + entity.addStatusEffect(nausea); + } + + entity.damage(MagicalDamageSource.FOOD_POISONING, amplifier); + + } + + @Override + public void applyInstantEffect(@Nullable Entity source, @Nullable Entity attacker, LivingEntity target, int amplifier, double proximity) { + applyUpdateEffect(target, amplifier); + } + + @Override + public boolean canApplyUpdateEffect(int duration, int amplifier) { + int i = 40 >> amplifier; + return i <= 0 || duration % i == 0; + } +} 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 fc31d4aa..7722af17 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/SunBlindnessStatusEffect.java @@ -13,19 +13,13 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectType; import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; import net.minecraft.world.LightType; public class SunBlindnessStatusEffect extends StatusEffect { public static final int MAX_DURATION = 50; - public static final SunBlindnessStatusEffect INSTANCE = new SunBlindnessStatusEffect(0x886F0F); - - private SunBlindnessStatusEffect(int color) { + SunBlindnessStatusEffect(int color) { super(StatusEffectType.NEUTRAL, color); - - Registry.register(Registry.STATUS_EFFECT, new Identifier("unicopia", "sun_blindness"), this); } @Override 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 83e01594..da224725 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/UEffects.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/UEffects.java @@ -1,29 +1,17 @@ package com.minelittlepony.unicopia.entity.effect; -import com.minelittlepony.unicopia.util.MagicalDamageSource; - import net.minecraft.entity.effect.StatusEffect; -import net.minecraft.entity.effect.StatusEffectInstance; -import net.minecraft.entity.effect.StatusEffectType; -import net.minecraft.entity.effect.StatusEffects; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; public interface UEffects { + StatusEffect FOOD_POISONING = register("food_poisoning", new FoodPoisoningStatusEffect(3484199)); + StatusEffect SUN_BLINDNESS = register("sun_blindness", new SunBlindnessStatusEffect(0x886F0F)); + StatusEffect CORRUPT_INFLUENCE = register("corrupt_influence", new CorruptInfluenceStatusEffect(0x00FF00)); - StatusEffect FOOD_POISONING = new CustomStatusEffect.Builder(new Identifier("unicopia", "food_poisoning"), StatusEffectType.HARMFUL, 3484199).direct((p, e, i) -> { - StatusEffectInstance nausea = e.getStatusEffect(StatusEffects.NAUSEA); - if (nausea == null) { - StatusEffectInstance foodEffect = e.getStatusEffect(p); - nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), - foodEffect.getAmplifier(), - true, - foodEffect.shouldShowParticles(), - false - ); + private static StatusEffect register(String name, StatusEffect effect) { + return Registry.register(Registry.STATUS_EFFECT, new Identifier("unicopia", name), effect); + } - e.addStatusEffect(nausea); - } - - e.damage(MagicalDamageSource.FOOD_POISONING, i); - }).build(); + static void bootstrap() {} } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java index 3ecadd21..82639098 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/UPotions.java @@ -1,6 +1,5 @@ package com.minelittlepony.unicopia.entity.effect; -import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.potion.Potion; import net.minecraft.util.Identifier; @@ -24,7 +23,6 @@ public interface UPotions { } static void bootstrap() { - @SuppressWarnings("unused") - StatusEffect e = SunBlindnessStatusEffect.INSTANCE; + UEffects.bootstrap(); } } 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 dae9db9f..4bb6bb0c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -22,6 +22,7 @@ import com.minelittlepony.unicopia.entity.PonyContainer; import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Trap; import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect; +import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.toxin.Toxin; import com.minelittlepony.unicopia.network.Channel; @@ -298,7 +299,7 @@ public class Pony extends Living implements Transmittable, Copieab } if (ticksInSun == 1) { - entity.addStatusEffect(new StatusEffectInstance(SunBlindnessStatusEffect.INSTANCE, SunBlindnessStatusEffect.MAX_DURATION * 10, 1, true, false)); + entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION * 10, 1, true, false)); UCriteria.LOOK_INTO_SUN.trigger(entity); if (isClient() && isClientPlayer()) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index 15cfc6df..9e059611 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.AwaitTickQueue; import com.minelittlepony.unicopia.entity.IItemEntity; import com.minelittlepony.unicopia.entity.ItemImpl; import com.minelittlepony.unicopia.entity.ItemImpl.TickableItem; +import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.player.MagicReserves; import com.minelittlepony.unicopia.entity.player.PlayerCharmTracker; import com.minelittlepony.unicopia.entity.player.Pony; @@ -28,6 +29,7 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.particle.ParticleEffect; @@ -200,6 +202,10 @@ public class AlicornAmuletItem extends AmuletItem implements PlayerCharmTracker. w.createExplosion(player, pos.x, pos.y, pos.z, 6, DestructionType.BREAK); }, 50); } + + pony.findAllEntitiesInRange(10, e -> e instanceof MobEntity && !((MobEntity)e).hasStatusEffect(UEffects.CORRUPT_INFLUENCE)).forEach(e -> { + ((MobEntity)e).addStatusEffect(new StatusEffectInstance(UEffects.CORRUPT_INFLUENCE, 1300, 1)); + }); } @Override