From fe71e62ad41039637a6f3a42c69e26f856e44f80 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 5 Feb 2023 15:49:29 +0100 Subject: [PATCH] improved plant boost and particle height calculations --- src/main/java/de/ellpeck/naturesaura/Helper.java | 12 ++++++++++++ .../naturesaura/chunk/effect/PlantBoostEffect.java | 5 +++-- .../de/ellpeck/naturesaura/events/ClientEvents.java | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 63c633f8..9314f4bc 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -321,4 +321,16 @@ public final class Helper { } return ItemStack.EMPTY; } + + public static BlockPos getClosestAirAboveGround(Level level, BlockPos pos, int radius) { + for (var i = 0; i < radius; i++) { + var up = pos.above(i); + if (level.isEmptyBlock(up) && !level.isEmptyBlock(up.below())) + return up; + var dn = pos.below(i); + if (level.isEmptyBlock(dn) && !level.isEmptyBlock(dn.below())) + return dn; + } + return pos; + } } diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java index b990ba53..fe0dded8 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java @@ -1,5 +1,6 @@ package de.ellpeck.naturesaura.chunk.effect; +import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.api.NaturesAuraAPI; @@ -65,9 +66,9 @@ public class PlantBoostEffect implements IDrainSpotEffect { return; 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 y = Mth.floor(pos.getY() + (2 * level.random.nextFloat() - 1) * this.dist); + var y = Mth.floor(pos.getY() + (2 * level.random.nextFloat() - 1) * this.dist / 2); var z = Mth.floor(pos.getZ() + (2 * level.random.nextFloat() - 1) * this.dist); - var plantPos = new BlockPos(x, y, z).below(); + var plantPos = Helper.getClosestAirAboveGround(level, new BlockPos(x, y, z), this.dist / 2).below(); if (plantPos.distSqr(pos) <= this.dist * this.dist && level.isLoaded(plantPos)) { if (NaturesAuraAPI.instance().isEffectPowderActive(level, plantPos, PlantBoostEffect.NAME)) continue; diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 6e7fe177..fb314bab 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -34,7 +34,6 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.MyceliumBlock; -import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -110,8 +109,9 @@ public class ClientEvents { var amount = Mth.floor(190 * ModConfig.instance.excessParticleAmount.get()); for (var i = 0; i < amount; i++) { var x = Mth.floor(mc.player.getX()) + mc.level.random.nextInt(64) - 32; + var y = Mth.floor(mc.player.getY()) + mc.level.random.nextInt(32) - 16; var z = Mth.floor(mc.player.getZ()) + mc.level.random.nextInt(64) - 32; - var pos = new BlockPos(x, mc.level.getHeight(Heightmap.Types.WORLD_SURFACE, x, z) - 1, z); + var pos = Helper.getClosestAirAboveGround(mc.level, new BlockPos(x, y, z), 16).below(); var state = mc.level.getBlockState(pos); var block = state.getBlock(); if (block instanceof BonemealableBlock || block instanceof IPlantable || block instanceof LeavesBlock || block instanceof MyceliumBlock) {