mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-26 05:08:34 +01:00
API update that makes it so that almost empty spots don't get overfilled by default
This commit is contained in:
parent
a54ea5b989
commit
e501f96c0c
4 changed files with 78 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -119,9 +119,51 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable<NBTTag
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue