Search in sources :

Example 6 with AbstractTileEntityRack

use of com.minecolonies.api.tileentities.AbstractTileEntityRack in project minecolonies by ldtteam.

the class TileEntityWareHouse method searchMostEmptyRack.

/**
 * Search for the chest with the least items in it.
 *
 * @return the tileEntity of this chest.
 */
@Nullable
private TileEntity searchMostEmptyRack() {
    int freeSlots = 0;
    TileEntity emptiestChest = null;
    for (@NotNull final BlockPos pos : getBuilding().getContainers()) {
        final TileEntity entity = getLevel().getBlockEntity(pos);
        if (entity instanceof TileEntityRack) {
            if (((AbstractTileEntityRack) entity).isEmpty()) {
                return entity;
            }
            final int tempFreeSlots = ((AbstractTileEntityRack) entity).getFreeSlots();
            if (tempFreeSlots > freeSlots) {
                freeSlots = tempFreeSlots;
                emptiestChest = entity;
            }
        }
    }
    return emptiestChest;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AbstractTileEntityRack (com.minecolonies.api.tileentities.AbstractTileEntityRack)6 TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)6 TileEntity (net.minecraft.tileentity.TileEntity)6 NotNull (org.jetbrains.annotations.NotNull)4 AbstractBlockMinecoloniesRack (com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack)2 ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 Nullable (org.jetbrains.annotations.Nullable)2