From 7ec222996be8acc793cecbd0f42dd16cf342be59 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 8 Nov 2020 22:57:41 +0100 Subject: [PATCH] added inexplicable anger --- .../de/ellpeck/naturesaura/ModConfig.java | 7 +- .../naturesaura/chunk/effect/AngerEffect.java | 80 +++++++++++++++++++ .../chunk/effect/DrainSpotEffects.java | 1 + .../book/en_us/entries/effects/anger.json | 12 +++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/chunk/effect/AngerEffect.java create mode 100644 src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/anger.json diff --git a/src/main/java/de/ellpeck/naturesaura/ModConfig.java b/src/main/java/de/ellpeck/naturesaura/ModConfig.java index 95054264..a7e738ad 100644 --- a/src/main/java/de/ellpeck/naturesaura/ModConfig.java +++ b/src/main/java/de/ellpeck/naturesaura/ModConfig.java @@ -32,6 +32,7 @@ public final class ModConfig { public ForgeConfigSpec.ConfigValue cacheRechargeEffect; public ForgeConfigSpec.ConfigValue explosionEffect; public ForgeConfigSpec.ConfigValue breathlessEffect; + public ForgeConfigSpec.ConfigValue angerEffect; public ForgeConfigSpec.ConfigValue animalEffect; public ForgeConfigSpec.ConfigValue oreEffect; public ForgeConfigSpec.ConfigValue auraBlooms; @@ -111,6 +112,10 @@ public final class ModConfig { .comment("If the Aura Imbalance effect of breathlessness if Aura levels are too low should occur") .translation("config." + NaturesAura.MOD_ID + ".breathlessEffect") .define("breathlessEffect", true); + this.angerEffect = builder + .comment("If the Aura Imbalance effect of passive mobs being angered if Aura levels are too low should occur") + .translation("config." + NaturesAura.MOD_ID + ".angerEffect") + .define("angerEffect", true); this.animalEffect = builder .comment("If the Aura Imbalance effect of farm animals being affected in positive ways if Aura levels are too high should occur") .translation("config." + NaturesAura.MOD_ID + ".animalEffect") @@ -166,7 +171,7 @@ public final class ModConfig { } public void apply() { - if (!this.grassDieEffect.get() && !this.netherDecayEffect.get() && !this.explosionEffect.get() && !this.breathlessEffect.get()) + if (!this.grassDieEffect.get() && !this.netherDecayEffect.get() && !this.explosionEffect.get() && !this.breathlessEffect.get() && !this.angerEffect.get()) throw new IllegalStateException("Nature's Aura has detected that all negative Aura Imbalance effects are disabled in the config file. This is disallowed behavior. Please enable at least one negative effect."); try { diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/AngerEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AngerEffect.java new file mode 100644 index 00000000..2b0b071c --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/AngerEffect.java @@ -0,0 +1,80 @@ +package de.ellpeck.naturesaura.chunk.effect; + +import de.ellpeck.naturesaura.ModConfig; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect; +import de.ellpeck.naturesaura.api.aura.type.IAuraType; +import net.minecraft.entity.IAngerable; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +import java.util.List; + +public class AngerEffect implements IDrainSpotEffect { + + public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "anger"); + + private AxisAlignedBB bb; + + private boolean calcValues(World world, BlockPos pos, Integer spot) { + if (spot >= 0) + return false; + int aura = IAuraChunk.getAuraInArea(world, pos, 50); + if (aura > 0) + return false; + int dist = Math.min(Math.abs(aura) / 50000, 75); + if (dist < 10) + return false; + this.bb = new AxisAlignedBB(pos).grow(dist); + return true; + } + + @Override + public ActiveType isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { + if (!this.calcValues(player.world, pos, spot)) + return ActiveType.INACTIVE; + if (!this.bb.contains(player.getPositionVec())) + return ActiveType.INACTIVE; + return ActiveType.ACTIVE; + } + + @Override + public ItemStack getDisplayIcon() { + return new ItemStack(Items.FIRE_CHARGE); + } + + @Override + public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { + if (world.getGameTime() % 100 != 0) + return; + if (!this.calcValues(world, pos, spot)) + return; + List entities = world.getEntitiesWithinAABB(LivingEntity.class, this.bb); + for (LivingEntity entity : entities) { + if (!(entity instanceof IAngerable)) + continue; + PlayerEntity player = world.getClosestPlayer(entity, 25); + if (player == null) + continue; + ((IAngerable) entity).setAttackTarget(player); + } + } + + @Override + public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { + return ModConfig.instance.angerEffect.get(); + } + + @Override + public ResourceLocation getName() { + return NAME; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java index b379bc84..c8cb06bf 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java @@ -17,6 +17,7 @@ public final class DrainSpotEffects { NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(OreSpawnEffect.NAME, OreSpawnEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(NetherGrassEffect.NAME, NetherGrassEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(NetherDecayEffect.NAME, NetherDecayEffect::new); + NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(AngerEffect.NAME, AngerEffect::new); NaturesAuraAPI.EFFECT_POWDERS.put(PlantBoostEffect.NAME, 0xc2f442); NaturesAuraAPI.EFFECT_POWDERS.put(CacheRechargeEffect.NAME, 0x1fb0d1); diff --git a/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/anger.json b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/anger.json new file mode 100644 index 00000000..03a51f60 --- /dev/null +++ b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/anger.json @@ -0,0 +1,12 @@ +{ + "name": "Inexplicable Anger", + "icon": "minecraft:fire_charge", + "category": "effects", + "advancement": "naturesaura:negative_imbalance", + "pages": [ + { + "type": "text", + "text": "When $(aura) levels get low enough in any area of any world, the increasing pressure of the environment makes it harder to contain oneself. Certain monsters, like $(item)Zombified Piglins$(), $(item)Endermen$() and other creatures that would usually only feel bothered when disturbed will instead start to $(thing)get angry$() seemingly completely out of the blue as soon as one comes close enough to them." + } + ] +} \ No newline at end of file