2018-11-13 11:39:28 +01:00
|
|
|
package de.ellpeck.naturesaura.chunk.effect;
|
2018-10-30 18:18:56 +01: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-30 18:18:56 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.IGrowable;
|
|
|
|
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-30 18:18:56 +01:00
|
|
|
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 PlantBoostEffect implements IDrainSpotEffect {
|
2018-11-13 11:39:28 +01:00
|
|
|
|
|
|
|
public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "plant_boost");
|
|
|
|
|
2018-10-30 18:18:56 +01: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-30 18:18:56 +01:00
|
|
|
if (spot.intValue() <= 0)
|
|
|
|
return;
|
2018-11-28 19:49:40 +01:00
|
|
|
int aura = IAuraChunk.getAuraInArea(world, pos, 30);
|
|
|
|
if (aura < 15000)
|
2018-10-30 18:18:56 +01:00
|
|
|
return;
|
|
|
|
int amount = Math.min(45, Math.abs(aura) / 1000);
|
2018-10-31 11:50:57 +01:00
|
|
|
if (amount <= 1)
|
2018-10-30 18:18:56 +01:00
|
|
|
return;
|
|
|
|
int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35);
|
|
|
|
|
|
|
|
for (int i = amount / 2 + world.rand.nextInt(amount / 2); i >= 0; i--) {
|
|
|
|
int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * dist);
|
|
|
|
int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * dist);
|
|
|
|
BlockPos plantPos = new BlockPos(x, world.getHeight(x, z), z);
|
|
|
|
if (plantPos.distanceSq(pos) <= dist * dist && world.isBlockLoaded(plantPos)) {
|
|
|
|
IBlockState state = world.getBlockState(plantPos);
|
|
|
|
Block block = state.getBlock();
|
2018-11-13 18:21:41 +01:00
|
|
|
if (block instanceof IGrowable &&
|
|
|
|
block != Blocks.TALLGRASS && block != Blocks.GRASS && block != Blocks.DOUBLE_PLANT) {
|
2018-10-30 18:18:56 +01:00
|
|
|
IGrowable growable = (IGrowable) block;
|
|
|
|
if (growable.canGrow(world, plantPos, state, false)) {
|
|
|
|
growable.grow(world, world.rand, plantPos, state);
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
BlockPos closestSpot = IAuraChunk.getHighestSpot(world, plantPos, 25, pos);
|
|
|
|
IAuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 100);
|
2018-10-30 18:18:56 +01:00
|
|
|
|
|
|
|
PacketHandler.sendToAllAround(world, plantPos, 32,
|
|
|
|
new PacketParticles(plantPos.getX(), plantPos.getY(), plantPos.getZ(), 6));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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.plantBoostEffect && 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-30 18:18:56 +01:00
|
|
|
}
|