Search in sources :

Example 1 with IDeliverable

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

the class StandardPlayerRequestResolver method resolve.

@Nullable
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest request) throws RuntimeException {
    final IColony colony = manager.getColony();
    if (colony instanceof Colony) {
        if (Configurations.requestSystem.creativeResolve && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get() instanceof AbstractBuilding) {
            final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get();
            final Optional<CitizenData> citizenDataOptional = building.getCitizenForRequest(request.getToken());
            final List<ItemStack> resolvablestacks = request.getDisplayStacks();
            if (!resolvablestacks.isEmpty() && citizenDataOptional.isPresent()) {
                final ItemStack resolveStack = resolvablestacks.get(0);
                resolveStack.setCount(Math.min(((IDeliverable) request.getRequest()).getCount(), resolveStack.getMaxStackSize()));
                final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(new InvWrapper(citizenDataOptional.get().getInventory()), resolveStack);
                if (ItemStackUtils.isEmpty(remainingItemStack)) {
                    manager.updateRequestState(request.getToken(), RequestState.COMPLETED);
                    return;
                }
            }
        }
        final List<EntityPlayer> players = new ArrayList<>(((Colony) colony).getMessageEntityPlayers());
        final EntityPlayer owner = ServerUtils.getPlayerFromUUID(colony.getWorld(), ((Colony) colony).getPermissions().getOwner());
        final TextComponentString colonyDescription = new TextComponentString(colony.getName() + ":");
        if (manager.getColony().getWorld().isDaytime()) {
            if (owner != null) {
                players.remove(owner);
                LanguageHandler.sendPlayerMessage(owner, "com.minecolonies.requestsystem.playerresolver", request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
            }
            LanguageHandler.sendPlayersMessage(players, "com.minecolonies.requestsystem.playerresolver", colonyDescription.getFormattedText() + " " + request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
        }
    }
    assignedRequests.add(request.getToken());
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IColony(com.minecolonies.api.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IDeliverable

use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable 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 3 with IDeliverable

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

Example 4 with IDeliverable

use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable 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 5 with IDeliverable

use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable 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

IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)6 ItemStack (net.minecraft.item.ItemStack)6 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)5 BlockPos (net.minecraft.util.math.BlockPos)5 NotNull (org.jetbrains.annotations.NotNull)5 ImmutableList (com.google.common.collect.ImmutableList)4 TypeToken (com.google.common.reflect.TypeToken)4 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)4 List (java.util.List)4 Nullable (org.jetbrains.annotations.Nullable)4 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)3 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)3 Colony (com.minecolonies.coremod.colony.Colony)3 TileEntity (net.minecraft.tileentity.TileEntity)3 TileEntityChest (net.minecraft.tileentity.TileEntityChest)3 EnumFacing (net.minecraft.util.EnumFacing)3 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)3 Lists (com.google.common.collect.Lists)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 Stack (com.minecolonies.api.colony.requestsystem.requestable.Stack)2