2018-11-13 11:39:28 +01:00
|
|
|
package de.ellpeck.naturesaura.chunk.effect;
|
2018-10-25 18:49:42 +02:00
|
|
|
|
2018-11-13 18:21:41 +01:00
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
2018-11-13 11:39:28 +01:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2018-11-12 01:29:33 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
|
2018-11-12 01:29:33 +01:00
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2018-10-25 18:49:42 +02:00
|
|
|
import de.ellpeck.naturesaura.blocks.ModBlocks;
|
|
|
|
import net.minecraft.block.*;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.init.Blocks;
|
2018-11-13 11:39:28 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-10-25 18:49:42 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-10-26 15:01:48 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2018-10-25 18:49:42 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.chunk.Chunk;
|
|
|
|
import org.apache.commons.lang3.mutable.MutableInt;
|
|
|
|
|
|
|
|
public class GrassDieEffect implements IDrainSpotEffect {
|
2018-11-13 11:39:28 +01:00
|
|
|
|
|
|
|
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "grass_die");
|
|
|
|
|
2018-10-25 18:49:42 +02:00
|
|
|
@Override
|
2018-11-11 13:26:19 +01:00
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, MutableInt spot) {
|
2018-10-25 18:49:42 +02:00
|
|
|
if (spot.intValue() < 0) {
|
2018-11-11 13:26:19 +01:00
|
|
|
int aura = IAuraChunk.getAuraInArea(world, pos, 25);
|
2018-10-25 18:49:42 +02:00
|
|
|
if (aura < 0) {
|
|
|
|
int amount = Math.min(300, Math.abs(aura) / 1000);
|
2018-10-26 15:01:48 +02:00
|
|
|
if (amount > 1) {
|
|
|
|
int dist = MathHelper.clamp(Math.abs(aura) / 750, 5, 45);
|
2018-11-21 17:45:06 +01:00
|
|
|
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();
|
2018-10-25 18:49:42 +02:00
|
|
|
|
2018-11-21 17:45:06 +01:00
|
|
|
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();
|
2018-10-25 18:49:42 +02:00
|
|
|
}
|
2018-11-21 17:45:06 +01:00
|
|
|
if (newState != null)
|
|
|
|
world.setBlockState(grassPos, newState);
|
2018-10-25 18:49:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 23:42:13 +01:00
|
|
|
|
|
|
|
@Override
|
2018-11-13 18:21:41 +01:00
|
|
|
public boolean appliesHere(Chunk chunk, IAuraChunk auraChunk, IAuraType type) {
|
|
|
|
return ModConfig.enabledFeatures.grassDieEffect && type == NaturesAuraAPI.TYPE_OVERWORLD;
|
2018-11-07 23:42:13 +01:00
|
|
|
}
|
2018-11-13 11:39:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getName() {
|
|
|
|
return NAME;
|
|
|
|
}
|
2018-10-25 18:49:42 +02:00
|
|
|
}
|