added explosion effect

This commit is contained in:
Ellpeck 2018-11-21 17:45:06 +01:00
parent 7d4ae9cb6d
commit 6275a326de
6 changed files with 86 additions and 22 deletions

View file

@ -38,6 +38,8 @@ public final class ModConfig {
public boolean grassDieEffect = true; public boolean grassDieEffect = true;
@Comment("If the Aura Imbalance effect of plant growth being boosted if the Aura levels are high enough should occur") @Comment("If the Aura Imbalance effect of plant growth being boosted if the Aura levels are high enough should occur")
public boolean plantBoostEffect = true; 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 { public static class Client {

View file

@ -9,5 +9,6 @@ public final class DrainSpotEffects {
NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(PlantBoostEffect.NAME, PlantBoostEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(PlantBoostEffect.NAME, PlantBoostEffect::new);
NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ReplenishingEffect.NAME, ReplenishingEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ReplenishingEffect.NAME, ReplenishingEffect::new);
NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(BalanceEffect.NAME, BalanceEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(BalanceEffect.NAME, BalanceEffect::new);
NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ExplosionEffect.NAME, ExplosionEffect::new);
} }
} }

View file

@ -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;
}
}

View file

@ -29,28 +29,26 @@ public class GrassDieEffect implements IDrainSpotEffect {
int amount = Math.min(300, Math.abs(aura) / 1000); int amount = Math.min(300, Math.abs(aura) / 1000);
if (amount > 1) { if (amount > 1) {
int dist = MathHelper.clamp(Math.abs(aura) / 750, 5, 45); 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--) {
for (int i = amount / 2 + world.rand.nextInt(amount / 2); i >= 0; i--) { BlockPos grassPos = new BlockPos(
BlockPos grassPos = new BlockPos( pos.getX() + world.rand.nextGaussian() * dist,
pos.getX() + world.rand.nextGaussian() * dist, pos.getY() + world.rand.nextGaussian() * dist,
pos.getY() + world.rand.nextGaussian() * dist, pos.getZ() + world.rand.nextGaussian() * dist
pos.getZ() + world.rand.nextGaussian() * dist );
); if (grassPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(grassPos)) {
if (grassPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(grassPos)) { IBlockState state = world.getBlockState(grassPos);
IBlockState state = world.getBlockState(grassPos); Block block = state.getBlock();
Block block = state.getBlock();
IBlockState newState = null; IBlockState newState = null;
if (block instanceof BlockLeaves) { if (block instanceof BlockLeaves) {
newState = ModBlocks.DECAYED_LEAVES.getDefaultState(); newState = ModBlocks.DECAYED_LEAVES.getDefaultState();
} else if (block instanceof BlockGrass) { } else if (block instanceof BlockGrass) {
newState = Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT); newState = Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT);
} else if (block instanceof BlockBush) { } else if (block instanceof BlockBush) {
newState = Blocks.AIR.getDefaultState(); newState = Blocks.AIR.getDefaultState();
}
if (newState != null)
world.setBlockState(grassPos, newState);
} }
if (newState != null)
world.setBlockState(grassPos, newState);
} }
} }
} }

View file

@ -34,8 +34,6 @@ public class PlantBoostEffect implements IDrainSpotEffect {
if (amount <= 1) if (amount <= 1)
return; return;
int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35); 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--) { for (int i = amount / 2 + world.rand.nextInt(amount / 2); i >= 0; i--) {
int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * dist); int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * dist);

View file

@ -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."
}
]
}