Search in sources :

Example 1 with StationRequestResolver

use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by Minecolonies.

the class StationRequestResolverFactory method deserialize.

@NotNull
@Override
public StationRequestResolver deserialize(IFactoryController controller, @NotNull PacketBuffer buffer) throws Throwable {
    final IToken<?> token = controller.deserialize(buffer);
    final ILocation location = controller.deserialize(buffer);
    return new StationRequestResolver(location, token);
}
Also used : ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) StationRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with StationRequestResolver

use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by Minecolonies.

the class StationRequestResolverFactory method deserialize.

@NotNull
@Override
public StationRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
    final IToken<?> token = controller.deserialize(nbt.getCompound(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompound(NBT_LOCATION));
    return new StationRequestResolver(location, token);
}
Also used : ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) StationRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with StationRequestResolver

use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by ldtteam.

the class QuarryModule method createResolvers.

@Override
public List<IRequestResolver<?>> createResolvers() {
    final ImmutableList.Builder<IRequestResolver<?>> builder = ImmutableList.builder();
    builder.add(new StationRequestResolver(building.getRequester().getLocation(), building.getColony().getRequestManager().getFactoryController().getNewInstance(TypeConstants.ITOKEN)));
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StationRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver)

Example 4 with StationRequestResolver

use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by ldtteam.

the class StationRequestResolverFactory method deserialize.

@NotNull
@Override
public StationRequestResolver deserialize(@NotNull final IFactoryController controller, @NotNull final CompoundNBT nbt) {
    final IToken<?> token = controller.deserialize(nbt.getCompound(NBT_TOKEN));
    final ILocation location = controller.deserialize(nbt.getCompound(NBT_LOCATION));
    return new StationRequestResolver(location, token);
}
Also used : ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) StationRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with StationRequestResolver

use of com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver in project minecolonies by ldtteam.

the class AbstractEntityAIBasic method lookForRequests.

/**
 * Utility method to search for items currently needed. Poll this until all items are there.
 *
 * @return the next state to go to.
 */
@NotNull
private IAIState lookForRequests() {
    if (!this.getOwnBuilding().hasOpenSyncRequest(worker.getCitizenData()) && !getOwnBuilding().hasCitizenCompletedRequests(worker.getCitizenData())) {
        return afterRequestPickUp();
    }
    if (getOwnBuilding().hasCitizenCompletedRequests(worker.getCitizenData())) {
        final Collection<IRequest<?>> completedRequests = getOwnBuilding().getCompletedRequests(worker.getCitizenData());
        final List<IRequest<?>> deliverableRequests = new ArrayList<>();
        for (final IRequest<?> req : completedRequests) {
            if (!req.canBeDelivered()) {
                getOwnBuilding().markRequestAsAccepted(worker.getCitizenData(), req.getId());
            } else {
                deliverableRequests.add(req);
            }
        }
        if (!deliverableRequests.isEmpty()) {
            final IRequest<?> firstDeliverableRequest = deliverableRequests.get(0);
            final IRequestResolver<?> resolver = getOwnBuilding().getColony().getRequestManager().getResolverForRequest(firstDeliverableRequest.getId());
            final ILocation pickupLocation = resolver instanceof StationRequestResolver ? resolver.getLocation() : getOwnBuilding().getLocation();
            if (walkToBlock(pickupLocation.getInDimensionLocation()) || !WorldUtil.isBlockLoaded(world, pickupLocation.getInDimensionLocation())) {
                return NEEDS_ITEM;
            }
            final TileEntity blockEntity = world.getBlockEntity(pickupLocation.getInDimensionLocation());
            if (blockEntity == null) {
                return NEEDS_ITEM;
            }
            boolean async = false;
            if (worker.getCitizenData().isRequestAsync(firstDeliverableRequest.getId())) {
                async = true;
                job.getAsyncRequests().remove(firstDeliverableRequest.getId());
            }
            getOwnBuilding().markRequestAsAccepted(worker.getCitizenData(), firstDeliverableRequest.getId());
            final List<IItemHandler> validHandlers = Lists.newArrayList();
            validHandlers.add(worker.getItemHandlerCitizen());
            validHandlers.addAll(InventoryUtils.getItemHandlersFromProvider(blockEntity));
            // Check if we either have the requested Items in our inventory or if they are in the building.
            if (InventoryUtils.areAllItemsInItemHandlerList(firstDeliverableRequest.getDeliveries(), validHandlers)) {
                final List<ItemStack> niceToHave = itemsNiceToHave();
                final List<ItemStack> contained = InventoryUtils.getContainedFromItemHandler(firstDeliverableRequest.getDeliveries(), worker.getItemHandlerCitizen());
                InventoryUtils.moveItemStacksWithPossibleSwap(worker.getItemHandlerCitizen(), InventoryUtils.getItemHandlersFromProvider(blockEntity), firstDeliverableRequest.getDeliveries(), itemStack -> contained.stream().anyMatch(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack)) || niceToHave.stream().anyMatch(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack)));
                return NEEDS_ITEM;
            } else {
                // Lets try this again.
                if (async) {
                    worker.getCitizenData().createRequestAsync(firstDeliverableRequest.getRequest());
                } else {
                    worker.getCitizenData().createRequest(firstDeliverableRequest.getRequest());
                }
            }
        }
    } else {
        walkToBuilding();
    }
    return NEEDS_ITEM;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) StationRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver) ArrayList(java.util.ArrayList) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StationRequestResolver (com.minecolonies.coremod.colony.requestsystem.resolvers.StationRequestResolver)8 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)6 NotNull (org.jetbrains.annotations.NotNull)6 ImmutableList (com.google.common.collect.ImmutableList)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IRequestResolver (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IItemHandler (net.minecraftforge.items.IItemHandler)2