use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.
the class BigIntEnergyStorage method take.
@Nonnull
@Override
public LongEnergyStack take(@Nonnull LongEnergyStack stack, boolean doAction) {
BigInteger takenAmount = energy.amount.min(BigInteger.valueOf(stack.amount));
LongEnergyStack result = new LongEnergyStack(takenAmount.longValueExact());
if (doAction) {
energy.amount = energy.amount.subtract(takenAmount);
dataUpdate.dataUpdated();
}
return result;
}
use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.
the class LongEnergyStorage method take.
@Override
@Nonnull
public LongEnergyStack take(@Nonnull LongEnergyStack stack, boolean doAction) {
long newStoredAmount = Math.max(energy.amount - stack.amount, 0);
LongEnergyStack result = new LongEnergyStack(Math.min(energy.amount, stack.amount));
if (doAction) {
energy.amount = newStoredAmount;
dataUpdate.dataUpdated();
}
return result;
}
use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.
the class LongEnergyStorageTest method take_doAction_whenFalse.
@Test
public void take_doAction_whenFalse() {
// Setup Base energy
storage.give(new LongEnergyStack(1000), true);
updateCalled = false;
LongEnergyStack simulatedTakenAmount = storage.take(new LongEnergyStack(1000), false);
assertThat(simulatedTakenAmount.getAmount()).isEqualTo(1000);
assertThat(storage.status().getAmount()).isEqualTo(1000);
assertThat(updateCalled).isFalse();
}
use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.
the class LongEnergyStorageTest method extractEnergy_simulate_whenTrue.
@Test
public void extractEnergy_simulate_whenTrue() {
// Setup Base energy
storage.give(new LongEnergyStack(1000), true);
updateCalled = false;
int simulatedExtract = storage.extractEnergy(1000, true);
assertThat(simulatedExtract).isEqualTo(1000);
assertThat(storage.status().getAmount()).isEqualTo(1000);
assertThat(updateCalled).isFalse();
}
use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.
the class LongEnergyStorageTest method give_doAction_whenFalse.
@Test
public void give_doAction_whenFalse() {
LongEnergyStack simulatedOverflow = storage.give(new LongEnergyStack(1000), false);
assertThat(simulatedOverflow.getAmount()).isEqualTo(0);
assertThat(storage.status().getAmount()).isEqualTo(0);
assertThat(updateCalled).isFalse();
}
Aggregations