Search in sources :

Example 11 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class WindowClipBoard method onOpened.

/**
 * Called when the window is opened.
 * Sets up the buttons for either hut mode or decoration mode.
 */
@Override
public void onOpened() {
    resourceList.setDataProvider(() -> getOpenRequests().size(), (index, rowPane) -> {
        final ImmutableList<IRequest> openRequests = getOpenRequests();
        if (index < 0 || index >= openRequests.size()) {
            return;
        }
        final IRequest request = openRequests.get(index);
        final ItemIcon exampleStackDisplay = rowPane.findPaneOfTypeByID(LIST_ELEMENT_ID_REQUEST_STACK, ItemIcon.class);
        final List<ItemStack> displayStacks = request.getDisplayStacks();
        if (!displayStacks.isEmpty()) {
            if (exampleStackDisplay != null) {
                exampleStackDisplay.setItem(displayStacks.get((lifeCount / LIFE_COUNT_DIVIDER) % displayStacks.size()));
            }
        } else {
            final Image logo = findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
            logo.setVisible(true);
            logo.setImage(request.getDisplayIcon());
        }
        final ColonyView view = ColonyManager.getColonyView(colonyId);
        rowPane.findPaneOfTypeByID(REQUESTER, Label.class).setLabelText(request.getRequester().getDisplayName(view.getRequestManager(), request.getToken()).getFormattedText());
        rowPane.findPaneOfTypeByID(REQUEST_SHORT_DETAIL, Label.class).setLabelText(request.getShortDisplayString().getFormattedText().replace("§f", ""));
    });
}
Also used : ColonyView(com.minecolonies.coremod.colony.ColonyView) ItemIcon(com.minecolonies.blockout.controls.ItemIcon) Label(com.minecolonies.blockout.controls.Label) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) Image(com.minecolonies.blockout.controls.Image)

Example 12 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class EntityAIWorkDeliveryman method deliver.

/**
 * Deliver the items to the hut.
 *
 * @return the next state.
 */
private AIState deliver() {
    if (job.isReturning()) {
        return DUMPING;
    }
    final BuildingDeliveryman deliveryHut = (getOwnBuilding() instanceof BuildingDeliveryman) ? (BuildingDeliveryman) getOwnBuilding() : null;
    final ILocation buildingToDeliver = deliveryHut == null ? null : deliveryHut.getBuildingToDeliver();
    if (deliveryHut == null) {
        return START_WORKING;
    } else if (buildingToDeliver == null) {
        if (job.getCurrentTask() != null && deliveryHut != null) {
            final IRequest<? extends Delivery> request = job.getCurrentTask();
            deliveryHut.setBuildingToDeliver(request.getRequest().getTarget());
            return getState();
        }
        return START_WORKING;
    }
    worker.setLatestStatus(new TextComponentTranslation("com.minecolonies.coremod.status.delivering"));
    if (!buildingToDeliver.isReachableFromLocation(worker.getLocation())) {
        Log.getLogger().info(worker.getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: ");
        return START_WORKING;
    }
    if (!worker.isWorkerAtSiteWithMove(buildingToDeliver.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
        return DELIVERY;
    }
    final InvWrapper workerInventory = new InvWrapper(worker.getInventoryCitizen());
    for (int i = 0; i < new InvWrapper(worker.getInventoryCitizen()).getSlots(); i++) {
        final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
        if (ItemStackUtils.isEmpty(stack)) {
            continue;
        }
        final TileEntity tileEntity = world.getTileEntity(buildingToDeliver.getInDimensionLocation());
        final ItemStack insertionResultStack;
        if (tileEntity instanceof TileEntityColonyBuilding && ((TileEntityColonyBuilding) tileEntity).getBuilding() instanceof AbstractBuildingWorker) {
            final AbstractBuilding building = ((TileEntityColonyBuilding) tileEntity).getBuilding();
            building.alterPickUpPriority(1);
            insertionResultStack = InventoryUtils.forceItemStackToItemHandler(new InvWrapper((TileEntityColonyBuilding) tileEntity), stack, ((AbstractBuildingWorker) building)::isItemStackInRequest);
        } else {
            insertionResultStack = InventoryUtils.forceItemStackToItemHandler(new InvWrapper((TileEntityColonyBuilding) tileEntity), stack, itemStack -> false);
        }
        if (!ItemStackUtils.isEmpty(insertionResultStack)) {
            if (ItemStack.areItemStacksEqual(insertionResultStack, stack)) {
                // same stack, we could not deliver ?
                if (buildingToDeliver instanceof TileEntityColonyBuilding && ((TileEntityColonyBuilding) tileEntity).getBuilding() instanceof AbstractBuildingWorker) {
                    chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, ((AbstractBuildingWorker) ((TileEntityColonyBuilding) tileEntity).getBuilding()).getMainWorker().getName());
                } else if (buildingToDeliver instanceof TileEntityColonyBuilding) {
                    chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new TextComponentString(" :" + ((TileEntityColonyBuilding) tileEntity).getBuilding().getSchematicName()));
                } else {
                    chatSpamFilter.talkWithoutSpam(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new TextComponentString(buildingToDeliver.getInDimensionLocation().toString()));
                }
            }
            // Insert the result back into the inventory so we do not loose it.
            workerInventory.insertItem(i, insertionResultStack, false);
        }
    }
    lastDelivery = deliveryHut.getBuildingToDeliver();
    worker.addExperience(1.0D);
    worker.setHeldItem(SLOT_HAND);
    deliveryHut.setBuildingToDeliver(null);
    job.finishRequest(true);
    setDelay(WAIT_DELAY);
    return START_WORKING;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) java.util(java.util) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) Log(com.minecolonies.blockout.Log) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityChest(net.minecraft.tileentity.TileEntityChest) 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) ImmutableList(com.google.common.collect.ImmutableList) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) ItemFood(net.minecraft.item.ItemFood) BlockPos(net.minecraft.util.math.BlockPos) AIState(com.minecolonies.coremod.entity.ai.util.AIState) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Collectors(java.util.stream.Collectors) com.minecolonies.coremod.colony.buildings(com.minecolonies.coremod.colony.buildings) TextComponentString(net.minecraft.util.text.TextComponentString) Nullable(org.jetbrains.annotations.Nullable) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) Configurations(com.minecolonies.api.configuration.Configurations) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) TextComponentString(net.minecraft.util.text.TextComponentString) TileEntity(net.minecraft.tileentity.TileEntity) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) ItemStack(net.minecraft.item.ItemStack)

