diff --git a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java index 181f38db..37cf5867 100644 --- a/src/main/java/de/ellpeck/naturesaura/InternalHooks.java +++ b/src/main/java/de/ellpeck/naturesaura/InternalHooks.java @@ -13,6 +13,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.items.IItemHandler; +import org.apache.commons.lang3.mutable.MutableFloat; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableObject; import org.lwjgl.util.vector.Vector3f; @@ -96,6 +97,16 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks { return result.intValue(); } + @Override + public int triangulateAuraInArea(World world, BlockPos pos, int radius) { + MutableFloat result = new MutableFloat(IAuraChunk.DEFAULT_AURA); + IAuraChunk.getSpotsInArea(world, pos, radius, (blockPos, spot) -> { + float percentage = 1F - (float) pos.getDistance(blockPos.getX(), blockPos.getY(), blockPos.getZ()) / radius; + result.add(spot * percentage); + }); + return result.intValue(); + } + @Override public BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) { MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE); diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 288cfb07..c8901548 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -232,6 +232,11 @@ public final class NaturesAuraAPI { */ int getAuraInArea(World world, BlockPos pos, int radius); + /** + * @see IAuraChunk#triangulateAuraInArea(World, BlockPos, int) + */ + int triangulateAuraInArea(World world, BlockPos pos, int radius); + /** * @see IAuraChunk#getLowestSpot(World, BlockPos, int, BlockPos) */ diff --git a/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java b/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java index 180be65d..7c1d9785 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/api/aura/chunk/IAuraChunk.java @@ -65,7 +65,8 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable { - float percentage = 1F - (float) this.pos.getDistance(pos.getX(), pos.getY(), pos.getZ()) / 25F; - totalAmount.add(spot * percentage); - }); - int power = MathHelper.clamp(MathHelper.ceil(totalAmount.intValue() / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15); + int totalAmount = IAuraChunk.triangulateAuraInArea(this.world, this.pos, 25); + int power = MathHelper.clamp(MathHelper.ceil(totalAmount / (IAuraChunk.DEFAULT_AURA * 2F) * 15F), 0, 15); if (this.redstonePower != power) { this.redstonePower = power; this.world.updateComparatorOutputLevel(this.pos, this.getBlockType()); diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 3789e24b..14c74599 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.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.IItemHandler; -import org.apache.commons.lang3.mutable.MutableFloat; import org.apache.commons.lang3.mutable.MutableInt; import org.lwjgl.opengl.GL11; @@ -240,12 +239,8 @@ public class ClientEvents { if (!mc.gameSettings.showDebugInfo) { GlStateManager.color(83 / 255F, 160 / 255F, 8 / 255F); - MutableFloat totalAmount = new MutableFloat(IAuraChunk.DEFAULT_AURA); - IAuraChunk.getSpotsInArea(mc.world, mc.player.getPosition(), 35, (pos, spot) -> { - float percentage = 1F - (float) mc.player.getDistance(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F) / 35F; - totalAmount.add(spot * percentage); - }); - float totalPercentage = totalAmount.intValue() / (IAuraChunk.DEFAULT_AURA * 2F); + int totalAmount = IAuraChunk.triangulateAuraInArea(mc.world, mc.player.getPosition(), 35); + float totalPercentage = totalAmount / (IAuraChunk.DEFAULT_AURA * 2F); int tHeight = MathHelper.ceil(MathHelper.clamp(totalPercentage, 0F, 1F) * 50); if (tHeight < 50)