use of net.minecraft.tileentity.ChestTileEntity in project ChaosAwakens by ChaosAwakens.
the class CATreasure method generateChest.
public void generateChest(IWorld world, BlockPos pos, Direction dir, boolean trapped) {
world.setBlock(pos, (trapped ? Blocks.TRAPPED_CHEST : Blocks.CHEST).defaultBlockState().setValue(ChestBlock.FACING, dir), 2);
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChestTileEntity) {
((ChestTileEntity) te).setLootTable(lootTable, ((ISeedReader) world).getSeed() * pos.getX() + pos.getY() ^ pos.getZ());
}
}
use of net.minecraft.tileentity.ChestTileEntity in project minecolonies by ldtteam.
the class InventoryUtils method getCountFromBuilding.
/**
* Count the number of items a building has.
*
* @param provider building to check in.
* @param stack the stack to check.
* @return Amount of occurrences of stacks that match the given stack.
*/
public static int getCountFromBuilding(@NotNull final IBuilding provider, @NotNull final ItemStorage stack) {
int totalCount = 0;
final World world = provider.getColony().getWorld();
for (final BlockPos pos : provider.getContainers()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
totalCount += ((TileEntityRack) entity).getCount(stack);
} else if (entity instanceof ChestTileEntity) {
totalCount += getItemCountInProvider(entity, itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack.getItemStack()));
}
}
}
return totalCount;
}
use of net.minecraft.tileentity.ChestTileEntity in project minecolonies by ldtteam.
the class InventoryUtils method getCountFromBuilding.
/**
* Count the number of items a building has.
*
* @param provider building to check in.
* @param predicate the predicate to match.
* @return Amount of occurrences of stacks that match the given stack.
*/
public static int getCountFromBuilding(@NotNull final IBuilding provider, @NotNull final Predicate<ItemStack> predicate) {
int totalCount = 0;
final World world = provider.getColony().getWorld();
for (final BlockPos pos : provider.getContainers()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
totalCount += ((TileEntityRack) entity).getItemCount(predicate);
} else if (entity instanceof ChestTileEntity) {
totalCount += getItemCountInProvider(entity, predicate);
}
}
}
return totalCount;
}
Aggregations