Search in sources :

Example 1 with IDeliverymanRequestable

use of com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable in project minecolonies by ldtteam.

the class EntityAIWorkDeliveryman method deliver.

/**
 * Deliver the items to the hut. TODO: Current precondition: The dman's inventory may only consist of the requested itemstack.
 *
 * @return the next state.
 */
private IAIState deliver() {
    final IRequest<? extends IDeliverymanRequestable> currentTask = job.getCurrentTask();
    if (!(currentTask instanceof DeliveryRequest)) {
        // Since prepareDelivery() was called earlier, go dumping first and then restart.
        return DUMPING;
    }
    worker.getCitizenData().setVisibleStatus(DELIVERING);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.delivering"));
    final ILocation targetBuildingLocation = ((Delivery) currentTask.getRequest()).getTarget();
    if (!targetBuildingLocation.isReachableFromLocation(worker.getLocation())) {
        Log.getLogger().info(worker.getCitizenColonyHandler().getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: ");
        return START_WORKING;
    }
    if (!worker.isWorkerAtSiteWithMove(targetBuildingLocation.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
        setDelay(WALK_DELAY);
        return DELIVERY;
    }
    final TileEntity tileEntity = world.getBlockEntity(targetBuildingLocation.getInDimensionLocation());
    if (!(tileEntity instanceof TileEntityColonyBuilding)) {
        // TODO: Non-Colony deliveries are unsupported yet. Fix that at some point in time.
        job.finishRequest(true);
        return START_WORKING;
    }
    final IBuilding targetBuilding = ((AbstractTileEntityColonyBuilding) tileEntity).getBuilding();
    boolean success = true;
    boolean extracted = false;
    final IItemHandler workerInventory = worker.getInventoryCitizen();
    for (int i = 0; i < workerInventory.getSlots(); i++) {
        if (workerInventory.getStackInSlot(i).isEmpty()) {
            continue;
        }
        final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
        if (ItemStackUtils.isEmpty(stack)) {
            continue;
        }
        extracted = true;
        final ItemStack insertionResultStack;
        // TODO: Please only push items into the target that were actually requested.
        if (targetBuilding instanceof AbstractBuilding) {
            insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, ((IBuilding) targetBuilding)::isItemStackInRequest);
        } else {
            // Buildings that are not inherently part of the request system, but just receive a delivery, cannot have their items replaced.
            // Therefore, the keep-predicate always returns true.
            insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, itemStack -> true);
        }
        if (!ItemStackUtils.isEmpty(insertionResultStack)) {
            if (ItemStack.matches(insertionResultStack, stack) && worker.getCitizenData() != null) {
                // The replaced stack is the same as the one we tried to put into the inventory.
                // Meaning, replacing failed.
                success = false;
                if (targetBuilding.hasModule(WorkerBuildingModule.class)) {
                    worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, targetBuilding.getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen().getName()), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuilding.getID()));
                } else {
                    worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new StringTextComponent(" :" + targetBuilding.getSchematicName())), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuildingLocation.getInDimensionLocation()));
                }
            }
            // Insert the result back into the inventory so we do not lose it.
            workerInventory.insertItem(i, insertionResultStack, false);
        }
    }
    if (!extracted) {
        // This can only happen if the dman's inventory was completely empty.
        // Let the retry-system handle this case.
        worker.decreaseSaturationForContinuousAction();
        worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
        job.finishRequest(false);
        // No need to go dumping in this case.
        return START_WORKING;
    }
    worker.getCitizenExperienceHandler().addExperience(1.5D);
    worker.decreaseSaturationForContinuousAction();
    worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
    job.finishRequest(true);
    return success ? START_WORKING : DUMPING;
}
Also used : TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) DeliveryRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.DeliveryRequest) IWareHouse(com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse) PickupRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.PickupRequest) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) StringTextComponent(net.minecraft.util.text.StringTextComponent) Hand(net.minecraft.util.Hand) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Log(com.minecolonies.api.util.Log) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) BuildingDeliveryman(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingDeliveryman) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) DeliveryRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.DeliveryRequest) IItemHandler(net.minecraftforge.items.IItemHandler) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) TileEntity(net.minecraft.tileentity.TileEntity) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 2 with IDeliverymanRequestable

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

