Search in sources :

Example 21 with TileEntityRack

use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.

the class InventoryUtils method hasBuildingEnoughElseCount.

/**
 * Check if a building has more than a count in stack. Return the count it has if it has less.
 *
 * @param provider building to check in.
 * @param stack    the stack to check.
 * @return Amount of occurrences of stacks that match the given predicate.
 */
public static int hasBuildingEnoughElseCount(@NotNull final IBuilding provider, @NotNull final ItemStorage stack, final int count) {
    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(), !stack.ignoreDamageValue(), !stack.ignoreNBT()));
            }
            if (totalCount > count) {
                return Integer.MAX_VALUE;
            }
        }
    }
    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 22 with TileEntityRack

use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.

the class BlockMinecoloniesRack method onRemove.

@Override
public void onRemove(BlockState state, @NotNull World worldIn, @NotNull BlockPos pos, BlockState newState, boolean isMoving) {
    if (state.getBlock() != newState.getBlock()) {
        TileEntity tileEntity = worldIn.getBlockEntity(pos);
        if (tileEntity instanceof TileEntityRack) {
            TileEntityRack tileEntityRack = (TileEntityRack) tileEntity;
            InventoryUtils.dropItemHandler(tileEntityRack.getInventory(), worldIn, tileEntityRack.getBlockPos().getX(), tileEntityRack.getBlockPos().getY(), tileEntityRack.getBlockPos().getZ());
            worldIn.updateNeighbourForOutputSignal(pos, this);
        }
        super.onRemove(state, worldIn, pos, newState, isMoving);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack)

Example 23 with TileEntityRack

use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.

the class BlockMinecoloniesRack method spawnAfterBreak.

@Override
public void spawnAfterBreak(final BlockState state, final ServerWorld worldIn, final BlockPos pos, final ItemStack stack) {
    final TileEntity tileentity = worldIn.getBlockEntity(pos);
    if (tileentity instanceof TileEntityRack) {
        final IItemHandler handler = ((AbstractTileEntityRack) tileentity).getInventory();
        InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
    }
    super.spawnAfterBreak(state, worldIn, pos, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) IItemHandler(net.minecraftforge.items.IItemHandler) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack)

Example 24 with TileEntityRack

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

the class WindowHutAllInventory method locate.

private void locate(final Button button) {
    final int row = stackList.getListElementIndexByPane(button);
    final ItemStorage storage = allItems.get(row);
    final Set<BlockPos> containerList = new HashSet<>(building.getContainerList());
    containerList.add(building.getID());
    HighlightManager.clearCategory("inventoryHighlight");
    Minecraft.getInstance().player.sendMessage(new TranslationTextComponent("com.minecolonies.coremod.locating"), Minecraft.getInstance().player.getUUID());
    close();
    for (BlockPos blockPos : containerList) {
        final TileEntity rack = Minecraft.getInstance().level.getBlockEntity(blockPos);
        if (rack instanceof TileEntityRack) {
            int count = ((TileEntityRack) rack).getCount(storage.getItemStack(), storage.ignoreDamageValue(), false);
            if (count > 0) {
                // Varies the color between yellow(low count) to green(64+)
                final int color = 0x00FF00 + 0xFF0000 * Math.max(0, 1 - count / 64);
                HighlightManager.addRenderBox("inventoryHighlight", new HighlightManager.TimedBoxRenderData().setPos(blockPos).setRemovalTimePoint(Minecraft.getInstance().level.getGameTime() + 60 * 20).addText("" + count).setColor(color));
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) HighlightManager(com.minecolonies.coremod.event.HighlightManager) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 25 with TileEntityRack

use of com.minecolonies.api.tileentities.TileEntityRack 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

TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)29 TileEntity (net.minecraft.tileentity.TileEntity)29 BlockPos (net.minecraft.util.math.BlockPos)19 World (net.minecraft.world.World)14 AbstractTileEntityRack (com.minecolonies.api.tileentities.AbstractTileEntityRack)12 ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)12 NotNull (org.jetbrains.annotations.NotNull)6 ItemStorage (com.minecolonies.api.crafting.ItemStorage)5 HighlightManager (com.minecolonies.coremod.event.HighlightManager)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)3 Pane (com.ldtteam.blockout.Pane)2 com.ldtteam.blockout.controls (com.ldtteam.blockout.controls)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 Window (com.ldtteam.blockout.views.Window)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 AbstractBlockMinecoloniesRack (com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack)2 IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)2 TileEntityColonyBuilding (com.minecolonies.api.tileentities.TileEntityColonyBuilding)2