侧边栏壁纸
  • 累计撰写 793 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录
MC

建筑师 请求 物品

Dettan
2021-07-10 / 0 评论 / 0 点赞 / 149 阅读 / 285 字
温馨提示:
本文最后更新于 2022-07-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure
每次只请求一个,因为请求一个就返回false了.
public static <J extends AbstractJobStructure<?, J>, B extends AbstractBuildingStructureBuilder> boolean hasListOfResInInvOrRequest(@NotNull final AbstractEntityAIStructure<J, B> placer, final List<ItemStack> itemList, final boolean force)
{
    final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(placer.getWorker().getInventoryCitizen(),
      itemStack -> itemList.stream().anyMatch(targetStack -> targetStack.isItemEqual(itemStack)));
    if (force)
    {
        for (final ItemStack foundStack : new ArrayList<>(foundStacks))
        {
            final Optional<ItemStack> opt = itemList.stream().filter(targetStack -> targetStack.isItemEqual(foundStack)).findFirst();
            if (opt.isPresent())
            {
                final ItemStack stack = opt.get();
                itemList.remove(stack);
                if (stack.getCount() > foundStack.getCount())
                {
                    stack.setCount(stack.getCount() - foundStack.getCount());
                    itemList.add(stack);
                }
            }
        }
    }
    else
    {
        itemList.removeIf(itemStack -> ItemStackUtils.isEmpty(itemStack) || foundStacks.stream().anyMatch(target -> target.isItemEqual(itemStack)));
    }
    itemList.removeIf(itemstack -> itemstack.getItem() instanceof BlockItem && isBlockFree(((BlockItem) itemstack.getItem()).getBlock()));

    final Map<ItemStorage, Integer> list = new HashMap<>();
    for (final ItemStack stack : itemList)
    {
        ItemStorage tempStorage = new ItemStorage(stack.copy());
        if (list.containsKey(tempStorage))
        {
            final int oldSize = list.get(tempStorage);
            tempStorage.setAmount(tempStorage.getAmount() + oldSize);
        }
        list.put(tempStorage, tempStorage.getAmount());
    }

    for (final Map.Entry<ItemStorage, Integer> placedStack : list.entrySet())
    {
        if (ItemStackUtils.isEmpty(placedStack.getKey().getItemStack()))
        {
            return false;
        }

        if (placer.getOwnBuilding()
              .getOpenRequestsOfTypeFiltered(
                placer.getWorker().getCitizenData(),
                TypeConstants.DELIVERABLE,
                (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack.getKey().getItemStack()))
              .isEmpty())
        {
            final com.minecolonies.api.colony.requestsystem.requestable.Stack stackRequest = new Stack(placedStack.getKey().getItemStack(), placedStack.getValue(), 1);
            placer.getWorker().getCitizenData().createRequest(stackRequest);
            placer.registerBlockAsNeeded(placedStack.getKey().getItemStack());
            return false;
        }
        return false;
    }
    return true;
}
0

评论区