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.*;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-02-09 21:55:40 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
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;
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
private int amount;
|
|
|
|
private int dist;
|
|
|
|
|
|
|
|
private boolean calcValues(World world, BlockPos pos, Integer spot) {
|
2018-12-02 01:36:41 +01:00
|
|
|
if (spot < 0) {
|
2018-11-29 17:58:47 +01:00
|
|
|
int aura = IAuraChunk.getAuraInArea(world, pos, 50);
|
2018-10-25 18:49:42 +02:00
|
|
|
if (aura < 0) {
|
2019-02-22 12:06:14 +01:00
|
|
|
this.amount = Math.min(300, MathHelper.ceil(Math.abs(aura) / 100000F / IAuraChunk.getSpotAmountInArea(world, pos, 50)));
|
2019-02-09 21:55:40 +01:00
|
|
|
if (this.amount > 1) {
|
|
|
|
this.dist = MathHelper.clamp(Math.abs(aura) / 75000, 5, 75);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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(ModBlocks.DECAYED_LEAVES);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, Integer spot) {
|
|
|
|
if (!this.calcValues(world, pos, spot))
|
|
|
|
return;
|
|
|
|
for (int i = this.amount / 2 + world.rand.nextInt(this.amount / 2); i >= 0; i--) {
|
|
|
|
BlockPos grassPos = new BlockPos(
|
|
|
|
pos.getX() + world.rand.nextGaussian() * this.dist,
|
|
|
|
pos.getY() + world.rand.nextGaussian() * this.dist,
|
|
|
|
pos.getZ() + world.rand.nextGaussian() * this.dist
|
|
|
|
);
|
|
|
|
if (grassPos.distanceSq(pos) <= this.dist * this.dist && world.isBlockLoaded(grassPos)) {
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState state = world.getBlockState(grassPos);
|
2019-02-09 21:55:40 +01:00
|
|
|
Block block = state.getBlock();
|
2018-10-25 18:49:42 +02:00
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState newState = null;
|
2020-01-21 23:02:39 +01:00
|
|
|
if (block instanceof LeavesBlock) {
|
2019-02-09 21:55:40 +01:00
|
|
|
newState = ModBlocks.DECAYED_LEAVES.getDefaultState();
|
2020-01-21 23:02:39 +01:00
|
|
|
} else if (block instanceof GrassBlock) {
|
|
|
|
newState = Blocks.COARSE_DIRT.getDefaultState();
|
|
|
|
} else if (block instanceof BushBlock) {
|
2019-02-09 21:55:40 +01:00
|
|
|
newState = Blocks.AIR.getDefaultState();
|
2018-10-25 18:49:42 +02:00
|
|
|
}
|
2019-02-09 21:55:40 +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) {
|
2019-02-16 21:31:37 +01:00
|
|
|
return ModConfig.enabledFeatures.grassDieEffect && type.isSimilar(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
|
|
|
}
|