Search in sources :

Example 1 with Stack

use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.

the class PlacementHandlers method checkForListInInvAndRequest.

/**
 * Check the placers inventory for the items in the itemList and remove it of the list if found.
 *
 * @param placer   the placer.
 * @param itemList the list to check.
 * @return true if need to request.
 */
public static boolean checkForListInInvAndRequest(@NotNull final AbstractEntityAIStructure<?> placer, final List<ItemStack> itemList) {
    final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(new InvWrapper(placer.getWorker().getInventoryCitizen()), itemStack -> itemList.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, targetStack, true, true)));
    itemList.removeIf(itemStack -> ItemStackUtils.isEmpty(itemStack) || foundStacks.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, targetStack, true, true)));
    for (final ItemStack placedStack : itemList) {
        if (ItemStackUtils.isEmpty(placedStack)) {
            return true;
        }
        if (placer.getOwnBuilding().getOpenRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack)).isEmpty()) {
            final Stack stackRequest = new Stack(placer.getTotalAmount(placedStack));
            placer.getWorker().getCitizenData().createRequest(stackRequest);
            return true;
        }
    }
    return false;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Blocks(net.minecraft.init.Blocks) UPDATE_FLAG(com.minecolonies.api.util.constant.Constants.UPDATE_FLAG) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ItemDoor(net.minecraft.item.ItemDoor) BlockMinecoloniesRack(com.minecolonies.coremod.blocks.BlockMinecoloniesRack) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TypeToken(com.google.common.reflect.TypeToken) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ChiselAndBitsCheck(com.minecolonies.api.compatibility.candb.ChiselAndBitsCheck) BlockUtils(com.minecolonies.api.util.BlockUtils) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) ColonyManager(com.minecolonies.coremod.colony.ColonyManager) net.minecraft.block(net.minecraft.block) EntityLiving(net.minecraft.entity.EntityLiving) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.BuildingWareHouse) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) Colony(com.minecolonies.coremod.colony.Colony) Items(net.minecraft.init.Items) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockSolidSubstitution(com.minecolonies.coremod.blocks.BlockSolidSubstitution) AbstractEntityAIStructure(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure) BlockPos(net.minecraft.util.math.BlockPos) DamageSource(net.minecraft.util.DamageSource) ItemFlintAndSteel(net.minecraft.item.ItemFlintAndSteel) IBlockState(net.minecraft.block.state.IBlockState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntity(net.minecraft.tileentity.TileEntity) BlockWaypoint(com.minecolonies.coremod.blocks.BlockWaypoint) NotNull(org.jetbrains.annotations.NotNull) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack)

Example 2 with Stack

use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method checkIfRequestForItemExistOrCreate.

/**
 * Check if a stack has been requested already or is in the inventory.
 * If not in the inventory and not requested already, create request
 *
 * @param stack the requested stack.
 * @return true if in the inventory, else false.
 */
public boolean checkIfRequestForItemExistOrCreate(@NotNull final ItemStack stack) {
    if (InventoryUtils.hasItemInItemHandler(new InvWrapper(worker.getInventoryCitizen()), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, stack))) {
        return true;
    }
    if (getOwnBuilding().getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(stack)).isEmpty()) {
        final Stack stackRequest = new Stack(stack);
        worker.getCitizenData().createRequest(stackRequest);
    }
    return false;
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack)

Example 3 with Stack

use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method checkIfRequestForItemExistOrCreateAsynch.

/**
 * Check if a stack has been requested already or is in the inventory.
 * If not in the inventory and not requested already, create request
 *
 * @param stack the requested stack.
 * @return true if in the inventory, else false.
 */
