Search in sources :

Example 6 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project ImmersiveEngineering by BluSunrize.

the class Utils method canInsertStackIntoInventory.

public static boolean canInsertStackIntoInventory(TileEntity inventory, ItemStack stack, EnumFacing side) {
    if (stack != null && inventory != null && inventory.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
        IItemHandler handler = inventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
        ItemStack temp = ItemHandlerHelper.insertItem(handler, stack.copy(), true);
        if (temp == null || temp.stackSize < stack.stackSize)
            return true;
    }
    return false;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack)

Example 7 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project VanillaTeleporter by dyeo.

the class BlockTeleporter method breakBlockRecall.

public void breakBlockRecall(World world, World nextWorld, BlockPos pos, BlockPos nextPos, IBlockState state, EntityPlayerMP player) {
    TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter) world.getTileEntity(pos);
    if (tileEntityTeleporter != null) {
        tileEntityTeleporter.removeFromNetwork();
        if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
            IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            ItemStack stack = handler.getStackInSlot(0);
            if (!stack.isEmpty()) {
                InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY() + 1, nextPos.getZ(), stack);
            }
        }
    }
    InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY() + 1, nextPos.getZ(), new ItemStack(ModBlocks.TELEPORTER, 1, getMetaFromState(state)));
    world.setBlockToAir(pos);
    while (world.getTileEntity(pos) != null) {
        world.removeTileEntity(pos);
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 8 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project VanillaTeleporter by dyeo.

the class BlockTeleporter method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter) world.getTileEntity(pos);
    if (tileEntityTeleporter != null) {
        tileEntityTeleporter.removeFromNetwork();
        if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
            IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            ItemStack stack = handler.getStackInSlot(0);
            if (!stack.isEmpty()) {
                stack = stack.copy();
                InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), stack);
            }
        }
    }
    // super _must_ be called last because it removes the tile entity
    super.breakBlock(world, pos, state);
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 9 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project BetterWithAddons by DaedalusGame.

the class BlockWeight method measureBlock.

public int measureBlock(World world, BlockPos pos, IBlockState state) {
    BlockPos checkpos = pos.up();
    IBlockState checkstate = world.getBlockState(checkpos);
    TileEntity te = world.getTileEntity(checkpos);
    boolean isFull = true;
    boolean isEmpty = true;
    int delay = 20;
    if (te != null) {
        boolean foundAnyMeasurable = false;
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
                IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
                if (!InventoryUtil.isEmpty(inventory))
                    isEmpty = false;
                if (!InventoryUtil.isFull(inventory))
                    isFull = false;
                foundAnyMeasurable = true;
            }
            if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) {
                IFluidHandler tank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
                FluidStack fluid = tank.drain(Integer.MAX_VALUE, false);
                if (fluid != null && tank.fill(fluid, false) > 0)
                    isFull = false;
                if (fluid != null && fluid.amount != 0)
                    isEmpty = false;
                foundAnyMeasurable = true;
            }
        }
        if (foundAnyMeasurable)
            delay = 1;
        else
            isFull = false;
    } else if (SPECIAL_BEHAVIOR.containsKey(checkstate.getBlock())) {
        ISpecialMeasuringBehavior behavior = SPECIAL_BEHAVIOR.get(checkstate.getBlock());
        isEmpty = behavior.isEmpty(world, checkpos, checkstate);
        isFull = behavior.isFull(world, checkpos, checkstate);
        delay = behavior.getDelay(world, checkpos, checkstate);
    } else {
        isFull = false;
    }
    boolean active = decideActivity(isEmpty, isFull);
    if (active != state.getValue(ACTIVE)) {
        world.setBlockState(pos, state.withProperty(ACTIVE, active));
        float f = active ? 0.6F : 0.5F;
        world.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1.0F, f);
    }
    return delay;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IItemHandler(net.minecraftforge.items.IItemHandler) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) ISpecialMeasuringBehavior(betterwithaddons.util.ISpecialMeasuringBehavior)

Example 10 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project BetterWithAddons by DaedalusGame.

the class TileEntityAncestrySand method fillBottles.

public void fillBottles() {
    IBlockState hopper = world.getBlockState(pos.down());
    if (spirits <= InteractionEriottoMod.SPIRIT_PER_BOTTLE)
        return;
    if (hopper.getBlock() != BWMBlocks.SINGLE_MACHINES || hopper.getValue(BlockMechMachines.TYPE) != BlockMechMachines.EnumType.HOPPER)
        return;
    boolean isOn = false;
    IBlockState state = world.getBlockState(pos);
    isOn = calculateInput() > 0;
    if (isOn) {
        TileEntity te = world.getTileEntity(pos.down());
        if (te instanceof TileEntityFilteredHopper) {
            TileEntityFilteredHopper tileHopper = (TileEntityFilteredHopper) te;
            IItemHandler handler = tileHopper.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
            ItemStack stack = new ItemStack(ModItems.ancestryBottle);
            ItemStack consumed = new ItemStack(Items.GLASS_BOTTLE);
            if (tileHopper.getFilterStack().getItem() == Item.getItemFromBlock(Blocks.SOUL_SAND) && InvUtils.canInsert(handler, stack, 1) && InvUtils.getFirstOccupiedStackOfItem(handler, consumed) >= 0) {
                InvUtils.consumeItemsInInventory(handler, consumed, 1, false);
                InvUtils.insert(handler, stack, false);
                consumeSpirits(InteractionEriottoMod.SPIRIT_PER_BOTTLE);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) TileEntityFilteredHopper(betterwithmods.common.blocks.mechanical.tile.TileEntityFilteredHopper)

Aggregations

IItemHandler (net.minecraftforge.items.IItemHandler)22 ItemStack (net.minecraft.item.ItemStack)17 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)4 IBlockState (net.minecraft.block.state.IBlockState)3 MultiSlotTileEntity (com.almuradev.almura.shared.tileentity.MultiSlotTileEntity)2 ISoulbound (convenientadditions.api.item.ISoulbound)2 Nullable (javax.annotation.Nullable)2 ItemDoll (mdc.voodoocraft.items.ItemDoll)2 TileDollPedestal (mdc.voodoocraft.tile.TileDollPedestal)2 TileEntityTeleporter (net.dyeo.teleporter.tileentity.TileEntityTeleporter)2 Block (net.minecraft.block.Block)2 EntityItem (net.minecraft.entity.item.EntityItem)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ISpecialMeasuringBehavior (betterwithaddons.util.ISpecialMeasuringBehavior)1 TileEntityFilteredHopper (betterwithmods.common.blocks.mechanical.tile.TileEntityFilteredHopper)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 IEInventoryHandler (blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler)1 IIEInventory (blusunrize.immersiveengineering.common.util.inventory.IIEInventory)1 DualItemHandlerContainer (com.almuradev.almura.shared.inventory.DualItemHandlerContainer)1