Search in sources :

Example 1 with IBlockCapabilityProvider

use of pl.asie.charset.api.lib.IBlockCapabilityProvider in project Charset by CharsetMC.

the class CapabilityHelper method get.

@SuppressWarnings("unchecked")
public static <T> T get(IBlockAccess world, BlockPos pos, Capability<T> capability, EnumFacing facing, boolean blocks, boolean tiles, boolean entities) {
    IBlockState state = world.getBlockState(pos);
    if (tiles && state.getBlock().hasTileEntity(state)) {
        TileEntity tile = world.getTileEntity(pos);
        T result = get(capability, tile, facing);
        if (result != null)
            return result;
    }
    if (blocks) {
        IBlockCapabilityProvider provider = blockProviders.get(state.getBlock(), capability);
        if (provider != null) {
            T result = (T) provider.create(world, pos, state, facing);
            if (result != null) {
                return result;
            }
        }
    }
    if (world instanceof World) {
        if (entities && !world.isSideSolid(pos, facing, false)) {
            List<Entity> entityList = ((World) world).getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos));
            for (Entity entity : entityList) {
                T result = get(capability, entity, facing);
                if (result != null)
                    return result;
            }
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IBlockCapabilityProvider(pl.asie.charset.api.lib.IBlockCapabilityProvider) World(net.minecraft.world.World)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 World (net.minecraft.world.World)1 IBlockCapabilityProvider (pl.asie.charset.api.lib.IBlockCapabilityProvider)1