2018-11-21 17:45:06 +01:00
|
|
|
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;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.Blocks;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-02-09 21:55:40 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2018-11-21 17:45:06 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraft.world.Explosion;
|
2018-11-21 17:45:06 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
2020-01-21 23:02:39 +01:00
|
|
|
import net.minecraft.world.gen.Heightmap;
|
2018-11-21 17:45:06 +01:00
|
|
|
|
|
|
|
public class ExplosionEffect implements IDrainSpotEffect {
|
|
|
|
|
|
|
|
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "explosions");
|
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
private float strength;
|
|
|
|
private int dist;
|
|
|
|
|
2020-01-21 23:02:39 +01:00
|
|
|
private boolean calcValues(World world, BlockPos pos, Integer spot) {
|
2019-02-09 21:55:40 +01:00
|
|
|
if (spot >= 0)
|
|
|
|
return false;
|
2018-11-21 17:45:06 +01:00
|
|
|
int aura = IAuraChunk.getAuraInArea(world, pos, 85);
|
2019-01-29 11:46:38 +01:00
|
|
|
if (aura > -5000000)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2019-02-15 17:51:26 +01:00
|
|
|
int chance = 140 - Math.abs(aura) / 200000;
|
|
|
|
if (chance > 1 && world.rand.nextInt(chance) != 0)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
|
|
|
this.strength = Math.min(Math.abs(aura) / 5000000F, 5F);
|
|
|
|
if (this.strength <= 0)
|
|
|
|
return false;
|
|
|
|
this.dist = MathHelper.clamp(Math.abs(aura) / 200000, 25, 100);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public int isActiveHere(PlayerEntity player, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2019-02-09 21:55:40 +01:00
|
|
|
if (!this.calcValues(player.world, pos, spot))
|
|
|
|
return -1;
|
2020-01-21 23:02:39 +01:00
|
|
|
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
|
2019-02-09 21:55:40 +01:00
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getDisplayIcon() {
|
|
|
|
return new ItemStack(Blocks.TNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
2020-01-21 23:02:39 +01:00
|
|
|
if (world.getGameTime() % 40 != 0)
|
2018-11-21 17:45:06 +01:00
|
|
|
return;
|
2020-01-21 23:02:39 +01:00
|
|
|
if (!this.calcValues(world, pos, spot))
|
2018-11-21 17:45:06 +01:00
|
|
|
return;
|
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * this.dist);
|
|
|
|
int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * this.dist);
|
2020-01-21 23:02:39 +01:00
|
|
|
BlockPos chosenPos = new BlockPos(x, world.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z);
|
2019-02-09 21:55:40 +01:00
|
|
|
if (chosenPos.distanceSq(pos) <= this.dist * this.dist && world.isBlockLoaded(chosenPos)) {
|
2020-01-21 23:02:39 +01:00
|
|
|
world.createExplosion(null,
|
2018-11-21 17:45:06 +01:00
|
|
|
chosenPos.getX() + 0.5, chosenPos.getY() + 0.5, chosenPos.getZ() + 0.5,
|
2020-01-21 23:02:39 +01:00
|
|
|
this.strength, false, Explosion.Mode.DESTROY);
|
2018-11-21 17:45:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
|
|
|
return ModConfig.enabledFeatures.explosionEffect;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getName() {
|
|
|
|
return NAME;
|
|
|
|
}
|
|
|
|
}
|