Search in sources :

Example 11 with LongEnergyStack

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;
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) BigInteger(java.math.BigInteger) Nonnull(javax.annotation.Nonnull)

Example 12 with LongEnergyStack

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;
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) Nonnull(javax.annotation.Nonnull)

Example 13 with LongEnergyStack

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();
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) Test(org.junit.Test)

Example 14 with LongEnergyStack

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();
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) Test(org.junit.Test)

Example 15 with LongEnergyStack

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();
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) Test(org.junit.Test)

Aggregations

LongEnergyStack (com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack)12 IHyperHandlerEnergy (com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy)6 Nonnull (javax.annotation.Nonnull)6 Test (org.junit.Test)6 LongEnergyStack (com.cjm721.overloaded.storage.LongEnergyStack)4 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)2 BigInteger (java.math.BigInteger)1 ITickableTileEntity (net.minecraft.tileentity.ITickableTileEntity)1 ActionResult (net.minecraft.util.ActionResult)1 Direction (net.minecraft.util.Direction)1 EnumFacing (net.minecraft.util.EnumFacing)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1