List of usage examples for net.minecraftforge.common.capabilities ICapabilityProvider getCapability
@Nonnull <T> LazyOptional<T> getCapability(@Nonnull final Capability<T> cap, final @Nullable Direction side);
From source file:buildcraft.core.statements.TriggerPower.java
License:Minecraft Mod Public
protected boolean isActive(ICapabilityProvider tile, EnumPipePart side) { return isTriggeredMjConnector(tile.getCapability(MjAPI.CAP_READABLE, side.face)); }
From source file:buildcraft.lib.inventory.InventoryIterator.java
License:Minecraft Mod Public
public static Iterable<IInvSlot> getIterable(ICapabilityProvider provider, EnumFacing side) { IItemHandler itemHandler = provider.getCapability(CapUtil.CAP_ITEMS, side); if (itemHandler != null) { return new InventoryIteratorHandler(itemHandler); } else if (provider instanceof IInventory) { return getIterable((IInventory) provider, side); } else {/*from w w w . ja v a2 s . co m*/ return ImmutableList.of(); } }
From source file:de.sanandrew.mods.sanlib.lib.util.InventoryUtils.java
License:Creative Commons License
@Nonnull public static ItemStack addStackToCapability(@Nonnull ItemStack is, ICapabilityProvider provider, EnumFacing facing, boolean simulate, int maxStackSize, int begin, int end) { if (is != ItemStack.EMPTY && provider.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) { IItemHandler handler = provider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing); assert handler != null; maxStackSize = Math.min(maxStackSize, is.getCount()); end = Math.min(end, handler.getSlots()); for (int i = begin; i < end; i++) { ItemStack maxStack = is.copy(); maxStack.setCount(maxStackSize); maxStack = handler.insertItem(i, maxStack, simulate); if (maxStack == ItemStack.EMPTY) { is.setCount(is.getCount() - maxStackSize); }/* w w w . ja va 2 s. c o m*/ if (is.getCount() <= 0) { return ItemStack.EMPTY; } } } return is; }
From source file:superscary.supercore.tools.Utilities.java
License:Apache License
/** * Get capability handler for an {@link ICapabilityProvider} * * @param provider the provider//from w w w. j ava 2 s . c om * @param capability the capability * @param facing facing direction * @param <T> handler type * @return the handler */ @Nullable public static <T> T getCapability(@Nullable ICapabilityProvider provider, Capability<T> capability, @Nullable EnumFacing facing) { return provider != null && provider.hasCapability(capability, facing) ? provider.getCapability(capability, facing) : null; }