use of net.minecraft.tileentity.ChestTileEntity in project BluePower by Qmunity.
the class WorldGenVolcano method generateLootChest.
private void generateLootChest(IWorld world, BlockPos pos, Random rand, Direction dir) {
setBlock(world, pos, Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, dir.getOpposite()));
TileEntity te = world.getBlockEntity(pos);
if (te instanceof ChestTileEntity) {
if (rand.nextInt(5) == 0 && BPConfig.CONFIG.generateTungstenInVolcano.get()) {
((ChestTileEntity) te).setItem(13, new ItemStack(BPItems.tungsten_ingot, 5 + rand.nextInt(10)));
} else {
((ChestTileEntity) te).setLootTable(LootTables.SIMPLE_DUNGEON, rand.nextInt());
}
}
}
use of net.minecraft.tileentity.ChestTileEntity in project minecolonies by Minecolonies.
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 Minecolonies.
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;
}
use of net.minecraft.tileentity.ChestTileEntity in project minecolonies by Minecolonies.
the class BuildingWareHouse method handleBuildingOverChest.
/**
* Handles the chest placement.
*
* @param pos at pos.
* @param chest the entity.
* @param world the world.
* @param tileEntityData the rack te data.
*/
public static void handleBuildingOverChest(@NotNull final BlockPos pos, final ChestTileEntity chest, final World world, @Nullable final CompoundNBT tileEntityData) {
final List<ItemStack> inventory = new ArrayList<>();
final int size = chest.getContainerSize();
for (int slot = 0; slot < size; slot++) {
final ItemStack stack = chest.getItem(slot);
if (!ItemStackUtils.isEmpty(stack)) {
inventory.add(stack.copy());
}
chest.removeItemNoUpdate(slot);
}
world.setBlock(pos, ModBlocks.blockRack.defaultBlockState(), 0x03);
if (tileEntityData != null) {
handleTileEntityPlacement(tileEntityData, world, pos);
}
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
((AbstractTileEntityRack) entity).setInWarehouse(true);
for (final ItemStack stack : inventory) {
if (!ItemStackUtils.isEmpty(stack)) {
InventoryUtils.addItemStackToItemHandler(((AbstractTileEntityRack) entity).getInventory(), stack);
}
}
}
}
use of net.minecraft.tileentity.ChestTileEntity in project minecolonies by Minecolonies.
the class RackPlacementHandler method handle.
@Override
public ActionProcessingResult handle(@NotNull final World world, @NotNull final BlockPos pos, @NotNull final BlockState blockState, @Nullable final CompoundNBT tileEntityData, final boolean complete, final BlockPos centerPos, final PlacementSettings settings) {
if (world.getBlockState(pos).getBlock() == ModBlocks.blockRack) {
return ActionProcessingResult.SUCCESS;
}
TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof ChestTileEntity) {
BuildingWareHouse.handleBuildingOverChest(pos, (ChestTileEntity) entity, world, tileEntityData);
} else {
world.setBlock(pos, blockState, UPDATE_FLAG);
if (tileEntityData != null) {
handleTileEntityPlacement(tileEntityData, world, pos, settings);
}
entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
((TileEntityRack) entity).updateBlockState();
}
}
return ActionProcessingResult.SUCCESS;
}
Aggregations