the class WindowHutCrafterTaskModule method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final List<IToken<?>> tasks = new ArrayList<>();
    for (final WorkerBuildingModuleView moduleView : buildingView.getModuleViews(WorkerBuildingModuleView.class)) {
        for (final int citizenId : moduleView.getAssignedCitizens()) {
            ICitizenDataView citizen = buildingView.getColony().getCitizen(citizenId);
            if (citizen != null) {
                if (citizen.getJobView() instanceof CrafterJobView) {
                    tasks.addAll(((CrafterJobView) citizen.getJobView()).getDataStore().getQueue());
                } else if (citizen.getJobView() instanceof DmanJobView) {
                    tasks.addAll(((DmanJobView) citizen.getJobView()).getDataStore().getQueue());
                }
            }
        }
    }
    final ScrollingList deliveryList = findPaneOfTypeByID(LIST_TASKS, ScrollingList.class);
    deliveryList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            tasks.removeIf(token -> buildingView.getColony().getRequestManager().getRequestForToken(token) == null);
            return tasks.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final IRequest<?> request = buildingView.getColony().getRequestManager().getRequestForToken(tasks.get(index));
            final IRequest<?> parent = buildingView.getColony().getRequestManager().getRequestForToken(request.getParent());
            if (parent != null) {
                rowPane.findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), request).getString() + " ->");
                rowPane.findPaneOfTypeByID(PARENT, Text.class).setText(parent.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), parent));
            } else {
                rowPane.findPaneOfTypeByID(REQUESTER, Text.class).setText(request.getRequester().getRequesterDisplayName(buildingView.getColony().getRequestManager(), request));
                rowPane.findPaneOfTypeByID(PARENT, Text.class).clearText();
            }
            rowPane.findPaneOfTypeByID(REQUEST_SHORT_DETAIL, Text.class).setText(request.getShortDisplayString().getString().replace("§f", ""));
            if (request.getRequest() instanceof IDeliverymanRequestable) {
                rowPane.findPaneOfTypeByID(REQUEST_PRIORITY, Text.class).setText(LanguageHandler.format(COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY) + ((IDeliverymanRequestable) (request.getRequest())).getPriority());
            }
            final Image logo = rowPane.findPaneOfTypeByID(DELIVERY_IMAGE, Image.class);
            logo.setImage(request.getDisplayIcon());
        }
    });
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) ScrollingList(com.ldtteam.blockout.views.ScrollingList) Pane(com.ldtteam.blockout.Pane) COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_PRIORITY) Text(com.ldtteam.blockout.controls.Text) ArrayList(java.util.ArrayList) DmanJobView(com.minecolonies.coremod.colony.jobs.views.DmanJobView) List(java.util.List) Image(com.ldtteam.blockout.controls.Image) IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) AbstractModuleWindow(com.minecolonies.coremod.client.gui.AbstractModuleWindow) CrafterJobView(com.minecolonies.coremod.colony.jobs.views.CrafterJobView) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Image(com.ldtteam.blockout.controls.Image) Pane(com.ldtteam.blockout.Pane) CrafterJobView(com.minecolonies.coremod.colony.jobs.views.CrafterJobView) IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) DmanJobView(com.minecolonies.coremod.colony.jobs.views.DmanJobView) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 3 with IDeliverymanRequestable

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

the class JobDeliveryman method addRequest.

/**
 * Method used to add a request to the queue
 *
 * @param token The token of the requests to add.
 */
