net.minecraftforge.items.CapabilityItemHandler Java Examples
The following examples show how to use
net.minecraftforge.items.CapabilityItemHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleMachineMetaTileEntity.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing side) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { IFluidHandler fluidHandler = (side == getOutputFacing() && !allowInputFromOutputSide) ? outputFluidInventory : fluidInventory; if(fluidHandler.getTankProperties().length > 0) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(fluidHandler); } return null; } else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { IItemHandler itemHandler = (side == getOutputFacing() && !allowInputFromOutputSide) ? outputItemInventory : itemInventory; if(itemHandler.getSlots() > 0) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemHandler); } return null; } return super.getCapability(capability, side); }
Example #2
Source File: TileEntityModuleMachine.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (facing == null) { return (T) invHandler; } else { return (T) itemHandlers.get(facing); } } return null; }
Example #3
Source File: TileEntityEngineeringTable.java From Cyberware with MIT License | 6 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (facing == EnumFacing.DOWN) { return (T) slotsBottom; } else { return (T) slotsTopSides; } } return super.getCapability(capability, facing); }
Example #4
Source File: TileEntitySimple.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Nullable @SuppressWarnings("unchecked") @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) getItemHandlerCapability(facing); } for (TileEntityModule module : modules.values()) { if (module.hasCapability(capability, facing)) return module.getCapability(capability, facing); } return super.getCapability(capability, facing); }
Example #5
Source File: TileGenericPipe.java From Logistics-Pipes-2 with MIT License | 6 votes |
public ArrayList<ItemStack> getItemsInInventory(EnumFacing face){ ArrayList<ItemStack> result = new ArrayList<ItemStack>(); if (!hasInventoryOnSide(face.getIndex())) { return result; } TileEntity te = world.getTileEntity(getPos().offset(face)); if (!te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, face.getOpposite())) { return result; } IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, face.getOpposite()); for(int i=0; i < itemHandler.getSlots(); i++) { ItemStack slotStack = itemHandler.getStackInSlot(i); if(!slotStack.isEmpty()) { result.add(slotStack); } } return result; }
Example #6
Source File: BlockMixin.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tile = worldIn.getTileEntity(pos); if (tile != null) { IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); if (itemHandler != null) { for (int i = 0; i < itemHandler.getSlots(); i++) { ItemStack stack = itemHandler.getStackInSlot(i); if (!stack.isEmpty()) { InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack); } } } } super.breakBlock(worldIn, pos, state); }
Example #7
Source File: CapabilityProviderItem.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") @Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandlerSupplier.ITEM_HANDLER_SUPPLIER_CAPABILITY) { return (T) this; } if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) getItemHandlerCapability(facing); } for (ItemModule module : modules.values()) { if (module.hasCapability(capability, facing)) return module.getCapability(capability, facing); } return null; }
Example #8
Source File: TileEntityScanner.java From Cyberware with MIT License | 6 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (facing == EnumFacing.DOWN) { if (slots.getStackInSlot(2) != null && slots.getStackInSlot(0) != null) { return (T) slotsBottom2; } else { return (T) slotsBottom; } } else { return (T) slotsTopSides; } } return super.getCapability(capability, facing); }
Example #9
Source File: TileGenericPipe.java From Logistics-Pipes-2 with MIT License | 6 votes |
public ConnectionTypes getConnection(IBlockAccess world, BlockPos pos, EnumFacing side) { TileEntity tile = world.getTileEntity(pos); if(getConnection(side) == ConnectionTypes.FORCENONE) { return ConnectionTypes.FORCENONE; } if(tile instanceof IPipe) { return ConnectionTypes.PIPE; } else if(tile!=null) { if(world.getTileEntity(pos).hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite())) return ConnectionTypes.BLOCK; if(world.getTileEntity(pos).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())) return ConnectionTypes.BLOCK; } return ConnectionTypes.NONE; }
Example #10
Source File: TileEntitySimple.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
@Nullable private IItemHandlerModifiable getItemHandlerCapability(@Nullable EnumFacing facing) { Capability<IItemHandler> capability = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; List<IItemHandlerModifiable> handlers = Lists.newLinkedList(); for (TileEntityModule module : modules.values()) { if (module.hasCapability(capability, facing)) handlers.add((IItemHandlerModifiable) module.getCapability(capability, facing)); } if (handlers.size() == 1) return handlers.get(0); else if (handlers.size() > 1) return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[handlers.size()])); else return null; }
Example #11
Source File: TileFastFurnace.java From YouTubeModdingTutorial with MIT License | 6 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (facing == null) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(combinedHandler); } else if (facing == EnumFacing.UP) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inputHandler); } else { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(outputHandler); } } if (capability == CapabilityEnergy.ENERGY) { return CapabilityEnergy.ENERGY.cast(energyStorage); } return super.getCapability(capability, facing); }
Example #12
Source File: CoverConveyor.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void update() { long timer = coverHolder.getTimer(); if (timer % 5 == 0 && isWorkingAllowed && itemsLeftToTransferLastSecond > 0) { TileEntity tileEntity = coverHolder.getWorld().getTileEntity(coverHolder.getPos().offset(attachedSide)); IItemHandler itemHandler = tileEntity == null ? null : tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, attachedSide.getOpposite()); IItemHandler myItemHandler = coverHolder.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, attachedSide); if (itemHandler != null && myItemHandler != null) { int totalTransferred = doTransferItems(itemHandler, myItemHandler, itemsLeftToTransferLastSecond); this.itemsLeftToTransferLastSecond -= totalTransferred; } } if (timer % 20 == 0) { this.itemsLeftToTransferLastSecond = transferRate; } }
Example #13
Source File: TileGenericPipe.java From Logistics-Pipes-2 with MIT License | 6 votes |
public ArrayList<Item> getItemTypesInInventory(EnumFacing face){ ArrayList<Item> result = new ArrayList<Item>(); if (!hasInventoryOnSide(face.getIndex())) { return result; } TileEntity te = world.getTileEntity(getPos().offset(face)); if (!te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, face.getOpposite())) { return result; } IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, face.getOpposite()); for(int i=0; i < itemHandler.getSlots(); i++) { ItemStack slotStack = itemHandler.getStackInSlot(i); Item item = slotStack.getItem(); if(!slotStack.isEmpty() && !result.contains(item)) { result.add(item); } } return result; }
Example #14
Source File: TileItemSource.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected IItemHandler computeItemHandler() { if (!world.isBlockLoaded(accessedBlockPos)) { //we handle unloaded blocks as empty item handlers //so when they are loaded, they are refreshed and handled correctly return EmptyHandler.INSTANCE; } //use cached tile entity as long as it's valid and has same position (just in case of frames etc) TileEntity tileEntity = cachedTileEntity.get(); if (tileEntity == null || tileEntity.isInvalid() || !tileEntity.getPos().equals(accessedBlockPos)) { tileEntity = world.getTileEntity(accessedBlockPos); if (tileEntity == null) { //if tile entity doesn't exist anymore, we are invalid now //return null which will be handled as INVALID return null; } //update cached tile entity this.cachedTileEntity = new WeakReference<>(tileEntity); } //fetch capability from tile entity //if it returns null, item handler info will be removed //block should emit block update once it obtains capability again, //so handler info will be recreated accordingly return tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, accessSide.getOpposite()); }
Example #15
Source File: TileEntityPhysicsInfuser.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return super.hasCapability(capability, facing); }
Example #16
Source File: TileFloader.java From YouTubeModdingTutorial with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inputHandler); } return super.getCapability(capability, facing); }
Example #17
Source File: TileFloader.java From YouTubeModdingTutorial with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; } return super.hasCapability(capability, facing); }
Example #18
Source File: ContainerFloader.java From YouTubeModdingTutorial with MIT License | 5 votes |
private void addOwnSlots() { IItemHandler itemHandler = this.te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); int x = 10; int y = 26; int slotIndex = 0; addSlotToContainer(new SlotItemHandler(itemHandler, slotIndex, x, y)); }
Example #19
Source File: TileEntityPhysicsInfuser.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return (T) handler; } return super.getCapability(capability, facing); }
Example #20
Source File: CoverItemFilter.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, T defaultValue) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { IItemHandler delegate = (IItemHandler) defaultValue; if (itemHandler == null || itemHandler.delegate != delegate) { this.itemHandler = new ItemHandlerFiltered(delegate); } return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemHandler); } return defaultValue; }
Example #21
Source File: ChoppingBlockTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @Nonnull public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return slotInventoryGetter.cast(); return super.getCapability(cap, side); }
Example #22
Source File: MetaTileEntityCokeOven.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing side) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { return null; } return super.getCapability(capability, side); }
Example #23
Source File: BlockOben.java From Sakura_mod with MIT License | 5 votes |
@Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntityOben te = (TileEntityOben) worldIn.getTileEntity(pos); IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP); if (inventory != null && inventory.getStackInSlot(0) != ItemStack.EMPTY) { Block.spawnAsEntity(worldIn, pos, inventory.getStackInSlot(0)); ((IItemHandlerModifiable) inventory).setStackInSlot(0, ItemStack.EMPTY); } super.breakBlock(worldIn, pos, state); }
Example #24
Source File: DryingRackTileEntity.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return itemsProvider.cast(); return super.getCapability(capability, facing); }
Example #25
Source File: ModificationTable.java From MiningGadgets with MIT License | 5 votes |
@Override public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (newState.getBlock() != this) { TileEntity tileEntity = worldIn.getTileEntity(pos); if (tileEntity != null) { LazyOptional<IItemHandler> cap = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); cap.ifPresent(handler -> { for(int i = 0; i < handler.getSlots(); ++i) { InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i)); } }); } super.onReplaced(state, worldIn, pos, newState, isMoving); } }
Example #26
Source File: HydroponicTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(this.fluidHandler); if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.itemHandler); if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.consumerEnergyHandler); return super.getCapability(capability, facing); }
Example #27
Source File: BlockBarrel.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void breakBlock(World world, BlockPos pos, IBlockState state) { TileEntity te = world.getTileEntity(pos); if (te != null && te instanceof TileBarrel) { TileBarrel barrel = (TileBarrel) te; if (barrel.getMode() != null && barrel.getMode().getName().equals("block")) { ItemStack stack = barrel.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(0); if (stack != null) Util.dropItemInWorld(te, null, stack, 0); } } super.breakBlock(world, pos, state); }
Example #28
Source File: ShredderTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.automationItemHandler); if (capability == CapabilityEnergy.ENERGY) return CapabilityEnergy.ENERGY.cast(this.consumerEnergyHandler); return super.getCapability(capability, facing); }
Example #29
Source File: ShredderTileEntity.java From EmergingTechnology with MIT License | 5 votes |
@Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true; if (capability == CapabilityEnergy.ENERGY) return true; return super.hasCapability(capability, facing); }
Example #30
Source File: BlockInventoryPipe.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public int getActiveNodeConnections(IBlockAccess world, BlockPos nodePos, IPipeTile<InventoryPipeType, EmptyNodeData> selfTileEntity) { int activeNodeConnections = 0; for (EnumFacing side : EnumFacing.VALUES) { BlockPos offsetPos = nodePos.offset(side); TileEntity tileEntity = world.getTileEntity(offsetPos); if(tileEntity != null && tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite())) { activeNodeConnections |= 1 << side.getIndex(); } } return activeNodeConnections; }