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();
}
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;
}
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);
}
}
Aggregations