Search in sources :

Example 1 with LongEnergyStack

use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.

the class ItemEnergyShield method onItemUse.

@Override
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        System.out.println("On Item Use");
        IHyperHandlerEnergy handler = player.getHeldItem(hand).getCapability(HYPER_ENERGY_HANDLER, null);
        LongEnergyStack energy = handler.take(new LongEnergyStack(constantUseCost), true);
        if (energy.amount == constantUseCost) {
            System.out.println("On Item Use Success");
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.PASS;
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.LongEnergyStack) IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy) Nonnull(javax.annotation.Nonnull)

Example 2 with LongEnergyStack

use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.

the class ItemEnergyShield method useOn.

@Override
@Nonnull
public ActionResultType useOn(ItemUseContext context) {
    if (!context.getLevel().isClientSide) {
        System.out.println("On Item Use");
        LazyOptional<IHyperHandlerEnergy> opHandler = context.getItemInHand().getCapability(HYPER_ENERGY_HANDLER);
        if (!opHandler.isPresent()) {
            Overloaded.logger.warn("EnergyShield has no HyperEnergy Capability? NBT: " + context.getItemInHand().getTag());
            return ActionResultType.FAIL;
        }
        IHyperHandlerEnergy handler = opHandler.orElseThrow(() -> new RuntimeException("Impossible Condition"));
        LongEnergyStack energy = handler.take(new LongEnergyStack(constantUseCost), true);
        if (energy.amount == constantUseCost) {
            System.out.println("On Item Use Success");
            return ActionResultType.SUCCESS;
        }
        return ActionResultType.FAIL;
    }
    return ActionResultType.PASS;
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy) Nonnull(javax.annotation.Nonnull)

Example 3 with LongEnergyStack

use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.

the class BlockAlmostInfiniteCapacitor method sendPlayerStatus.

@Override
protected void sendPlayerStatus(World world, BlockPos pos, PlayerEntity player) {
    LongEnergyStack stack = ((TileAlmostInfiniteCapacitor) world.getBlockEntity(pos)).getStorage().status();
    double percent = 100 * (double) stack.getAmount() / (double) Long.MAX_VALUE;
    player.displayClientMessage(new StringTextComponent(String.format("Energy Amount: %,d  %,.4f%%", stack.getAmount(), percent)), false);
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 4 with LongEnergyStack

use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.

the class LongEnergyStorageTest method take_moreThenAvailable.

@Test
public void take_moreThenAvailable() {
    // Setup Base energy
    storage.give(new LongEnergyStack(100), true);
    updateCalled = false;
    LongEnergyStack taken = storage.take(new LongEnergyStack(1000), true);
    assertThat(taken.getAmount()).isEqualTo(100);
    assertThat(storage.status().getAmount()).isEqualTo(0);
    assertThat(updateCalled).isTrue();
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) Test(org.junit.Test)

Example 5 with LongEnergyStack

use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.

the class LongEnergyStorageTest method give_moreThenAvailable.

@Test
public void give_moreThenAvailable() {
    // Setup Base Energy
    storage.give(new LongEnergyStack(Long.MAX_VALUE), true);
    updateCalled = false;
    LongEnergyStack overflow = storage.give(new LongEnergyStack(1000), true);
    assertThat(overflow.getAmount()).isEqualTo(1000);
    assertThat(storage.status().getAmount()).isEqualTo(Long.MAX_VALUE);
    assertThat(updateCalled).isTrue();
}
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