From 3493a43f17122372348b4eeec0faba52e467913d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 8 Nov 2020 15:05:45 +0100 Subject: [PATCH] added nether decay --- .../de/ellpeck/naturesaura/ModConfig.java | 12 +- .../chunk/effect/DrainSpotEffects.java | 1 + .../chunk/effect/NetherDecayEffect.java | 103 ++++++++++++++++++ .../en_us/entries/effects/nether_decay.json | 12 ++ 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherDecayEffect.java create mode 100644 src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/nether_decay.json diff --git a/src/main/java/de/ellpeck/naturesaura/ModConfig.java b/src/main/java/de/ellpeck/naturesaura/ModConfig.java index d8eee516..95054264 100644 --- a/src/main/java/de/ellpeck/naturesaura/ModConfig.java +++ b/src/main/java/de/ellpeck/naturesaura/ModConfig.java @@ -2,13 +2,9 @@ package de.ellpeck.naturesaura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.type.BasicAuraType; -import de.ellpeck.naturesaura.api.aura.type.IAuraType; import de.ellpeck.naturesaura.api.misc.WeightedOre; import de.ellpeck.naturesaura.chunk.effect.OreSpawnEffect; -import net.minecraft.block.Block; import net.minecraft.entity.EntityType; -import net.minecraft.tags.BlockTags; -import net.minecraft.tags.Tag; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.registries.ForgeRegistries; @@ -31,6 +27,7 @@ public final class ModConfig { public ForgeConfigSpec.ConfigValue rfConverter; public ForgeConfigSpec.ConfigValue chunkLoader; public ForgeConfigSpec.ConfigValue grassDieEffect; + public ForgeConfigSpec.ConfigValue netherDecayEffect; public ForgeConfigSpec.ConfigValue plantBoostEffect; public ForgeConfigSpec.ConfigValue cacheRechargeEffect; public ForgeConfigSpec.ConfigValue explosionEffect; @@ -94,6 +91,10 @@ public final class ModConfig { .comment("If the Aura Imbalance effect of grass and trees dying in the area if the Aura levels are too low should occur") .translation("config." + NaturesAura.MOD_ID + ".grassDieEffect") .define("grassDieEffect", true); + this.netherDecayEffect = builder + .comment("If the Aura Imbalance effect of nether blocks degrading in the area if the Aura levels are too low should occur") + .translation("config." + NaturesAura.MOD_ID + ".netherDecayEffect") + .define("netherDecayEffect", true); this.plantBoostEffect = builder .comment("If the Aura Imbalance effect of plant growth being boosted if the Aura levels are high enough should occur") .translation("config." + NaturesAura.MOD_ID + ".plantBoostEffect") @@ -165,9 +166,8 @@ public final class ModConfig { } public void apply() { - if (!this.grassDieEffect.get() && !this.explosionEffect.get() && !this.breathlessEffect.get()) { + if (!this.grassDieEffect.get() && !this.netherDecayEffect.get() && !this.explosionEffect.get() && !this.breathlessEffect.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 { for (String s : this.additionalBotanistPickaxeConversions.get()) { 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 1f366bd3..b379bc84 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java @@ -16,6 +16,7 @@ public final class DrainSpotEffects { NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(AnimalEffect.NAME, AnimalEffect::new); 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.EFFECT_POWDERS.put(PlantBoostEffect.NAME, 0xc2f442); NaturesAuraAPI.EFFECT_POWDERS.put(CacheRechargeEffect.NAME, 0x1fb0d1); diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherDecayEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherDecayEffect.java new file mode 100644 index 00000000..eb67b3e3 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/NetherDecayEffect.java @@ -0,0 +1,103 @@ +package de.ellpeck.naturesaura.chunk.effect; + +import de.ellpeck.naturesaura.ModConfig; +import de.ellpeck.naturesaura.NaturesAura; +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +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.block.AbstractFireBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.tags.BlockTags; +import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class NetherDecayEffect implements IDrainSpotEffect { + + public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "nether_decay"); + + private int amount; + private int dist; + + 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; + this.amount = Math.min(300, MathHelper.ceil(Math.abs(aura) / 50000F / IAuraChunk.getSpotAmountInArea(world, pos, 50))); + if (this.amount <= 1) + return false; + this.dist = MathHelper.clamp(Math.abs(aura) / 50000, 5, 75); + 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 (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist) + return ActiveType.INACTIVE; + return ActiveType.ACTIVE; + } + + @Override + public ItemStack getDisplayIcon() { + return new ItemStack(Items.SOUL_SAND); + } + + @Override + public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) { + if (!this.calcValues(world, pos, spot)) + return; + for (int i = this.amount / 2 + world.rand.nextInt(this.amount / 2); i >= 0; i--) { + BlockPos offset = new BlockPos( + pos.getX() + world.rand.nextGaussian() * this.dist, + pos.getY() + world.rand.nextGaussian() * this.dist, + pos.getZ() + world.rand.nextGaussian() * this.dist); + if (offset.distanceSq(pos) > this.dist * this.dist || !world.isBlockLoaded(offset)) + continue; + + // degrade blocks + Block degraded = null; + BlockState state = world.getBlockState(offset); + if (state.getBlock() == Blocks.GLOWSTONE) { + degraded = Blocks.NETHERRACK; + } else if (state.getBlock().isIn(BlockTags.NYLIUM) || state.getBlock() == Blocks.NETHERRACK) { + degraded = Blocks.SOUL_SOIL; + } else if (state.getBlock() == Blocks.SOUL_SOIL) { + degraded = Blocks.SOUL_SAND; + } + if (degraded != null) { + world.playEvent(2001, offset, Block.getStateId(state)); + world.setBlockState(offset, degraded.getDefaultState()); + } + + // ignite blocks + if (AbstractFireBlock.canLightBlock(world, offset, Direction.NORTH)) { + BlockState fire = AbstractFireBlock.getFireForPlacement(world, offset); + world.setBlockState(offset, fire); + world.playEvent(1009, offset, 0); + } + } + } + + @Override + public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { + return ModConfig.instance.netherDecayEffect.get() && type.isSimilar(NaturesAuraAPI.TYPE_NETHER); + } + + @Override + public ResourceLocation getName() { + return NAME; + } +} diff --git a/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/nether_decay.json b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/nether_decay.json new file mode 100644 index 00000000..bc611483 --- /dev/null +++ b/src/main/resources/data/naturesaura/patchouli_books/book/en_us/entries/effects/nether_decay.json @@ -0,0 +1,12 @@ +{ + "name": "Crimson Decay", + "icon": "minecraft:soul_sand", + "category": "effects", + "advancement": "naturesaura:negative_imbalance", + "pages": [ + { + "type": "text", + "text": "As it turns out, the effects of $(l:effects/decay)Natural Decay$() extend to the $(thing)nether$() in a way: When the $(aura) levels are low enough, $(item)netherrack$() and other blocks will start to $(thing)decay$() as well. First, they will transform into $(item)soul soil$(), then into $(item)soul sand$(), inevitably making the area truly hard to traverse. Additionally, blocks will also start to $(thing)ignite$() seemingly at random." + } + ] +} \ No newline at end of file