Search in sources :

Example 1 with ChestTileEntity

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());
        }
    }
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ChestTileEntity

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;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) World(net.minecraft.world.World)

Example 3 with ChestTileEntity

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;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) World(net.minecraft.world.World)

Example 4 with ChestTileEntity

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);
            }
        }
    }
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ChestTileEntity

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;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity)

Aggregations

ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)18 TileEntity (net.minecraft.tileentity.TileEntity)13 BlockPos (net.minecraft.util.math.BlockPos)8 TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)7 World (net.minecraft.world.World)7 ItemStack (net.minecraft.item.ItemStack)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 BlockState (net.minecraft.block.BlockState)2 ChestBlock (net.minecraft.block.ChestBlock)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Set (java.util.Set)1 Block (net.minecraft.block.Block)1 Blocks (net.minecraft.block.Blocks)1 HugeMushroomBlock (net.minecraft.block.HugeMushroomBlock)1 VineBlock (net.minecraft.block.VineBlock)1