diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java index 45f8845c..a21e8584 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java @@ -19,10 +19,7 @@ import org.apache.commons.lang3.mutable.MutableInt; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiConsumer; import java.util.function.Supplier; @@ -57,19 +54,17 @@ public class AuraChunk implements IAuraChunk { @Override public void drainAura(BlockPos pos, int amount) { - MutableInt spot = this.getDrainSpot(pos); - spot.subtract(amount); - if (spot.intValue() == 0) - this.drainSpots.remove(pos); + if (amount <= 0) + return; + this.getDrainSpot(pos).subtract(amount); this.markDirty(); } @Override public void storeAura(BlockPos pos, int amount) { - MutableInt spot = this.getDrainSpot(pos); - spot.add(amount); - if (spot.intValue() == 0) - this.drainSpots.remove(pos); + if (amount <= 0) + return; + this.getDrainSpot(pos).add(amount); this.markDirty(); } @@ -100,20 +95,34 @@ public class AuraChunk implements IAuraChunk { public void update() { World world = this.chunk.getWorld(); + + Set toClear = null; + for (Map.Entry entry : this.drainSpots.entrySet()) { + BlockPos pos = entry.getKey(); + MutableInt amount = entry.getValue(); + for (IDrainSpotEffect effect : this.effects) { + world.profiler.func_194340_a(() -> effect.getName().toString()); + effect.update(world, this.chunk, this, pos, amount); + world.profiler.endSection(); + } + if (amount.intValue() == 0) { + if (toClear == null) + toClear = new HashSet<>(); + toClear.add(pos); + } + } + if (toClear != null) { + for (BlockPos spot : toClear) + this.drainSpots.remove(spot); + this.markDirty(); + } + if (this.needsSync) { PacketHandler.sendToAllLoaded(world, new BlockPos(this.chunk.x * 16, 0, this.chunk.z * 16), this.makePacket()); this.needsSync = false; } - - for (Map.Entry entry : this.drainSpots.entrySet()) { - for (IDrainSpotEffect effect : this.effects) { - world.profiler.func_194340_a(() -> effect.getName().toString()); - effect.update(world, this.chunk, this, entry.getKey(), entry.getValue()); - world.profiler.endSection(); - } - } } public IMessage makePacket() { diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/MigrationEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java similarity index 94% rename from src/main/java/de/ellpeck/naturesaura/chunk/effect/MigrationEffect.java rename to src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java index 6271176c..5a07375b 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/MigrationEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/BalanceEffect.java @@ -10,9 +10,9 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import org.apache.commons.lang3.mutable.MutableInt; -public class MigrationEffect implements IDrainSpotEffect { +public class BalanceEffect implements IDrainSpotEffect { - public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "migration"); + public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "balance"); @Override public void update(World world, Chunk chunk, IAuraChunk auraChunk, BlockPos pos, MutableInt spot) { diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java index 54d7aa3a..905bb3fe 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/DrainSpotEffects.java @@ -8,6 +8,6 @@ public final class DrainSpotEffects { NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(GrassDieEffect.NAME, GrassDieEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(PlantBoostEffect.NAME, PlantBoostEffect::new); NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(ReplenishingEffect.NAME, ReplenishingEffect::new); - NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(MigrationEffect.NAME, MigrationEffect::new); + NaturesAuraAPI.DRAIN_SPOT_EFFECTS.put(BalanceEffect.NAME, BalanceEffect::new); } }