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;
}
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;
}
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);
}
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();
}
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();
}
Aggregations