add a simulate parameter to IAuraChunk draining/storing for convenience

This commit is contained in:
Ellpeck 2018-11-24 17:32:39 +01:00
parent f6420d2c8e
commit 69e07e25a5
2 changed files with 22 additions and 18 deletions

View file

@ -132,13 +132,13 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable<NBTTag
* @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);
int drainAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate);
/**
* 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.
* Convenience version of {@link #drainAura(BlockPos, int, boolean,
* boolean)} with aimForZero and simulate 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);
@ -155,13 +155,13 @@ public interface IAuraChunk extends ICapabilityProvider, INBTSerializable<NBTTag
* @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);
int storeAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate);
/**
* 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.
* Convenience version of {@link #storeAura(BlockPos, int, boolean,
* boolean)} with aimForZero set to true and simulate set to false, 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);

View file

@ -53,7 +53,7 @@ public class AuraChunk implements IAuraChunk {
}
@Override
public int drainAura(BlockPos pos, int amount, boolean aimForZero) {
public int drainAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate) {
if (amount <= 0)
return 0;
MutableInt spot = this.getDrainSpot(pos);
@ -62,18 +62,20 @@ public class AuraChunk implements IAuraChunk {
if (curr > 0 && curr - amount < 0)
amount = curr;
}
spot.subtract(amount);
this.markDirty();
if (!simulate) {
spot.subtract(amount);
this.markDirty();
}
return amount;
}
@Override
public int drainAura(BlockPos pos, int amount) {
return this.drainAura(pos, amount, false);
return this.drainAura(pos, amount, false, false);
}
@Override
public int storeAura(BlockPos pos, int amount, boolean aimForZero) {
public int storeAura(BlockPos pos, int amount, boolean aimForZero, boolean simulate) {
if (amount <= 0)
return 0;
MutableInt spot = this.getDrainSpot(pos);
@ -83,14 +85,16 @@ public class AuraChunk implements IAuraChunk {
amount = -curr;
}
}
spot.add(amount);
this.markDirty();
if (!simulate) {
spot.add(amount);
this.markDirty();
}
return amount;
}
@Override
public int storeAura(BlockPos pos, int amount) {
return this.storeAura(pos, amount, true);
return this.storeAura(pos, amount, true, false);
}
@Override