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;
}
Aggregations