public boolean checkIfRequestForItemExistOrCreateAsynch(@NotNull final ItemStack stack) {
    if (InventoryUtils.hasItemInItemHandler(new InvWrapper(worker.getInventoryCitizen()), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, stack) && s.getCount() >= stack.getCount())) {
        return true;
    }
    if (InventoryUtils.getItemCountInProvider(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, true, true)) >= stack.getCount() && InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, true, true), stack.getCount(), new InvWrapper(worker.getInventoryCitizen()))) {
        return true;
    }
    if (getOwnBuilding().getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(stack)).isEmpty()) {
        final Stack stackRequest = new Stack(stack);
        worker.getCitizenData().createRequestAsync(stackRequest);
    }
    return false;
}
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) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack)

Example 4 with Stack

use of com.minecolonies.api.colony.requestsystem.requestable.Stack in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method lookForRequests.

/**
 * Utility method to search for items currently needed.
 * Poll this until all items are there.
 */
@NotNull
private AIState lookForRequests() {
    if (!this.getOwnBuilding().hasWorkerOpenRequestsFiltered(worker.getCitizenData(), r -> !worker.getCitizenData().isRequestAsync(r.getToken())) && !getOwnBuilding().hasCitizenCompletedRequests(worker.getCitizenData())) {
        return IDLE;
    }
    if (!walkToBuilding() && getOwnBuilding().hasCitizenCompletedRequests(worker.getCitizenData())) {
        delay += DELAY_RECHECK;
        @SuppressWarnings(RAWTYPES) final ImmutableList<IRequest> completedRequests = getOwnBuilding().getCompletedRequests(worker.getCitizenData());
        completedRequests.stream().filter(r -> !(r.canBeDelivered())).forEach(r -> getOwnBuilding().markRequestAsAccepted(worker.getCitizenData(), r.getToken()));
        @SuppressWarnings(RAWTYPES) final IRequest firstDeliverableRequest = completedRequests.stream().filter(IRequest::canBeDelivered).findFirst().orElse(null);
        if (firstDeliverableRequest != null) {
            boolean async = false;
            if (worker.getCitizenData().isRequestAsync(firstDeliverableRequest.getToken())) {
                async = true;
                job.getAsyncRequests().remove(firstDeliverableRequest.getToken());
            }
            getOwnBuilding().markRequestAsAccepted(worker.getCitizenData(), firstDeliverableRequest.getToken());
            final ItemStack deliveredItemStack = firstDeliverableRequest.getDelivery();
            final int count = InventoryUtils.getItemCountInItemHandler(new InvWrapper(worker.getInventoryCitizen()), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(deliveredItemStack, stack, true, true));
            if (count >= deliveredItemStack.getCount() && getTotalRequiredAmount(deliveredItemStack) <= count) {
                return NEEDS_ITEM;
            }
            // Takes one Stack from the hut if existent
            if (InventoryUtils.getItemCountInProvider(getOwnBuilding(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(deliveredItemStack, stack, true, true)) >= deliveredItemStack.getCount() && InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(deliveredItemStack, stack, true, true), deliveredItemStack.getCount(), new InvWrapper(worker.getInventoryCitizen()))) {
                return NEEDS_ITEM;
            } else {
                // Lets try this again.
                if (async) {
                    worker.getCitizenData().createRequestAsync(firstDeliverableRequest.getRequest());
                } else {
                    worker.getCitizenData().createRequest(firstDeliverableRequest.getRequest());
                }
            }
        }
    }
    return NEEDS_ITEM;
}
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) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)4 ItemStack (net.minecraft.item.ItemStack)4 TypeToken (com.google.common.reflect.TypeToken)3 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)3 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)3 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Blocks (net.minecraft.init.Blocks)3 TileEntity (net.minecraft.tileentity.TileEntity)3 TileEntityChest (net.minecraft.tileentity.TileEntityChest)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)3 ImmutableList (com.google.common.collect.ImmutableList)2 Lists (com.google.common.collect.Lists)2 Tool (com.minecolonies.api.colony.requestsystem.requestable.Tool)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 IWalkToProxy (com.minecolonies.api.entity.ai.pathfinding.IWalkToProxy)2 com.minecolonies.api.util (com.minecolonies.api.util)2