use of com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack in project Overloaded by CJ-MC-Mods.
the class ItemEnergyShield method use.
@Nonnull
@Override
public ActionResult<ItemStack> use(World worldIn, PlayerEntity playerIn, @Nonnull Hand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
playerIn.startUsingItem(handIn);
LazyOptional<IHyperHandlerEnergy> opHandler = itemstack.getCapability(HYPER_ENERGY_HANDLER);
if (!opHandler.isPresent()) {
Overloaded.logger.warn("EnergyShield has no HyperEnergy Capability? NBT: " + itemstack.getTag());
return new ActionResult<>(ActionResultType.FAIL, itemstack);
}
IHyperHandlerEnergy handler = opHandler.orElseThrow(() -> new RuntimeException("Impossible Condition"));
LongEnergyStack energy = handler.take(new LongEnergyStack(initialUseCost), true);
if (energy.amount == initialUseCost) {
System.out.println("Right click Success");
return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
} else {
System.out.println("Right click FAIL");
return new ActionResult<>(ActionResultType.FAIL, itemstack);
}
}
Aggregations