Search in sources :

Example 16 with LongEnergyStack

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);
    }
}
Also used : ActionResult(net.minecraft.util.ActionResult) LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) ItemStack(net.minecraft.item.ItemStack) IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy) Nonnull(javax.annotation.Nonnull)

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