made the plant boost effect also affect underground plants

Closes #297
This commit is contained in:
Ell 2023-02-05 14:43:03 +01:00
parent 4c29b7a380
commit 2953dd0eea

View file

@ -16,9 +16,11 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.DoublePlantBlock;
import net.minecraft.world.level.block.TallGrassBlock;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.levelgen.Heightmap;
public class PlantBoostEffect implements IDrainSpotEffect { public class PlantBoostEffect implements IDrainSpotEffect {
@ -34,7 +36,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
int aura = auraAndSpots.getLeft(); int aura = auraAndSpots.getLeft();
if (aura < 1500000) if (aura < 1500000)
return false; return false;
this.amount = Math.min(45, Mth.ceil(Math.abs(aura) / 100000F / auraAndSpots.getRight())); this.amount = Math.min(75, Mth.ceil(Math.abs(aura) / 50000F / auraAndSpots.getRight()));
if (this.amount <= 1) if (this.amount <= 1)
return false; return false;
this.dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35); this.dist = Mth.clamp(Math.abs(aura) / 150000, 5, 35);
@ -63,15 +65,16 @@ public class PlantBoostEffect implements IDrainSpotEffect {
return; return;
for (var i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) { for (var i = this.amount / 2 + level.random.nextInt(this.amount / 2); i >= 0; i--) {
var x = Mth.floor(pos.getX() + (2 * level.random.nextFloat() - 1) * this.dist); var x = Mth.floor(pos.getX() + (2 * level.random.nextFloat() - 1) * this.dist);
var y = Mth.floor(pos.getY() + (2 * level.random.nextFloat() - 1) * this.dist);
var z = Mth.floor(pos.getZ() + (2 * level.random.nextFloat() - 1) * this.dist); var z = Mth.floor(pos.getZ() + (2 * level.random.nextFloat() - 1) * this.dist);
var plantPos = new BlockPos(x, level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z), z).below(); var plantPos = new BlockPos(x, y, z).below();
if (plantPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(plantPos)) { if (plantPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(plantPos)) {
if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, PlantBoostEffect.NAME)) if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, PlantBoostEffect.NAME))
continue; continue;
var state = level.getBlockState(plantPos); var state = level.getBlockState(plantPos);
var block = state.getBlock(); var block = state.getBlock();
if (block instanceof BonemealableBlock growable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK) { if (block instanceof BonemealableBlock growable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK && block != Blocks.MOSS_BLOCK) {
if (growable.isValidBonemealTarget(level, plantPos, state, false)) { if (growable.isValidBonemealTarget(level, plantPos, state, false)) {
try { try {
growable.performBonemeal((ServerLevel) level, level.random, plantPos, state); growable.performBonemeal((ServerLevel) level, level.random, plantPos, state);