Search in sources :

Example 1 with IEnergyStorage

use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
    IEnergyStorage handler = stack.getCapability(ENERGY, null);
    tooltip.add(String.format("Energy Stored: %d", handler.getEnergyStored()));
    super.addInformation(stack, playerIn, tooltip, advanced);
}
Also used : IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IEnergyStorage

use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method rightClickWithItem.

public void rightClickWithItem(@Nonnull World worldIn, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos, @Nonnull EnumFacing sideHit, float hitX, float hitY, float hitZ) {
    ItemStack multiTool = player.getHeldItemMainhand();
    if (multiTool.getItem() != this) {
        return;
    }
    NBTTagCompound tagCompound = multiTool.getTagCompound();
    if (tagCompound == null || !tagCompound.hasKey("Item")) {
        player.sendStatusMessage(new TextComponentString("No block type selected to place."), true);
        return;
    }
    NBTTagCompound itemTag = tagCompound.getCompoundTag("Item");
    ItemStack blockStack = new ItemStack(itemTag);
    if (!(blockStack.getItem() instanceof ItemBlock)) {
        player.sendStatusMessage(new TextComponentString("No valid block type selected to place."), true);
        return;
    }
    IEnergyStorage energy = multiTool.getCapability(ENERGY, null);
    Vec3i sideVector = sideHit.getDirectionVec();
    BlockPos.MutableBlockPos newPosition = new BlockPos.MutableBlockPos(pos.add(sideVector));
    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
        return;
    if (player.isSneaking()) {
        BlockPos playerPos = player.getPosition();
        switch(sideHit) {
            case UP:
                while (newPosition.getY() < playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case DOWN:
                while (newPosition.getY() > playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case NORTH:
                while (newPosition.getZ() > playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case SOUTH:
                while (newPosition.getZ() < playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case EAST:
                while (newPosition.getX() < playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
            case WEST:
                while (newPosition.getX() > playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
                        break;
                }
                break;
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with IEnergyStorage

use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method onBlockDestroyed.

//    @Override
//    public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
//        return true;
//    }
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
    IEnergyStorage storage = stack.getCapability(ENERGY, null);
    if (storage != null) {
        int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack);
        int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack);
        float breakCost = getBreakCost(worldIn.getBlockState(pos).getBlockHardness(worldIn, pos), efficiency, unbreaking, entityLiving == null ? 10 : getDistance(entityLiving, pos));
        storage.extractEnergy((int) Math.min(Integer.MAX_VALUE, breakCost), false);
    }
    return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);
}
Also used : IEnergyStorage(net.minecraftforge.energy.IEnergyStorage)

Example 4 with IEnergyStorage

use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method leftClickOnBlockServer.

public void leftClickOnBlockServer(@Nonnull World world, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos) {
    ItemStack itemStack = player.getHeldItem(EnumHand.MAIN_HAND);
    if (itemStack.getItem() != this || world.isAirBlock(pos)) {
        return;
    }
    player.setActiveHand(EnumHand.MAIN_HAND);
    if (player.isSneaking()) {
        NBTTagCompound tag = itemStack.getTagCompound();
        if (tag == null) {
            tag = new NBTTagCompound();
        }
        IBlockState state = world.getBlockState(pos);
        Item item = Item.getItemFromBlock(state.getBlock());
        ItemStack stackToPlace = new ItemStack(item, 1, state.getBlock().damageDropped(state));
        NBTTagCompound blockTag = new NBTTagCompound();
        stackToPlace.writeToNBT(blockTag);
        tag.setTag("Item", blockTag);
        itemStack.setTagCompound(tag);
        ITextComponent component = stackToPlace.getTextComponent();
        player.sendStatusMessage(new TextComponentString("Bound tool to ").appendSibling(component), true);
    } else {
        IEnergyStorage energy = itemStack.getCapability(ENERGY, null);
        int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, itemStack);
        int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
        switch(breakAndUseEnergy(world, pos, energy, player, efficiency, unbreaking)) {
            case FAIL_REMOVE:
                player.sendStatusMessage(new TextComponentString("Unable to break block, reason unknown"), true);
                break;
            case FAIL_ENERGY:
                player.sendStatusMessage(new TextComponentString("Unable to break block, not enough energy"), true);
                break;
            case FAIL_UNBREAKABLE:
                player.sendStatusMessage(new TextComponentString("Block is unbreakable"), true);
                break;
            case SUCCESS:
                break;
        }
    }
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) ModItem(com.cjm721.overloaded.item.ModItem) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ITextComponent(net.minecraft.util.text.ITextComponent) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) ItemStack(net.minecraft.item.ItemStack) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with IEnergyStorage

use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.

the class TileCreativeGeneratorFE method update.

/**
     * Like the old updateEntity(), except more generic.
     */
@Override
public void update() {
    if (getWorld().isRemote)
        return;
    BlockPos pos = this.getPos();
    for (EnumFacing facing : EnumFacing.values()) {
        TileEntity te = world.getTileEntity(pos.add(facing.getDirectionVec()));
        if (te == null)
            continue;
        IEnergyStorage storage = te.getCapability(ENERGY, facing.getOpposite());
        if (storage == null)
            continue;
        storage.receiveEnergy(Integer.MAX_VALUE, false);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)6 BlockPos (net.minecraft.util.math.BlockPos)3 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 ModItem (com.cjm721.overloaded.item.ModItem)1 LongEnergyStack (com.cjm721.overloaded.storage.LongEnergyStack)1 IHyperHandlerEnergy (com.cjm721.overloaded.storage.energy.IHyperHandlerEnergy)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 Vec3i (net.minecraft.util.math.Vec3i)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1