mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-17 01:43:12 +01:00
54 lines
2.1 KiB
Java
54 lines
2.1 KiB
Java
|
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;
|
||
|
}
|
||
|
}
|