public void addRequest(@NotNull final IToken<?> token, final int insertionIndex) {
    final IRequestManager requestManager = getColony().getRequestManager();
    IRequest<? extends IDeliverymanRequestable> newRequest = (IRequest<? extends IDeliverymanRequestable>) (requestManager.getRequestForToken(token));
    LinkedList<IToken<?>> taskQueue = getTaskQueueFromDataStore();
    int offset = 0;
    for (int i = insertionIndex; i < taskQueue.size(); i++) {
        final IToken theToken = taskQueue.get(i);
        final IRequest<? extends IDeliverymanRequestable> request = (IRequest<? extends IDeliverymanRequestable>) (requestManager.getRequestForToken(theToken));
        if (request == null || request.getState() == RequestState.COMPLETED) {
            taskQueue.remove(theToken);
            i--;
            offset--;
        } else {
            request.getRequest().incrementPriorityDueToAging();
        }
    }
    getTaskQueueFromDataStore().add(Math.max(0, insertionIndex + offset), token);
    if (newRequest instanceof StandardRequests.PickupRequest && newRequest.getRequest().getPriority() == getPlayerActionPriority(true)) {
        getCitizen().getEntity().ifPresent(e -> e.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_FORCEPICKUP));
        ;
    }
}
Also used : IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) StandardRequests(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Example 4 with IDeliverymanRequestable

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

the class EntityAIWorkDeliveryman method deliver.

/**
 * Deliver the items to the hut. TODO: Current precondition: The dman's inventory may only consist of the requested itemstack.
 *
 * @return the next state.
 */
private IAIState deliver() {
    final IRequest<? extends IDeliverymanRequestable> currentTask = job.getCurrentTask();
    if (!(currentTask instanceof DeliveryRequest)) {
        // Since prepareDelivery() was called earlier, go dumping first and then restart.
        return DUMPING;
    }
    worker.getCitizenData().setVisibleStatus(DELIVERING);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.delivering"));
    final ILocation targetBuildingLocation = ((Delivery) currentTask.getRequest()).getTarget();
    if (!targetBuildingLocation.isReachableFromLocation(worker.getLocation())) {
        Log.getLogger().info(worker.getCitizenColonyHandler().getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: ");
        return START_WORKING;
    }
    if (!worker.isWorkerAtSiteWithMove(targetBuildingLocation.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
        setDelay(WALK_DELAY);
        return DELIVERY;
    }
    final TileEntity tileEntity = world.getBlockEntity(targetBuildingLocation.getInDimensionLocation());
    if (!(tileEntity instanceof TileEntityColonyBuilding)) {
        // TODO: Non-Colony deliveries are unsupported yet. Fix that at some point in time.
        job.finishRequest(true);
        return START_WORKING;
    }
    final IBuilding targetBuilding = ((AbstractTileEntityColonyBuilding) tileEntity).getBuilding();
    boolean success = true;
    boolean extracted = false;
    final IItemHandler workerInventory = worker.getInventoryCitizen();
    for (int i = 0; i < workerInventory.getSlots(); i++) {
        if (workerInventory.getStackInSlot(i).isEmpty()) {
            continue;
        }
        final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
        if (ItemStackUtils.isEmpty(stack)) {
            continue;
        }
        extracted = true;
        final ItemStack insertionResultStack;
        // TODO: Please only push items into the target that were actually requested.
        if (targetBuilding instanceof AbstractBuilding) {
            insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, ((IBuilding) targetBuilding)::isItemStackInRequest);
        } else {
            // Buildings that are not inherently part of the request system, but just receive a delivery, cannot have their items replaced.
            // Therefore, the keep-predicate always returns true.
            insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, itemStack -> true);
        }
        if (!ItemStackUtils.isEmpty(insertionResultStack)) {
            if (ItemStack.matches(insertionResultStack, stack) && worker.getCitizenData() != null) {
                // The replaced stack is the same as the one we tried to put into the inventory.
                // Meaning, replacing failed.
                success = false;
                if (targetBuilding.hasModule(WorkerBuildingModule.class)) {
                    worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, targetBuilding.getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen().getName()), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuilding.getID()));
                } else {
                    worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new StringTextComponent(" :" + targetBuilding.getSchematicName())), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuildingLocation.getInDimensionLocation()));
                }
            }
            // Insert the result back into the inventory so we do not lose it.
            workerInventory.insertItem(i, insertionResultStack, false);
        }
    }
    if (!extracted) {
        // This can only happen if the dman's inventory was completely empty.
        // Let the retry-system handle this case.
        worker.decreaseSaturationForContinuousAction();
        worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
        job.finishRequest(false);
        // No need to go dumping in this case.
        return START_WORKING;
    }
    worker.getCitizenExperienceHandler().addExperience(1.5D);
    worker.decreaseSaturationForContinuousAction();
    worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
    job.finishRequest(true);
    return success ? START_WORKING : DUMPING;
}
Also used : TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) DeliveryRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.DeliveryRequest) IWareHouse(com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse) PickupRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.PickupRequest) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ArrayList(java.util.ArrayList) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ItemStack(net.minecraft.item.ItemStack) IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) StringTextComponent(net.minecraft.util.text.StringTextComponent) Hand(net.minecraft.util.Hand) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) Log(com.minecolonies.api.util.Log) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) AbstractEntityAIInteract(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIInteract) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) BuildingDeliveryman(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingDeliveryman) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) DeliveryRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.DeliveryRequest) IItemHandler(net.minecraftforge.items.IItemHandler) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) PosBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.PosBasedInteraction) TileEntity(net.minecraft.tileentity.TileEntity) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) Delivery(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 5 with IDeliverymanRequestable

use of com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable in project minecolonies by ldtteam.

the class JobDeliveryman method addRequest.

/**
 * Method used to add a request to the queue
 *
 * @param token The token of the requests to add.
 */
public void addRequest(@NotNull final IToken<?> token, final int insertionIndex) {
    final IRequestManager requestManager = getColony().getRequestManager();
    IRequest<? extends IDeliverymanRequestable> newRequest = (IRequest<? extends IDeliverymanRequestable>) (requestManager.getRequestForToken(token));
    LinkedList<IToken<?>> taskQueue = getTaskQueueFromDataStore();
    int offset = 0;
    for (int i = insertionIndex; i < taskQueue.size(); i++) {
        final IToken theToken = taskQueue.get(i);
        final IRequest<? extends IDeliverymanRequestable> request = (IRequest<? extends IDeliverymanRequestable>) (requestManager.getRequestForToken(theToken));
        if (request == null || request.getState() == RequestState.COMPLETED) {
            taskQueue.remove(theToken);
            i--;
            offset--;
        } else {
            request.getRequest().incrementPriorityDueToAging();
        }
    }
    getTaskQueueFromDataStore().add(Math.max(0, insertionIndex + offset), token);
    if (newRequest instanceof StandardRequests.PickupRequest && newRequest.getRequest().getPriority() == getPlayerActionPriority(true)) {
        getCitizen().getEntity().ifPresent(e -> e.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_DELIVERYMAN_FORCEPICKUP));
        ;
    }
}
Also used : IDeliverymanRequestable(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable) StandardRequests(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Aggregations

IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)6 IDeliverymanRequestable (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable)6 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 NotNull (org.jetbrains.annotations.NotNull)3 Pane (com.ldtteam.blockout.Pane)2 Image (com.ldtteam.blockout.controls.Image)2 Text (com.ldtteam.blockout.controls.Text)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 LanguageHandler (com.ldtteam.structurize.util.LanguageHandler)2 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery)2