diff --git a/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java b/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java index c1d83bb6..3d96ba4c 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/chunk/AuraChunk.java @@ -79,21 +79,36 @@ public class AuraChunk implements ICapabilityProvider, INBTSerializable closestSpot = new MutableObject<>(); + public static BlockPos getLowestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) { + MutableInt lowestAmount = new MutableInt(Integer.MAX_VALUE); + MutableObject lowestSpot = new MutableObject<>(); getSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> { - double dist = pos.distanceSq(blockPos); - if (dist < closestDist.doubleValue()) { - closestDist.setValue(dist); - closestSpot.setValue(blockPos); + int amount = drainSpot.intValue(); + if (amount < lowestAmount.intValue()) { + lowestAmount.setValue(amount); + lowestSpot.setValue(blockPos); } }); - BlockPos closest = closestSpot.getValue(); - if (closest == null) { - closest = defaultSpot; - } - return closest; + BlockPos lowest = lowestSpot.getValue(); + if (lowest == null) + lowest = defaultSpot; + return lowest; + } + + public static BlockPos getHighestSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot) { + MutableInt highestAmount = new MutableInt(Integer.MIN_VALUE); + MutableObject highestSpot = new MutableObject<>(); + getSpotsInArea(world, pos, radius, (blockPos, drainSpot) -> { + int amount = drainSpot.intValue(); + if (amount > highestAmount.intValue()) { + highestAmount.setValue(amount); + highestSpot.setValue(blockPos); + } + }); + BlockPos highest = highestSpot.getValue(); + if (highest == null) + highest = defaultSpot; + return highest; } public void getSpotsInArea(BlockPos pos, int radius, BiConsumer consumer) { diff --git a/src/main/java/de/ellpeck/naturesaura/aura/chunk/effect/PlantBoostEffect.java b/src/main/java/de/ellpeck/naturesaura/aura/chunk/effect/PlantBoostEffect.java index d6e66b8e..ccc28718 100644 --- a/src/main/java/de/ellpeck/naturesaura/aura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/aura/chunk/effect/PlantBoostEffect.java @@ -24,7 +24,7 @@ public class PlantBoostEffect implements IDrainSpotEffect { if (aura <= 0) return; int amount = Math.min(45, Math.abs(aura) / 1000); - if (amount <= 0) + if (amount <= 1) return; int dist = MathHelper.clamp(Math.abs(aura) / 1500, 5, 35); if (dist <= 0) @@ -42,7 +42,7 @@ public class PlantBoostEffect implements IDrainSpotEffect { if (growable.canGrow(world, plantPos, state, false)) { growable.grow(world, world.rand, plantPos, state); - BlockPos closestSpot = AuraChunk.getClosestSpot(world, plantPos, 25, pos); + BlockPos closestSpot = AuraChunk.getHighestSpot(world, plantPos, 25, pos); AuraChunk.getAuraChunk(world, closestSpot).drainAura(closestSpot, 25); PacketHandler.sendToAllAround(world, plantPos, 32, diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFurnaceHeater.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFurnaceHeater.java index a48957a8..39258491 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFurnaceHeater.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityFurnaceHeater.java @@ -33,7 +33,7 @@ public class TileEntityFurnaceHeater extends TileEntityImpl implements ITickable //if set higher than 199, it'll never finish because the furnace does ++ and then == furnace.setField(2, Math.min(199, furnace.getField(2) + 5)); - BlockPos spot = AuraChunk.getClosestSpot(this.world, this.pos, 15, this.pos); + BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 15, this.pos); AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot); chunk.drainAura(spot, MathHelper.ceil((200 - time) / 4F)); did = true; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java index 5e03bdda..3626b307 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java @@ -68,9 +68,9 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable { if (this.structureFine) { int space = this.container.storeAura(3, true); if (space > 0) { - int toStore = Math.min(AuraChunk.getAuraInArea(this.world, this.pos, 10), space); + int toStore = Math.min(AuraChunk.getAuraInArea(this.world, this.pos, 20), space); if (toStore > 0) { - BlockPos spot = AuraChunk.getClosestSpot(this.world, this.pos, 10, this.pos); + BlockPos spot = AuraChunk.getHighestSpot(this.world, this.pos, 20, this.pos); AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot); chunk.drainAura(spot, toStore); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPotionGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPotionGenerator.java index 6a77522a..4baf66ea 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPotionGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityPotionGenerator.java @@ -41,21 +41,30 @@ public class TileEntityPotionGenerator extends TileEntityImpl implements ITickab continue; } - boolean dispersed = false; - int toAdd = (effect.getAmplifier() * 5 + 1) * (effect.getDuration() / 40); - for (EnumFacing dir : EnumFacing.HORIZONTALS) { - BlockPos offset = this.pos.offset(dir, 8); - BlockPos spot = AuraChunk.getClosestSpot(this.world, offset, 10, offset); - if (AuraChunk.getAuraInArea(this.world, spot, 10) < 15000) { - AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot); - chunk.storeAura(spot, toAdd / 4); - dispersed = true; + int toAdd = ((effect.getAmplifier() * 5 + 1) * (effect.getDuration() / 40)) / 4; + int toAddTimes = 4; + while (toAddTimes > 0) { + boolean foundEmpty = false; + for (EnumFacing dir : EnumFacing.HORIZONTALS) { + BlockPos offset = this.pos.offset(dir, 12); + BlockPos spot = AuraChunk.getLowestSpot(this.world, offset, 15, offset); + if (AuraChunk.getAuraInArea(this.world, spot, 15) < 20000) { + AuraChunk chunk = AuraChunk.getAuraChunk(this.world, spot); + chunk.storeAura(spot, toAdd); + + foundEmpty = true; + toAddTimes--; + if (toAddTimes <= 0) + break; + } } + if (!foundEmpty) + break; } PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles( this.pos.getX(), this.pos.getY(), this.pos.getZ(), 5, - PotionUtils.getPotionColor(type), dispersed ? 1 : 0)); + PotionUtils.getPotionColor(type), toAddTimes < 4 ? 1 : 0)); addedOne = true; break; diff --git a/src/main/java/de/ellpeck/naturesaura/commands/CommandAura.java b/src/main/java/de/ellpeck/naturesaura/commands/CommandAura.java index f0718f66..3eb906ab 100644 --- a/src/main/java/de/ellpeck/naturesaura/commands/CommandAura.java +++ b/src/main/java/de/ellpeck/naturesaura/commands/CommandAura.java @@ -41,14 +41,14 @@ public class CommandAura extends CommandBase { World world = sender.getEntityWorld(); BlockPos pos = sender.getPosition(); - BlockPos spot = AuraChunk.getClosestSpot(world, pos, range, pos); - AuraChunk chunk = AuraChunk.getAuraChunk(world, spot); if ("add".equals(action)) { - chunk.storeAura(spot, amount); + BlockPos spot = AuraChunk.getLowestSpot(world, pos, range, pos); + AuraChunk.getAuraChunk(world, spot).storeAura(spot, amount); sender.sendMessage(new TextComponentString("Added " + amount + " aura")); } else if ("remove".equals(action)) { - chunk.drainAura(spot, amount); + BlockPos spot = AuraChunk.getHighestSpot(world, pos, range, pos); + AuraChunk.getAuraChunk(world, spot).drainAura(spot, amount); sender.sendMessage(new TextComponentString("Removed " + amount + " aura")); } else { throw new SyntaxErrorException("Invalid action " + action);