diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index f9f38303..d42aa7b9 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -37,7 +37,7 @@ public final class NaturesAuraAPI { public static final String MOD_ID = "naturesaura"; public static final String API_ID = MOD_ID + "api"; - public static final String VERSION = "1"; + public static final String VERSION = "2"; /** * The list of all {@link AltarRecipe} instances which are the recipes used 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 4fd335a2..2e2a32bd 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 @@ -119,9 +119,51 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable consumer); - void drainAura(BlockPos pos, int amount); + /** + * Drains the given amount of Aura from the given position. Returns the + * amount of Aura that was drained. + * + * @param pos The position + * @param amount The amount to drain + * @param aimForZero If true, and draining the given amount would make the + * level go from positive to negative, an amount will be + * drained instead that will cause the spot's amount to be + * 0. + * @return The amount of Aura drained. Will only be different from the + * supplied amount if stopAtZero is true + */ + int drainAura(BlockPos pos, int amount, boolean aimForZero); - void storeAura(BlockPos pos, int amount); + /** + * Convenience version of {@link #drainAura(BlockPos, int, boolean)} with + * aimForZero set to false, as this is the most likely behavior you will + * want. Notice that {@link #storeAura(BlockPos, int)} has aimForZero set to + * true. + */ + int drainAura(BlockPos pos, int amount); + + /** + * Stores the given amount of Aura at the given position. Returns the amount + * of Aura that was stored. + * + * @param pos The position + * @param amount The amount to store + * @param aimForZero If true, and storing the given amount would make the + * level go from negative to positive, an amount will be + * stored instead that will cause the spot's amount to be + * 0. + * @return The amount of Aura stored. Will only be different from the + * supplied amount if stopAtZero is true + */ + int storeAura(BlockPos pos, int amount, boolean aimForZero); + + /** + * Convenience version of {@link #storeAura(BlockPos, int, boolean)} with + * aimForZero set to true, as this is the most likely behavior you will + * want. Notice that {@link #drainAura(BlockPos, int)} has aimForZero set to + * false. + */ + int storeAura(BlockPos pos, int amount); MutableInt getDrainSpot(BlockPos pos); diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java index a21e8584..fcfc05ac 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java @@ -53,19 +53,44 @@ public class AuraChunk implements IAuraChunk { } @Override - public void drainAura(BlockPos pos, int amount) { + public int drainAura(BlockPos pos, int amount, boolean aimForZero) { if (amount <= 0) - return; - this.getDrainSpot(pos).subtract(amount); + return 0; + MutableInt spot = this.getDrainSpot(pos); + if (aimForZero) { + int curr = spot.intValue(); + if (curr > 0 && curr - amount < 0) + amount = curr; + } + spot.subtract(amount); this.markDirty(); + return amount; } @Override - public void storeAura(BlockPos pos, int amount) { + public int drainAura(BlockPos pos, int amount) { + return this.drainAura(pos, amount, true); + } + + @Override + public int storeAura(BlockPos pos, int amount, boolean aimForZero) { if (amount <= 0) - return; - this.getDrainSpot(pos).add(amount); + return 0; + MutableInt spot = this.getDrainSpot(pos); + if (aimForZero) { + int curr = spot.intValue(); + if (curr < 0 && curr + amount > 0) { + amount = -curr; + } + } + spot.add(amount); this.markDirty(); + return amount; + } + + @Override + public int storeAura(BlockPos pos, int amount) { + return this.storeAura(pos, amount, true); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 29a81e6d..319f6267 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -58,7 +58,8 @@ public class ClientEvents { IAuraChunk.getSpotsInArea(mc.world, mc.player.getPosition(), 15, ((blockPos, drainSpot) -> { spots.increment(); amount.add(drainSpot.intValue()); - left.add(prefix + drainSpot.intValue() + " @ " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ()); + if (mc.player.isSneaking()) + left.add(prefix + drainSpot.intValue() + " @ " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ()); })); left.add(prefix + "Total: " + amount.intValue() + " in " + spots.intValue() + " spots"); left.add(prefix + "Type: " + IAuraType.forWorld(mc.world).getName());