package org.cyclops.cyclopscore.helper;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.IBlockAccess;
import org.cyclops.cyclopscore.datastructure.DimPos;

/**
 * Contains helper methods for various tile entity specific things.
 * @author rubensworks
 */
public final class TileHelpers {

    /**
     * Safely cast a tile entity.
     * @param dimPos The dimensional position of the block providing the tile entity.
     * @param targetClazz The class to cast to.
     * @param <T> The type of tile to cast at.
     * @return The tile entity or null.
     */
    public static <T> T getSafeTile(DimPos dimPos, Class<T> targetClazz) {
        return getSafeTile(dimPos.getWorld(), dimPos.getBlockPos(), targetClazz);
    }

    /**
     * Safely cast a tile entity.
     * @param world The world.
     * @param pos The position of the block providing the tile entity.
     * @param targetClazz The class to cast to.
     * @param <T> The type of tile to cast at.
     * @return The tile entity or null.
     */
    public static <T> T getSafeTile(IBlockAccess world, BlockPos pos, Class<T> targetClazz) {
        TileEntity tile = world.getTileEntity(pos);
        try {
            return targetClazz.cast(tile);
        } catch (ClassCastException e) {
            return null;
        }
    }

}

@@ -139,26 +139,156 @@
 aft.
-world.IBlockAccess
+util.EnumFacing;%0Aimport net.minecraft.world.IBlockAccess;%0Aimport net.minecraft.world.World;%0Aimport net.minecraftforge.common.capabilities.Capability
 ;%0Aim
@@ -1480,10 +1480,682 @@
 %0A    %7D%0A%0A
+    /**%0A     * Safely get a capability from a tile.%0A     * @param world The world.%0A     * @param pos The position of the block of the tile entity providing the capability.%0A     * @param side The side to get the capability from.%0A     * @param capability The capability.%0A     * @param %3CC%3E The capability instance.%0A     * @return The capability or null.%0A     */%0A    public static %3CC%3E C getCapability(World world, BlockPos pos, EnumFacing side, Capability%3CC%3E capability) %7B%0A        TileEntity tile = TileHelpers.getSafeTile(world, pos, TileEntity.class);%0A        if(tile != null) %7B%0A            return tile.getCapability(capability, side);%0A        %7D%0A        return null;%0A    %7D%0A%0A
 %7D%0A

Add convenience method for retrieving tile capabilities