Search in sources :

Example 6 with IRequest

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

the class RequestHandler method processParentReplacement.

/**
 * Method used during clean up to process Parent replacement.
 *
 * @param manager   The manager which is handling the cleanup.
 * @param target    The target request, which gets their parent replaced.
 * @param newParent The new cleanup request used to cleanup the target when it is finished.
 */
@SuppressWarnings({ RAWTYPES, UNCHECKED })
public static void processParentReplacement(final IStandardRequestManager manager, final IRequest target, final IRequest newParent) {
    // Clear out the existing parent.
    if (target.hasParent()) {
        final IRequest currentParent = RequestHandler.getRequest(manager, target.getParent());
        currentParent.removeChild(target.getToken());
        target.setParent(null);
    }
    if (newParent != null) {
        // Switch out the parent, and add the old child to the cleanup request as new child
        newParent.addChild(target.getToken());
        target.setParent(newParent.getToken());
        // Assign the new parent request if it is not assigned yet.
        if (!RequestHandler.isAssigned(manager, newParent.getToken())) {
            RequestHandler.assignRequest(manager, newParent);
        }
    }
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Example 7 with IRequest

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

the class RequestHandler method onRequestCancelled.

/**
 * Method used to handle requests that were overruled or cancelled.
 * Cancels all children first, handles the creation of clean up requests.
 *
 * @param manager The manager that got notified of the cancellation or overruling.
 * @param token   The token of the request that got cancelled or overruled
 */
@SuppressWarnings(UNCHECKED)
public static void onRequestCancelled(final IStandardRequestManager manager, final IToken<?> token) {
    @SuppressWarnings(RAWTYPES) final IRequest request = RequestHandler.getRequest(manager, token);
    if (request == null) {
        return;
    }
    request.setState(new WrappedStaticStateRequestManager(manager), RequestState.CANCELLED);
    processInternalCancellation(manager, token);
    // Notify the requester.
    final IRequester requester = request.getRequester();
    requester.onRequestCancelled(manager, token);
    cleanRequestData(manager, token);
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) WrappedStaticStateRequestManager(com.minecolonies.coremod.colony.requestsystem.management.manager.wrapped.WrappedStaticStateRequestManager)

Example 8 with IRequest

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

the class RequestHandler method processInternalCancellation.

/**
 * Method used to handle cancellation internally without notifying the requester that the request has been cancelled.
 *
 * @param manager The manager for which the cancellation is internally processed.
 * @param token   The token which is internally processed.
 */
@SuppressWarnings(UNCHECKED)
public static void processInternalCancellation(final IStandardRequestManager manager, final IToken<?> token) {
    @SuppressWarnings(RAWTYPES) final IRequest request = getRequest(manager, token);
    if (manager.getRequestResolverRequestAssignmentDataStore().getAssignmentForValue(token) == null) {
        return;
    }
    // Lets cancel all our children first, else this would make a big fat mess.
    if (request.hasChildren()) {
        final ImmutableCollection<IToken<?>> currentChildren = request.getChildren();
        currentChildren.forEach(t -> onRequestCancelled(manager, t));
    }
    // Now lets get ourselfs a clean up.
    final IRequestResolver<?> targetResolver = ResolverHandler.getResolverForRequest(manager, request);
    processParentReplacement(manager, request, targetResolver.onRequestCancelled(manager, request));
    manager.updateRequestState(token, RequestState.FINALIZING);
}
Also used : IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Example 9 with IRequest

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

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

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