From 6275a326dee111d263ff7de4fd2b327d1b267710 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 21 Nov 2018 17:45:06 +0100 Subject: [PATCH] added explosion effect --- .../de/ellpeck/naturesaura/ModConfig.java | 2 + .../chunk/effect/DrainSpotEffects.java | 1 + .../chunk/effect/ExplosionEffect.java | 53 +++++++++++++++++++ .../chunk/effect/GrassDieEffect.java | 38 +++++++------ .../chunk/effect/PlantBoostEffect.java | 2 - .../en_us/entries/effects/explosions.json | 12 +++++ 6 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/chunk/effect/ExplosionEffect.java create mode 100644 src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/explosions.json diff --git a/src/main/java/de/ellpeck/naturesaura/ModConfig.java b/src/main/java/de/ellpeck/naturesaura/ModConfig.java index 77f824fe..eaf9306b 100644 --- a/src/main/java/de/ellpeck/naturesaura/ModConfig.java +++ b/src/main/java/de/ellpeck/naturesaura/ModConfig.java @@ -38,6 +38,8 @@ public final class ModConfig { public boolean grassDieEffect = true; @Comment("If the Aura Imbalance effect of plant growth being boosted if the Aura levels are high enough should occur") public boolean plantBoostEffect = true; + @Comment("If the Aura Imbalance effect of explosions happening randomly if Aura levels are too low should occur") + public boolean explosionEffect = true; } public static class Client { 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 905bb3fe..18db8816 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java @@ -9,5 +9,6 @@ public final class DrainSpotEffects { NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(PlantBoostEffect.NAME, PlantBoostEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ReplenishingEffect.NAME, ReplenishingEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(BalanceEffect.NAME, BalanceEffect::new); + NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ExplosionEffect.NAME, ExplosionEffect::new); } } diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/ExplosionEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/ExplosionEffect.java new file mode 100644 index 00000000..7515861d --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/ExplosionEffect.java @@ -0,0 +1,53 @@ +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.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; +import org.apache.commons.lang3.mutable.MutableInt; + +public class ExplosionEffect implements IDrainSpotEffect { + + public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "explosions"); + + @Override + public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, MutableInt spot) { + if (spot.intValue() >= 0 || world.getTotalWorldTime() % 40 != 0) + return; + int aura = IAuraChunk.getAuraInArea(world, pos, 85); + if (aura > -50000) + return; + int chance = 140 - Math.abs(aura) / 2000; + if (chance > 1 && world.rand.nextInt(chance) != 0) + return; + float strength = Math.min(Math.abs(aura) / 50000F, 5F); + if (strength <= 0) + return; + int dist = MathHelper.clamp(Math.abs(aura) / 2000, 25, 100); + + int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * dist); + int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * dist); + BlockPos chosenPos = new BlockPos(x, world.getHeight(x, z), z); + if (chosenPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(chosenPos)) { + world.newExplosion(null, + chosenPos.getX() + 0.5, chosenPos.getY() + 0.5, chosenPos.getZ() + 0.5, + strength, false, true); + } + } + + @Override + public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) { + return ModConfig.enabledFeatures.explosionEffect; + } + + @Override + public ResourceLocation getName() { + return NAME; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java index 361d22ae..2715218d 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/GrassDieEffect.java @@ -29,28 +29,26 @@ public class GrassDieEffect implements IDrainSpotEffect { int amount = Math.min(300, Math.abs(aura) / 1000); if (amount > 1) { int dist = MathHelper.clamp(Math.abs(aura) / 750, 5, 45); - if (dist > 0) { - for (int i = amount / 2 + world.rand.nextInt(amount / 2); i >= 0; i--) { - BlockPos grassPos = new BlockPos( - pos.getX() + world.rand.nextGaussian() * dist, - pos.getY() + world.rand.nextGaussian() * dist, - pos.getZ() + world.rand.nextGaussian() * dist - ); - if (grassPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(grassPos)) { - IBlockState state = world.getBlockState(grassPos); - Block block = state.getBlock(); + for (int i = amount / 2 + world.rand.nextInt(amount / 2); i >= 0; i--) { + BlockPos grassPos = new BlockPos( + pos.getX() + world.rand.nextGaussian() * dist, + pos.getY() + world.rand.nextGaussian() * dist, + pos.getZ() + world.rand.nextGaussian() * dist + ); + if (grassPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(grassPos)) { + IBlockState state = world.getBlockState(grassPos); + Block block = state.getBlock(); - IBlockState newState = null; - if (block instanceof BlockLeaves) { - newState = ModBlocks.DECAYED_LEAVES.getDefaultState(); - } else if (block instanceof BlockGrass) { - newState = Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT); - } else if (block instanceof BlockBush) { - newState = Blocks.AIR.getDefaultState(); - } - if (newState != null) - world.setBlockState(grassPos, newState); + IBlockState newState = null; + if (block instanceof BlockLeaves) { + newState = ModBlocks.DECAYED_LEAVES.getDefaultState(); + } else if (block instanceof BlockGrass) { + newState = Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT); + } else if (block instanceof BlockBush) { + newState = Blocks.AIR.getDefaultState(); } + if (newState != null) + world.setBlockState(grassPos, newState); } } } diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java index 853cf0a2..2c590336 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java @@ -34,8 +34,6 @@ public class PlantBoostEffect implements IDrainSpotEffect { if (amount <= 1) return; int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35); - if (dist <= 0) - return; for (int i = amount / 2 + world.rand.nextInt(amount / 2); i >= 0; i--) { int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * dist); diff --git a/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/explosions.json b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/explosions.json new file mode 100644 index 00000000..0d4799b0 --- /dev/null +++ b/src/main/resources/assets/naturesaura/patchouli_books/book/en_us/entries/effects/explosions.json @@ -0,0 +1,12 @@ +{ + "name": "Unstable Outbreak", + "icon": "minecraft:tnt", + "category": "effects", + "advancement": "naturesaura:furnace_heater", + "pages": [ + { + "type": "text", + "text": "When the $(aura) levels in the area are extremely low, to the point that $(item)Natural Decay$() has already done all of the work it can, but the levels are still not increased, nature itself loses stability to the point of $(item)Unstable Outbreak$(): $(thing)Explosions$() will start sporadically occuring in a large area on the surface, their severity and interval varying based on the severity of the imbalance." + } + ] +} \ No newline at end of file