Search in sources :

Example 1 with IRequestManager

use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.

the class DeliveryRequestResolver method attemptResolve.

@Nullable
@Override
public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
    if (manager.getColony().getWorld().isRemote) {
        return null;
    }
    final Colony colony = (Colony) manager.getColony();
    // We can do an instant get here, since we are already filtering on anything that has no entity.
    final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> request.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).min(Comparator.comparing((CitizenData c) -> ((JobDeliveryman) c.getJob()).getTaskQueue().size()).thenComparing(Comparator.comparing(c -> {
        BlockPos targetPos = request.getRequest().getTarget().getInDimensionLocation();
        // We can do an instant get here, since we are already filtering on anything that has no entity.
        BlockPos entityLocation = c.getCitizenEntity().get().getLocation().getInDimensionLocation();
        return BlockPosUtil.getDistanceSquared(targetPos, entityLocation);
    }))).orElse(null);
    if (freeDeliveryMan == null) {
        return null;
    }
    final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
    job.addRequest(request.getToken());
    return Lists.newArrayList();
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BlockPos(net.minecraft.util.math.BlockPos) TypeToken(com.google.common.reflect.TypeToken) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Log(com.minecolonies.blockout.Log) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Nullable(org.jetbrains.annotations.Nullable) CitizenData(com.minecolonies.coremod.colony.CitizenData) List(java.util.List) Lists(com.google.common.collect.Lists) MineColonies(com.minecolonies.coremod.MineColonies) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AbstractRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IRequestManager

use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.

the class DeliveryRequestResolver method canResolve.

@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends Delivery> requestToCheck) {
    if (manager.getColony().getWorld().isRemote) {
        return false;
    }
    final Colony colony = (Colony) manager.getColony();
    final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> requestToCheck.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).findFirst().orElse(null);
    return freeDeliveryMan != null;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BlockPos(net.minecraft.util.math.BlockPos) TypeToken(com.google.common.reflect.TypeToken) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Log(com.minecolonies.blockout.Log) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Nullable(org.jetbrains.annotations.Nullable) CitizenData(com.minecolonies.coremod.colony.CitizenData) List(java.util.List) Lists(com.google.common.collect.Lists) MineColonies(com.minecolonies.coremod.MineColonies) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AbstractRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData)

Example 3 with IRequestManager

use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.

the class AbstractBuilding method getRequiredItemsAndAmount.

/**
 * Override this method if you want to keep an amount of items in inventory.
 * When the inventory is full, everything get's dumped into the building chest.
 * But you can use this method to hold some stacks back.
 *
 * @return a list of objects which should be kept.
 */
public Map<Predicate<ItemStack>, Integer> getRequiredItemsAndAmount() {
    final Map<Predicate<ItemStack>, Integer> toKeep = new HashMap<>();
    toKeep.putAll(keepX);
    final IRequestManager manager = colony.getRequestManager();
    toKeep.put(stack -> this.getOpenRequestsByCitizen().values().stream().anyMatch(list -> list.stream().anyMatch(token -> manager.getRequestForToken(token).getRequest() instanceof IDeliverable && ((IDeliverable) manager.getRequestForToken(token).getRequest()).matches(stack))), Integer.MAX_VALUE);
    return toKeep;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuildingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.BuildingRequestResolver) Constants(net.minecraftforge.common.util.Constants) ImmutableCollection(com.google.common.collect.ImmutableCollection) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) NBTTagList(net.minecraft.nbt.NBTTagList) Block(net.minecraft.block.Block) CombinedItemHandler(com.minecolonies.coremod.inventory.api.CombinedItemHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView) InventoryHelper(net.minecraft.inventory.InventoryHelper) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Collectors(java.util.stream.Collectors) Capability(net.minecraftforge.common.capabilities.Capability) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) Nullable(org.jetbrains.annotations.Nullable) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) BuildingUtils(com.minecolonies.coremod.util.BuildingUtils) EntityPlayer(net.minecraft.entity.player.EntityPlayer) com.minecolonies.coremod.blocks(com.minecolonies.coremod.blocks) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) IRequestResolverProvider(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolverProvider) ItemStorage(com.minecolonies.api.crafting.ItemStorage) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) NotNull(org.jetbrains.annotations.NotNull) NBTUtil(net.minecraft.nbt.NBTUtil) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) Suppression(com.minecolonies.api.util.constant.Suppression) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) EntityAIWorkDeliveryman(com.minecolonies.coremod.entity.ai.citizen.deliveryman.EntityAIWorkDeliveryman) TypeToken(com.google.common.reflect.TypeToken) Constructor(java.lang.reflect.Constructor) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) ByteBuf(io.netty.buffer.ByteBuf) StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) ConstructionTapeHelper(com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper) com.minecolonies.api.util(com.minecolonies.api.util) Nonnull(javax.annotation.Nonnull) WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) BlockContainer(net.minecraft.block.BlockContainer) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) Tuple(net.minecraft.util.Tuple) BlockPos(net.minecraft.util.math.BlockPos) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) com.minecolonies.coremod.colony(com.minecolonies.coremod.colony) IInventory(net.minecraft.inventory.IInventory) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) ByteBufUtils(net.minecraftforge.fml.common.network.ByteBufUtils) TileEntity(net.minecraft.tileentity.TileEntity) IRequestSystemBuildingDataStore(com.minecolonies.api.colony.requestsystem.data.IRequestSystemBuildingDataStore) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) Predicate(java.util.function.Predicate)

Example 4 with IRequestManager

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

Example 5 with IRequestManager

use of com.minecolonies.api.colony.requestsystem.manager.IRequestManager in project minecolonies by Minecolonies.

the class AbstractBuildingDependentRequestResolver method resolve.

@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request) {
    final AbstractBuilding building = getBuilding(manager, request.getToken()).map(r -> (AbstractBuilding) r).get();
    resolveForBuilding(manager, request, building);
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) RequestHandler(com.minecolonies.coremod.colony.requestsystem.management.handlers.RequestHandler) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IBuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.IBuildingBasedRequester) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)5 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)5 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)5 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)5 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 TypeToken (com.google.common.reflect.TypeToken)4 List (java.util.List)4 BlockPos (net.minecraft.util.math.BlockPos)4 Lists (com.google.common.collect.Lists)3 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)3 Log (com.minecolonies.blockout.Log)3 Colony (com.minecolonies.coremod.colony.Colony)3 AbstractRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver)3 ImmutableList (com.google.common.collect.ImmutableList)2 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)2 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)2 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)2 BlockPosUtil (com.minecolonies.api.util.BlockPosUtil)2