Search in sources :

Example 6 with AbstractAssignedCitizenModule

use of com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule in project minecolonies by ldtteam.

the class CitizenManager method removeCivilian.

@Override
public void removeCivilian(@NotNull final ICivilianData citizen) {
    if (!(citizen instanceof ICitizenData)) {
        return;
    }
    // Remove the Citizen
    citizens.remove(citizen.getId());
    for (@NotNull final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
        for (final AbstractAssignedCitizenModule assignedCitizenModule : building.getModules(AbstractAssignedCitizenModule.class)) {
            assignedCitizenModule.removeCitizen((ICitizenData) citizen);
        }
    }
    colony.getWorkManager().clearWorkForCitizen((ICitizenData) citizen);
    // Inform Subscribers of removed citizen
    for (final ServerPlayerEntity player : colony.getPackageManager().getCloseSubscribers()) {
        Network.getNetwork().sendToPlayer(new ColonyViewRemoveCitizenMessage(colony, citizen.getId()), player);
    }
    calculateMaxCitizens();
    markDirty();
    colony.markDirty();
}
Also used : ColonyViewRemoveCitizenMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveCitizenMessage) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AbstractAssignedCitizenModule

use of com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule in project minecolonies by ldtteam.

the class StationRequestResolver method canResolveForBuilding.

@Override
public boolean canResolveForBuilding(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends IDeliverable> request, @NotNull final AbstractBuilding building) {
    if (building instanceof BuildingWareHouse || building.getCitizenForRequest(request.getId()).isPresent() || building.hasModule(WorkerBuildingModule.class) || !building.hasModule(AbstractAssignedCitizenModule.class)) {
        return false;
    }
    boolean foundMatch = false;
    for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
        for (final ICitizenData citizen : module.getAssignedCitizen()) {
            if (citizen.getWorkBuilding() != null && citizen.getWorkBuilding().getCitizenForRequest(request.getId()).isPresent()) {
                foundMatch = true;
                break;
            }
        }
    }
    if (!foundMatch) {
        return false;
    }
    final Predicate<ItemStack> pred = itemStack -> {
        if (ItemStackUtils.isEmpty(itemStack) || !request.getRequest().matches(itemStack)) {
            return false;
        }
        if (!request.hasParent()) {
            return true;
        }
        final IRequest<?> requestParent = manager.getRequestForToken(request.getParent());
        return !requestParent.getRequestOfType(IDeliverable.class).map(d -> d.matches(itemStack)).orElse(false);
    };
    return InventoryUtils.getCountFromBuilding(building, pred) > 0;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) java.util(java.util) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) Predicate(java.util.function.Predicate) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) ItemStack(net.minecraft.item.ItemStack) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) InventoryUtils(com.minecolonies.api.util.InventoryUtils) NotNull(org.jetbrains.annotations.NotNull) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 8 with AbstractAssignedCitizenModule

use of com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule in project minecolonies by ldtteam.

the class AssignUnassignMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final DefaultBuildingInstance building) {
    final ICitizenData citizen = colony.getCitizenManager().getCivilian(citizenID);
    final AbstractAssignedCitizenModule module;
    if (jobEntry == null) {
        module = building.getFirstModuleOccurance(LivingBuildingModule.class);
    } else {
        module = building.getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == jobEntry);
    }
    if (assign && !module.isFull() && !building.equals(citizen.getHomeBuilding())) {
        if (citizen.getHomeBuilding() != null) {
            citizen.getHomeBuilding().getFirstModuleOccurance(LivingBuildingModule.class).removeCitizen(citizen);
        }
        module.assignCitizen(citizen);
    } else if (module.hasAssignedCitizen(citizen)) {
        module.removeCitizen(citizen);
    }
}
Also used : DefaultBuildingInstance(com.minecolonies.coremod.colony.buildings.DefaultBuildingInstance) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) AbstractBuildingServerMessage(com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IColony(com.minecolonies.api.colony.IColony) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)8 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)8 NotNull (org.jetbrains.annotations.NotNull)8 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)4 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)4 IColony (com.minecolonies.api.colony.IColony)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)2 InventoryUtils (com.minecolonies.api.util.InventoryUtils)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 DefaultBuildingInstance (com.minecolonies.coremod.colony.buildings.DefaultBuildingInstance)2 LivingBuildingModule (com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule)2 BuildingWareHouse (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)2 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)2