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;
|
2020-01-22 23:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
2020-01-21 21:04:44 +01:00
|
|
|
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;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.item.Items;
|
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;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.world.gen.Heightmap;
|
2020-01-28 18:08:56 +01:00
|
|
|
import net.minecraft.world.server.ServerWorld;
|
2018-10-30 18:18:56 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
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)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2018-11-28 19:49:40 +01:00
|
|
|
int aura = IAuraChunk.getAuraInArea(world, pos, 30);
|
2019-01-29 11:46:38 +01:00
|
|
|
if (aura < 1500000)
|
2019-02-09 21:55:40 +01:00
|
|
|
return false;
|
2019-02-22 11:56:36 +01:00
|
|
|
this.amount = Math.min(45, MathHelper.ceil(Math.abs(aura) / 100000F / IAuraChunk.getSpotAmountInArea(world, pos, 30)));
|
2019-02-09 21:55:40 +01:00
|
|
|
if (this.amount <= 1)
|
|
|
|
return false;
|
|
|
|
this.dist = MathHelper.clamp(Math.abs(aura) / 150000, 5, 35);
|
|
|
|
return true;
|
|
|
|
}
|
2018-10-30 18:18:56 +01:00
|
|
|
|
2019-02-09 21:55:40 +01:00
|
|
|
@Override
|
2020-01-23 16:05:52 +01:00
|
|
|
public ActiveType 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))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INACTIVE;
|
2020-01-21 21:04:44 +01:00
|
|
|
if (player.getDistanceSq(pos.getX(), pos.getY(), pos.getZ()) > this.dist * this.dist)
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INACTIVE;
|
2019-02-09 21:55:40 +01:00
|
|
|
if (NaturesAuraAPI.instance().isEffectPowderActive(player.world, player.getPosition(), NAME))
|
2020-01-23 16:05:52 +01:00
|
|
|
return ActiveType.INHIBITED;
|
|
|
|
return ActiveType.ACTIVE;
|
2019-02-09 21:55:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getDisplayIcon() {
|
|
|
|
return new ItemStack(Items.WHEAT_SEEDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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--) {
|
|
|
|
int x = MathHelper.floor(pos.getX() + world.rand.nextGaussian() * this.dist);
|
|
|
|
int z = MathHelper.floor(pos.getZ() + world.rand.nextGaussian() * this.dist);
|
2020-02-08 01:21:29 +01:00
|
|
|
BlockPos plantPos = new BlockPos(x, world.getHeight(Heightmap.Type.WORLD_SURFACE, x, z), z).down();
|
2019-02-09 21:55:40 +01:00
|
|
|
if (plantPos.distanceSq(pos) <= this.dist * this.dist && world.isBlockLoaded(plantPos)) {
|
2019-01-28 14:58:08 +01:00
|
|
|
if (NaturesAuraAPI.instance().isEffectPowderActive(world, plantPos, NAME))
|
2018-12-14 00:47:01 +01:00
|
|
|
continue;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
BlockState state = world.getBlockState(plantPos);
|
2018-10-30 18:18:56 +01:00
|
|
|
Block block = state.getBlock();
|
2020-02-08 13:19:38 +01:00
|
|
|
if (block instanceof IGrowable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK) {
|
2018-10-30 18:18:56 +01:00
|
|
|
IGrowable growable = (IGrowable) block;
|
|
|
|
if (growable.canGrow(world, plantPos, state, false)) {
|
2020-03-14 00:47:54 +01:00
|
|
|
try {
|
|
|
|
growable.grow((ServerWorld) world, world.rand, plantPos, state);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// Vanilla issue causes bamboo to crash if grown close to world height
|
|
|
|
if (!(growable instanceof BambooBlock))
|
|
|
|
throw e;
|
|
|
|
}
|
2018-11-11 13:26:19 +01:00
|
|
|
BlockPos closestSpot = IAuraChunk.getHighestSpot(world, plantPos, 25, pos);
|
2019-01-29 11:46:38 +01:00
|
|
|
IAuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 3500);
|
2018-10-30 18:18:56 +01:00
|
|
|
|
2020-01-22 23:21:52 +01:00
|
|
|
PacketHandler.sendToAllAround(world, plantPos, 32,
|
2020-01-26 00:16:06 +01:00
|
|
|
new PacketParticles(plantPos.getX(), plantPos.getY(), plantPos.getZ(), PacketParticles.Type.PLANT_BOOST));
|
2018-10-30 18:18:56 +01: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) {
|
2020-01-24 17:05:41 +01:00
|
|
|
return ModConfig.instance.plantBoostEffect.get() && 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-30 18:18:56 +01:00
|
|
|
}
|