Search in sources :

Example 1 with IHyperHandlerEnergy

use of com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy 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 IHyperHandlerEnergy

use of com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy in project Overloaded by CJ-MC-Mods.

the class ItemEnergyShield method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
    IHyperHandlerEnergy handler = stack.getCapability(HYPER_ENERGY_HANDLER, null);
    tooltip.add("Energy Stored: " + handler.status().getAmount());
    super.addInformation(stack, playerIn, tooltip, advanced);
}
Also used : IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IHyperHandlerEnergy

use of com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy in project Overloaded by CJ-MC-Mods.

the class TileEnergyExtractor method update.

/**
     * Like the old updateEntity(), except more generic.
     */
@Override
public void update() {
    BlockPos me = this.getPos();
    TileEntity frontTE = getWorld().getTileEntity(me.add(front.getDirectionVec()));
    if (frontTE == null || !frontTE.hasCapability(HYPER_ENERGY_HANDLER, front.getOpposite()))
        return;
    IHyperHandlerEnergy storage = frontTE.getCapability(HYPER_ENERGY_HANDLER, front.getOpposite());
    LongEnergyStack energy = storage.take(new LongEnergyStack(Long.MAX_VALUE), false);
    for (EnumFacing facing : EnumFacing.values()) {
        if (energy.getAmount() == 0L)
            return;
        if (facing == front)
            continue;
        TileEntity te = world.getTileEntity(me.add(facing.getDirectionVec()));
        if (te == null || !te.hasCapability(ENERGY, facing.getOpposite()))
            continue;
        IEnergyStorage receiver = te.getCapability(ENERGY, facing.getOpposite());
        if (!receiver.canReceive())
            continue;
        int acceptedAmount = receiver.receiveEnergy((int) Math.min(energy.getAmount(), Integer.MAX_VALUE), true);
        if (acceptedAmount != 0) {
            receiver.receiveEnergy(acceptedAmount, false);
            energy = storage.take(new LongEnergyStack(acceptedAmount), true);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LongEnergyStack(com.cjm721.overloaded.storage.LongEnergyStack) EnumFacing(net.minecraft.util.EnumFacing) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos) IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy)

Example 4 with IHyperHandlerEnergy

use of com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy in project Overloaded by CJ-MC-Mods.

the class ItemEnergyShield method onItemRightClick.

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    playerIn.setActiveHand(handIn);
    IHyperHandlerEnergy handler = itemstack.getCapability(HYPER_ENERGY_HANDLER, null);
    LongEnergyStack energy = handler.take(new LongEnergyStack(initialUseCost), true);
    if (energy.amount == initialUseCost) {
        System.out.println("Right click Success");
        return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
    } else {
        System.out.println("Right click FAIL");
        return new ActionResult<>(EnumActionResult.FAIL, itemstack);
    }
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.LongEnergyStack) ItemStack(net.minecraft.item.ItemStack) IHyperHandlerEnergy(com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy) Nonnull(javax.annotation.Nonnull)

Aggregations

IHyperHandlerEnergy (com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy)4 LongEnergyStack (com.cjm721.overloaded.storage.LongEnergyStack)3 Nonnull (javax.annotation.Nonnull)2 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1