Search in sources :

Example 1 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class TileEntityRack method updateItemStorage.

/**
 * Scans through the whole storage and updates it.
 */
public void updateItemStorage() {
    content.clear();
    for (int slot = 0; slot < inventory.getSlots(); slot++) {
        final ItemStack stack = inventory.getStackInSlot(slot);
        if (ItemStackUtils.isEmpty(stack)) {
            continue;
        }
        final ItemStorage storage = new ItemStorage(stack.copy());
        int amount = ItemStackUtils.getSize(stack);
        if (content.containsKey(storage)) {
            amount += content.remove(storage);
        }
        content.put(storage, amount);
    }
    updateBlockState();
    markDirty();
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 2 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class WindowBuildBuilding method updateResourceList.

public void updateResourceList() {
    final ScrollingList recourseList = findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class);
    recourseList.enable();
    recourseList.show();
    final List<ItemStorage> tempRes = new ArrayList<>(resources.values());
    // Creates a dataProvider for the unemployed recourseList.
    recourseList.setDataProvider(new ScrollingList.DataProvider() {

        /**
         * The number of rows of the list.
         * @return the number.
         */
        @Override
        public int getElementCount() {
            return tempRes.size();
        }

        /**
         * Inserts the elements into each row.
         * @param index the index of the row/list element.
         * @param rowPane the parent Pane for the row, containing the elements to update.
         */
        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final ItemStorage resource = tempRes.get(index);
            final Label resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Label.class);
            final Label quantityLabel = rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class);
            resourceLabel.setLabelText(resource.getItemStack().getDisplayName());
            quantityLabel.setLabelText(Integer.toString(resource.getAmount()));
            resourceLabel.setColor(WHITE, WHITE);
            quantityLabel.setColor(WHITE, WHITE);
            rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(new ItemStack(resource.getItem(), 1, resource.getDamageValue()));
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Label(com.minecolonies.blockout.controls.Label) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Pane(com.minecolonies.blockout.Pane) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 3 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method dumpOneMoreSlot.

/**
 * Dumps one inventory slot into the building chest.
 *
 * @return true if is has to dump more.
 */
private boolean dumpOneMoreSlot() {
    // Items already kept in the inventory
    final List<ItemStorage> alreadyKept = new ArrayList<>();
    @Nullable final AbstractBuildingWorker buildingWorker = getOwnBuilding();
    return buildingWorker != null && (walkToBuilding() || InventoryFunctions.matchFirstInHandlerWithAction(new InvWrapper(worker.getInventoryCitizen()), itemStack -> !ItemStackUtils.isEmpty(itemStack) && !buildingWorker.buildingRequiresCertainAmountOfItem(itemStack, alreadyKept), (handler, slot) -> InventoryUtils.transferItemStackIntoNextFreeSlotInItemHandlers(new InvWrapper(worker.getInventoryCitizen()), slot, new InvWrapper(buildingWorker.getTileEntity()))));
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) Blocks(net.minecraft.init.Blocks) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) TypeToken(com.google.common.reflect.TypeToken) AbstractJob(com.minecolonies.coremod.colony.jobs.AbstractJob) TextComponentBase(net.minecraft.util.text.TextComponentBase) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) AITarget(com.minecolonies.coremod.entity.ai.util.AITarget) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Block(net.minecraft.block.Block) RAWTYPES(com.minecolonies.api.util.constant.Suppression.RAWTYPES) Tool(com.minecolonies.api.colony.requestsystem.requestable.Tool) com.minecolonies.api.util(com.minecolonies.api.util) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) IWalkToProxy(com.minecolonies.api.entity.ai.pathfinding.IWalkToProxy) EntityCitizenWalkToProxy(com.minecolonies.coremod.entity.pathfinding.EntityCitizenWalkToProxy) TOOL_LEVEL_WOOD_OR_GOLD(com.minecolonies.api.util.constant.ToolLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EnumFacing(net.minecraft.util.EnumFacing) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) SATURATION_DECREASE_FACTOR(com.minecolonies.api.util.constant.CitizenConstants.SATURATION_DECREASE_FACTOR) AIState(com.minecolonies.coremod.entity.ai.util.AIState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) WorkerUtil(com.minecolonies.coremod.util.WorkerUtil) TileEntity(net.minecraft.tileentity.TileEntity) ToolType(com.minecolonies.api.util.constant.ToolType) MAX_PRIO(com.minecolonies.coremod.colony.buildings.AbstractBuilding.MAX_PRIO) ItemStorage(com.minecolonies.api.crafting.ItemStorage) IToolType(com.minecolonies.api.util.constant.IToolType) NotNull(org.jetbrains.annotations.NotNull) HIGH_SATURATION(com.minecolonies.api.util.constant.CitizenConstants.HIGH_SATURATION) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ArrayList(java.util.ArrayList) ItemStorage(com.minecolonies.api.crafting.ItemStorage) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class CompatabilityManager method discoverSaplings.

