Search in sources :

Example 41 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class BuildingCombatAcademy method getCombatPartner.

/**
 * Get the citizen of the combat partner or null if not existing or available.
 *
 * @param citizen the citizen.
 * @return the citizen or null.
 */
public AbstractEntityCitizen getCombatPartner(final AbstractEntityCitizen citizen) {
    final ICitizenData data = citizen.getCitizenData();
    if (data != null) {
        final int citizenId;
        if (trainingPartners.containsKey(data.getId())) {
            citizenId = trainingPartners.get(data.getId());
        } else if (trainingPartners.containsValue(data.getId())) {
            citizenId = trainingPartners.inverse().get(data.getId());
        } else {
            return null;
        }
        final ICitizenData citizenData = getFirstModuleOccurance(WorkAtHomeBuildingModule.class).getAssignedCitizen().stream().filter(cit -> cit.getId() != data.getId()).filter(cit -> cit.getId() == citizenId).findFirst().orElse(null);
        if (citizenData != null) {
            return citizenData.getEntity().orElse(null);
        }
    }
    return null;
}
Also used : Window(com.ldtteam.blockout.views.Window) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) Random(java.util.Random) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) WindowHutWorkerModulePlaceholder(com.minecolonies.coremod.client.gui.huts.WindowHutWorkerModulePlaceholder) Map(java.util.Map) ListNBT(net.minecraft.nbt.ListNBT) BiMap(com.google.common.collect.BiMap) IColonyView(com.minecolonies.api.colony.IColonyView) WorkAtHomeBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkAtHomeBuildingModule) World(net.minecraft.world.World) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) JobCombatTraining(com.minecolonies.coremod.colony.jobs.JobCombatTraining) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BlockPos(net.minecraft.util.math.BlockPos) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Collectors(java.util.stream.Collectors) CarvedPumpkinBlock(net.minecraft.block.CarvedPumpkinBlock) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) HashBiMap(com.google.common.collect.HashBiMap) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) List(java.util.List) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) NBTUtils(com.minecolonies.api.util.NBTUtils) IColony(com.minecolonies.api.colony.IColony) HayBlock(net.minecraft.block.HayBlock) NotNull(org.jetbrains.annotations.NotNull) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 42 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class PublicWorkerCraftingProductionResolver method removeRequestFromTaskList.

private void removeRequestFromTaskList(@NotNull final IRequest<? extends PublicCrafting> completedRequest, final IColony colony) {
    final ICitizenData holdingCrafter = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof AbstractJobCrafter && (((AbstractJobCrafter<?, ?>) c.getJob()).getTaskQueue().contains(completedRequest.getId()) || ((AbstractJobCrafter<?, ?>) c.getJob()).getAssignedTasks().contains(completedRequest.getId()))).findFirst().orElse(null);
    if (holdingCrafter != null) {
        final AbstractJobCrafter<?, ?> job = (AbstractJobCrafter<?, ?>) holdingCrafter.getJob();
        job.onTaskDeletion(completedRequest.getId());
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Example 43 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class StandardPlayerRequestResolver method resolveRequest.

@Override
public void resolveRequest(@NotNull final IRequestManager manager, @NotNull final IRequest<?> request) throws RuntimeException {
    final IColony colony = manager.getColony();
    if (colony instanceof Colony) {
        if (MinecoloniesAPIProxy.getInstance().getConfig().getServer().creativeResolve.get() && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getId()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getId()).get() instanceof AbstractBuilding) {
            final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getId()).get();
            final Optional<ICitizenData> citizenDataOptional = building.getCitizenForRequest(request.getId());
            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(citizenDataOptional.get().getInventory(), resolveStack);
                if (ItemStackUtils.isEmpty(remainingItemStack)) {
                    manager.updateRequestState(request.getId(), RequestState.RESOLVED);
                    return;
                }
            }
        }
    }
    assignedRequests.add(request.getId());
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IColony(com.minecolonies.api.colony.IColony) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 44 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class AbstractWorkOrder method read.

/**
 * Read the WorkOrder data from the CompoundNBT.
 *
 * @param compound NBT Tag compound
 * @param manager  the workManager calling this method.
 */
@Override
public void read(@NotNull final CompoundNBT compound, final IWorkManager manager) {
    // TODO: In 1.19 remove this method call as this is purely for backwards compatibility with old class mappings
    migrateOldNbt(compound, manager);
    id = compound.getInt(TAG_ID);
    if (compound.contains(TAG_TH_PRIORITY)) {
        priority = compound.getInt(TAG_TH_PRIORITY);
    }
    if (compound.contains(TAG_CLAIMED_BY)) {
        final int citizenId = compound.getInt(TAG_CLAIMED_BY);
        if (manager.getColony() != null) {
            final ICitizenData data = manager.getColony().getCitizenManager().getCivilian(citizenId);
            if (data != null && data.getWorkBuilding() != null) {
                claimedBy = data.getWorkBuilding().getPosition();
            }
        }
    } else if (compound.contains(TAG_CLAIMED_BY_BUILDING)) {
        claimedBy = BlockPosUtil.read(compound, TAG_CLAIMED_BY_BUILDING);
    }
    structureName = compound.getString(TAG_STRUCTURE_NAME);
    workOrderName = compound.getString(TAG_WO_NAME);
    workOrderType = WorkOrderType.values()[compound.getInt(TAG_WO_TYPE)];
    location = BlockPosUtil.read(compound, TAG_LOCATION);
    rotation = compound.getInt(TAG_ROTATION);
    isMirrored = compound.getBoolean(TAG_IS_MIRRORED);
    currentLevel = compound.getInt(TAG_CURRENT_LEVEL);
    targetLevel = compound.getInt(TAG_TARGET_LEVEL);
    amountOfResources = compound.getInt(TAG_AMOUNT_OF_RESOURCES);
    iteratorType = compound.getString(TAG_ITERATOR);
    cleared = compound.getBoolean(TAG_IS_CLEARED);
    requested = compound.getBoolean(TAG_IS_REQUESTED);
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 45 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class DeliverymenRequestResolver method attemptResolveRequest.

@Nullable
@Override
public List<IToken<?>> attemptResolveRequest(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request) {
    if (manager.getColony().getWorld().isClientSide) {
        return null;
    }
    ICitizenData chosenCourier = null;
    Tuple<Double, Integer> bestScore = null;
    for (final ICitizenData citizen : getResolveAbleDeliverymen(manager)) {
        if (citizen.isWorking()) {
            Tuple<Double, Integer> localScore = ((JobDeliveryman) citizen.getJob()).getScoreForDelivery(request);
            if (bestScore == null || localScore.getA() < bestScore.getA()) {
                bestScore = localScore;
                chosenCourier = citizen;
            }
        }
    }
    if (chosenCourier == null) {
        return null;
    }
    return Lists.newArrayList();
}
Also used : JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) ICitizenData(com.minecolonies.api.colony.ICitizenData) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12