API update that makes it so that almost empty spots don't get overfilled by default

This commit is contained in:
Ellpeck 2018-11-18 20:34:57 +01:00
parent a54ea5b989
commit e501f96c0c
4 changed files with 78 additions and 10 deletions

View file

@ -37,7 +37,7 @@ public final class NaturesAuraAPI {
public static final String MOD_ID = "naturesaura"; public static final String MOD_ID = "naturesaura";
public static final String API_ID = MOD_ID + "api"; 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 * The list of all {@link AltarRecipe} instances which are the recipes used

View file

@ -119,9 +119,51 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable<NBTTag
*/ */
void getSpotsInArea(BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> consumer); void getSpotsInArea(BlockPos pos, int radius, BiConsumer<BlockPos, MutableInt> 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); MutableInt getDrainSpot(BlockPos pos);

View file

@ -53,19 +53,44 @@ public class AuraChunk implements IAuraChunk {
} }
@Override @Override
public void drainAura(BlockPos pos, int amount) { public int drainAura(BlockPos pos, int amount, boolean aimForZero) {
if (amount <= 0) if (amount <= 0)
return; return 0;
this.getDrainSpot(pos).subtract(amount); MutableInt spot = this.getDrainSpot(pos);
if (aimForZero) {
int curr = spot.intValue();
if (curr > 0 && curr - amount < 0)
amount = curr;
}
spot.subtract(amount);
this.markDirty(); this.markDirty();
return amount;
} }
@Override @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) if (amount <= 0)
return; return 0;
this.getDrainSpot(pos).add(amount); MutableInt spot = this.getDrainSpot(pos);
if (aimForZero) {
int curr = spot.intValue();
if (curr < 0 && curr + amount > 0) {
amount = -curr;
}
}
spot.add(amount);
this.markDirty(); this.markDirty();
return amount;
}
@Override
public int storeAura(BlockPos pos, int amount) {
return this.storeAura(pos, amount, true);
} }
@Override @Override

View file

@ -58,6 +58,7 @@ public class ClientEvents {
IAuraChunk.getSpotsInArea(mc.world, mc.player.getPosition(), 15, ((blockPos, drainSpot) -> { IAuraChunk.getSpotsInArea(mc.world, mc.player.getPosition(), 15, ((blockPos, drainSpot) -> {
spots.increment(); spots.increment();
amount.add(drainSpot.intValue()); amount.add(drainSpot.intValue());
if (mc.player.isSneaking())
left.add(prefix + drainSpot.intValue() + " @ " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ()); left.add(prefix + drainSpot.intValue() + " @ " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());
})); }));
left.add(prefix + "Total: " + amount.intValue() + " in " + spots.intValue() + " spots"); left.add(prefix + "Total: " + amount.intValue() + " in " + spots.intValue() + " spots");