use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by Minecolonies.
the class AbstractBuilding method removeWorkOrder.
/**
* Remove the work order for the building.
* <p>
* Remove either the upgrade or repair work order
*/
@Override
public void removeWorkOrder() {
for (@NotNull final WorkOrderBuild o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuild.class)) {
if (o.getSchematicLocation().equals(getID()) && (o instanceof WorkOrderBuildBuilding || o instanceof WorkOrderBuildRemoval)) {
colony.getWorkManager().removeWorkOrder(o.getID());
markDirty();
final BlockPos buildingPos = o.getClaimedBy();
final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
if (building != null) {
for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
for (final ICitizenData citizen : module.getAssignedCitizen()) {
building.cancelAllRequestsOfCitizen(citizen);
}
}
}
return;
}
}
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by Minecolonies.
the class BuildingBuilder method searchWorkOrder.
@Override
public void searchWorkOrder() {
final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
if (citizen == null) {
return;
}
final List<WorkOrderBuildDecoration> list = new ArrayList<>();
list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildRemoval.class, getPosition()));
// WorkOrderBuildDecoration is the superclass of BuildBuilding and thus returns both
list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildDecoration.class, getPosition()));
list.removeIf(order -> order instanceof WorkOrderBuildMiner);
final WorkOrderBuildDecoration order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getPosition())).findFirst().orElse(null);
if (order != null) {
citizen.getJob(JobBuilder.class).setWorkOrder(order);
order.setClaimedBy(citizen);
return;
}
if (getManualMode()) {
return;
}
for (final WorkOrderBuildDecoration wo : list) {
double distanceToBuilder = Double.MAX_VALUE;
if (wo instanceof WorkOrderBuild && !(wo instanceof WorkOrderBuildRemoval) && !((WorkOrderBuild) wo).canBuild(citizen)) {
continue;
}
for (@NotNull final ICitizenData otherBuilder : getColony().getCitizenManager().getCitizens()) {
final JobBuilder job = otherBuilder.getJob(JobBuilder.class);
if (job == null || otherBuilder.getWorkBuilding() == null || citizen.getId() == otherBuilder.getId()) {
continue;
}
if (!job.hasWorkOrder() && wo instanceof WorkOrderBuild && ((WorkOrderBuild) wo).canBuild(otherBuilder)) {
final double distance = otherBuilder.getWorkBuilding().getID().distSqr(wo.getSchematicLocation());
if (distance < distanceToBuilder) {
distanceToBuilder = distance;
}
}
}
if (citizen.getWorkBuilding().getID().distSqr(wo.getSchematicLocation()) < distanceToBuilder) {
citizen.getJob(JobBuilder.class).setWorkOrder(wo);
wo.setClaimedBy(citizen);
return;
}
}
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by ldtteam.
the class AbstractBuilding method removeWorkOrder.
/**
* Remove the work order for the building.
* <p>
* Remove either the upgrade or repair work order
*/
@Override
public void removeWorkOrder() {
for (@NotNull final WorkOrderBuild o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuild.class)) {
if (o.getSchematicLocation().equals(getID()) && (o instanceof WorkOrderBuildBuilding || o instanceof WorkOrderBuildRemoval)) {
colony.getWorkManager().removeWorkOrder(o.getID());
markDirty();
final BlockPos buildingPos = o.getClaimedBy();
final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
if (building != null) {
for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
for (final ICitizenData citizen : module.getAssignedCitizen()) {
building.cancelAllRequestsOfCitizen(citizen);
}
}
}
return;
}
}
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by ldtteam.
the class AbstractBuilding method requestWorkOrder.
/**
* Adds work orders to the {@link Colony#getWorkManager()}.
*
* @param level Desired level.
* @param builder the assigned builder.
*/
protected void requestWorkOrder(final int level, final BlockPos builder, final boolean removal) {
for (@NotNull final WorkOrderBuildBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuildBuilding.class)) {
if (o.getSchematicLocation().equals(getID())) {
return;
}
}
WorkOrderBuild workOrder;
if (removal) {
if (!canDeconstruct()) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.cantdeconstruct");
return;
}
workOrder = new WorkOrderBuildRemoval(this, level);
} else {
workOrder = new WorkOrderBuildBuilding(this, level);
}
if (!removal && !canBeBuiltByBuilder(level) && !workOrder.canBeResolved(colony, level)) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildernecessary", Integer.toString(level));
return;
}
if (workOrder.tooFarFromAnyBuilder(colony, level) && builder.equals(BlockPos.ZERO)) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuilderstoofar");
return;
}
if (getCorners().getA().getY() >= MAX_BUILD_HEIGHT || getCorners().getB().getY() >= MAX_BUILD_HEIGHT) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildtoohigh");
return;
} else if (getPosition().getY() <= MIN_BUILD_HEIGHT) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildtoolow");
return;
}
if (!builder.equals(BlockPos.ZERO)) {
final IBuilding building = colony.getBuildingManager().getBuilding(builder);
if (building instanceof AbstractBuildingStructureBuilder && (building.getBuildingLevel() >= level || canBeBuiltByBuilder(level))) {
workOrder.setClaimedBy(builder);
} else {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildernecessary", Integer.toString(level));
return;
}
}
colony.getWorkManager().addWorkOrder(workOrder, false);
colony.getProgressManager().progressWorkOrderPlacement(workOrder);
if (workOrder.getID() != 0) {
LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.workorderadded", workOrder.getDisplayName(), colony.getName(), workOrder.getSchematicLocation().getX(), workOrder.getSchematicLocation().getY(), workOrder.getSchematicLocation().getZ());
}
markDirty();
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by ldtteam.
the class BuildingBuilder method searchWorkOrder.
@Override
public void searchWorkOrder() {
final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
if (citizen == null) {
return;
}
final List<WorkOrderBuildDecoration> list = new ArrayList<>();
list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildRemoval.class, getPosition()));
// WorkOrderBuildDecoration is the superclass of BuildBuilding and thus returns both
list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildDecoration.class, getPosition()));
list.removeIf(order -> order instanceof WorkOrderBuildMiner);
final WorkOrderBuildDecoration order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getPosition())).findFirst().orElse(null);
if (order != null) {
citizen.getJob(JobBuilder.class).setWorkOrder(order);
order.setClaimedBy(citizen);
return;
}
if (getManualMode()) {
return;
}
for (final WorkOrderBuildDecoration wo : list) {
double distanceToBuilder = Double.MAX_VALUE;
if (wo instanceof WorkOrderBuild && !(wo instanceof WorkOrderBuildRemoval) && !((WorkOrderBuild) wo).canBuild(citizen)) {
continue;
}
for (@NotNull final ICitizenData otherBuilder : getColony().getCitizenManager().getCitizens()) {
final JobBuilder job = otherBuilder.getJob(JobBuilder.class);
if (job == null || otherBuilder.getWorkBuilding() == null || citizen.getId() == otherBuilder.getId()) {
continue;
}
if (!job.hasWorkOrder() && wo instanceof WorkOrderBuild && ((WorkOrderBuild) wo).canBuild(otherBuilder)) {
final double distance = otherBuilder.getWorkBuilding().getID().distSqr(wo.getSchematicLocation());
if (distance < distanceToBuilder) {
distanceToBuilder = distance;
}
}
}
if (citizen.getWorkBuilding().getID().distSqr(wo.getSchematicLocation()) < distanceToBuilder) {
citizen.getJob(JobBuilder.class).setWorkOrder(wo);
wo.setClaimedBy(citizen);
return;
}
}
}
Aggregations