Search in sources :

Example 16 with ChestTileEntity

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

Example 17 with ChestTileEntity

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;
}
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 18 with ChestTileEntity

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

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