Example 13 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method checkForToolOrWeapon.

protected boolean checkForToolOrWeapon(@NotNull final IToolType toolType, final int minimalLevel) {
    final ImmutableList<IRequest<? extends Tool>> openToolRequests = getOwnBuilding().getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeToken.of(Tool.class), r -> r.getRequest().getToolClass().equals(toolType) && r.getRequest().getMinLevel() >= minimalLevel);
    final ImmutableList<IRequest<? extends Tool>> completedToolRequests = getOwnBuilding().getCompletedRequestsOfTypeFiltered(worker.getCitizenData(), TypeToken.of(Tool.class), r -> r.getRequest().getToolClass().equals(toolType) && r.getRequest().getMinLevel() >= minimalLevel);
    if (checkForNeededTool(toolType, minimalLevel)) {
        if (openToolRequests.isEmpty() && completedToolRequests.isEmpty()) {
            final Tool request = new Tool(toolType, minimalLevel, getOwnBuilding().getMaxToolLevel() < minimalLevel ? minimalLevel : getOwnBuilding().getMaxToolLevel());
            worker.getCitizenData().createRequest(request);
        }
        return true;
    }
    return false;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Tool(com.minecolonies.api.colony.requestsystem.requestable.Tool)

Example 14 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest 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)

Example 15 with IRequest

use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.

the class WarehouseRequestResolver method canResolve.

@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends IDeliverable> requestToCheck) {
    if (!manager.getColony().getWorld().isRemote) {
        final Colony colony = (Colony) manager.getColony();
        final Set<TileEntityWareHouse> wareHouses = getWareHousesInColony(colony);
        wareHouses.removeIf(Objects::isNull);
        try {
            return wareHouses.stream().anyMatch(wareHouse -> wareHouse.hasMatchinItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack)));
        } catch (Exception e) {
            Log.getLogger().error(e);
        }
    }
    return false;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) TypeToken(com.google.common.reflect.TypeToken) Log(com.minecolonies.blockout.Log) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.BuildingWareHouse) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) TileEntityWareHouse(com.minecolonies.coremod.tileentities.TileEntityWareHouse) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) CONST_WAREHOUSE_RESOLVER_PRIORITY(com.minecolonies.api.util.RSConstants.CONST_WAREHOUSE_RESOLVER_PRIORITY) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) NotNull(org.jetbrains.annotations.NotNull) AbstractRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver) TileEntityWareHouse(com.minecolonies.coremod.tileentities.TileEntityWareHouse) Objects(java.util.Objects) Colony(com.minecolonies.coremod.colony.Colony)

Aggregations

IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 NotNull (org.jetbrains.annotations.NotNull)13 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)11 Nullable (org.jetbrains.annotations.Nullable)11 BlockPos (net.minecraft.util.math.BlockPos)10 List (java.util.List)9 ItemStack (net.minecraft.item.ItemStack)9 ImmutableList (com.google.common.collect.ImmutableList)8 TypeToken (com.google.common.reflect.TypeToken)7 Lists (com.google.common.collect.Lists)6 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)6 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)6 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)6 MineColonies (com.minecolonies.coremod.MineColonies)6 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)6 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)5 RAWTYPES (com.minecolonies.api.util.constant.Suppression.RAWTYPES)5 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)5 ArrayList (java.util.ArrayList)5 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)4