Search in sources :

Example 1 with ITransferable

use of com.wuest.prefab.Capabilities.ITransferable in project MC-Prefab by Brian-Wuest.

the class ItemBlockCapability method setTileEntityCapabilities.

/**
 * Transfers the capability data from this item to the tile entity.
 * @param world The world this is affecting.
 * @param player The controlling player.
 * @param pos The block pos of the placed block.
 * @param stack The item stack to set the tile entity capability for.
 * @param side The side for which to get the capability for.
 */
protected void setTileEntityCapabilities(World world, EntityPlayer player, BlockPos pos, ItemStack stack, EnumFacing side) {
    if (world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity != null) {
            for (Capability capability : this.allowedCapabilities) {
                // Get the interfaces for this capability.
                Object stackCapability = stack.getCapability(capability, side);
                Object tileEntityCapability = tileEntity.getCapability(capability, side);
                if (stackCapability != null && tileEntityCapability != null && stackCapability instanceof ITransferable && tileEntityCapability instanceof ITransferable) {
                    // transfer the capability data, it's up to the capability to transfer the data.
                    ((ITransferable) tileEntityCapability).Transfer((ITransferable) stackCapability);
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Capability(net.minecraftforge.common.capabilities.Capability) ITransferable(com.wuest.prefab.Capabilities.ITransferable)

Example 2 with ITransferable

use of com.wuest.prefab.Capabilities.ITransferable in project MC-Prefab by Brian-Wuest.

the class TileEntityBase method transferCapabilities.

/**
 * Transfers capabilities available for transferring to the supplied itemstack.
 * @param stack The item stack to copy capabilities for.
 * @return The updated item stack with the original ItemStack's capabilities.
 */
public ItemStack transferCapabilities(ItemStack stack) {
    // Transfer each transferable capability to the itemstack.
    for (Capability allowedCapability : this.getAllowedCapabilities()) {
        // Get the interfaces for this capability.
        Object stackCapability = stack.getCapability(allowedCapability, EnumFacing.NORTH);
        Object tileEntityCapability = this.getCapability(allowedCapability, EnumFacing.NORTH);
        if (stackCapability != null && tileEntityCapability != null && stackCapability instanceof ITransferable && tileEntityCapability instanceof ITransferable) {
            // transfer the capability data, it's up to the capability to transfer the data.
            ((ITransferable) stackCapability).Transfer((ITransferable) tileEntityCapability);
        }
    }
    return stack;
}
Also used : Capability(net.minecraftforge.common.capabilities.Capability) ITransferable(com.wuest.prefab.Capabilities.ITransferable)

Aggregations

ITransferable (com.wuest.prefab.Capabilities.ITransferable)2 Capability (net.minecraftforge.common.capabilities.Capability)2 TileEntity (net.minecraft.tileentity.TileEntity)1