private void discoverSaplings() {
    for (final ItemStack saps : OreDictionary.getOres(SAPLINGS)) {
        if (saps.getHasSubtypes()) {
            for (final CreativeTabs tabs : CreativeTabs.CREATIVE_TAB_ARRAY) {
                final NonNullList<ItemStack> list = NonNullList.create();
                saps.getItem().getSubItems(tabs, list);
                for (final ItemStack stack : list) {
                    // Just put it in if not in there already, don't mind the leave yet.
                    if (!ItemStackUtils.isEmpty(stack) && !leavesToSaplingMap.containsValue(new ItemStorage(stack)) && !saplings.contains(new ItemStorage(stack))) {
                        saplings.add(new ItemStorage(stack));
                    }
                }
            }
        }
    }
    Log.getLogger().info("Finished discovering saplings");
}
Also used : CreativeTabs(net.minecraft.creativetab.CreativeTabs) ItemStack(net.minecraft.item.ItemStack) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 5 with ItemStorage

use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.

the class AbstractBuilding method buildingRequiresCertainAmountOfItem.

/**
 * Check if the worker requires a certain amount of that item and the alreadykept list contains it.
 * Always leave one stack behind if the worker requires a certain amount of it. Just to be sure.
 *
 * @param stack            the stack to check it with.
 * @param localAlreadyKept already kept items.
 * @return true if it should be leave it behind.
 */
public boolean buildingRequiresCertainAmountOfItem(final ItemStack stack, final List<ItemStorage> localAlreadyKept) {
    for (final Map.Entry<Predicate<ItemStack>, Integer> entry : getRequiredItemsAndAmount().entrySet()) {
        if (entry.getKey().test(stack)) {
            final ItemStorage kept = ItemStorage.getItemStackOfListMatchingPredicate(localAlreadyKept, entry.getKey());
            if (kept != null) {
                if (kept.getAmount() >= entry.getValue()) {
                    return false;
                }
                localAlreadyKept.remove(kept);
                kept.setAmount(kept.getAmount() + ItemStackUtils.getSize(stack));
                localAlreadyKept.add(kept);
                return true;
            }
            localAlreadyKept.add(new ItemStorage(stack));
            return true;
        }
    }
    return false;
}
Also used : ItemStorage(com.minecolonies.api.crafting.ItemStorage) Predicate(java.util.function.Predicate)

Aggregations

ItemStorage (com.minecolonies.api.crafting.ItemStorage)11 ItemStack (net.minecraft.item.ItemStack)7 ArrayList (java.util.ArrayList)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 List (java.util.List)2 Predicate (java.util.function.Predicate)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 CreativeTabs (net.minecraft.creativetab.CreativeTabs)2 NotNull (org.jetbrains.annotations.NotNull)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 TypeToken (com.google.common.reflect.TypeToken)1 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)1 Tool (com.minecolonies.api.colony.requestsystem.requestable.Tool)1