use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by ldtteam.
the class WorkManager method addWorkOrder.
/**
* Adds work order to the work manager.
*
* @param order Order to add.
* @param readingFromNbt if being read from NBT.
*/
@Override
public void addWorkOrder(@NotNull final IWorkOrder order, final boolean readingFromNbt) {
dirty = true;
if (order instanceof WorkOrderBuildDecoration && !(order instanceof WorkOrderBuildMiner)) {
for (final IWorkOrder or : workOrders.values()) {
if (or instanceof WorkOrderBuildDecoration) {
if (((WorkOrderBuildDecoration) or).getSchematicLocation().equals(((WorkOrderBuildDecoration) order).buildingLocation) && ((WorkOrderBuildDecoration) or).getStructureName().equals(((WorkOrderBuildDecoration) order).getStructureName())) {
Log.getLogger().warn("Avoiding adding duplicate workOrder");
removeWorkOrder(or);
break;
}
}
}
if (!readingFromNbt && !isWorkOrderWithinColony((WorkOrderBuildDecoration) order)) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), OUT_OF_COLONY, ((WorkOrderBuildDecoration) order).getName(), ((WorkOrderBuildDecoration) order).getSchematicLocation().getX(), ((WorkOrderBuildDecoration) order).getSchematicLocation().getZ());
return;
}
}
if (order.getID() == 0) {
topWorkOrderId++;
order.setID(topWorkOrderId);
}
if (order instanceof WorkOrderBuildDecoration && !readingFromNbt) {
final StructureName structureName = new StructureName(((WorkOrderBuildDecoration) order).getStructureName());
if (order instanceof WorkOrderBuildBuilding) {
final int level = ((WorkOrderBuildBuilding) order).getUpgradeLevel();
AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.CREATE_BUILD_REQUEST.trigger(player, structureName, level));
} else {
AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.CREATE_BUILD_REQUEST.trigger(player, structureName, 0));
}
}
workOrders.put(order.getID(), order);
order.onAdded(colony, readingFromNbt);
}
use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by ldtteam.
the class BuildingBuilder method setWorkOrder.
/**
* Sets the work order with the given id as the work order for this buildings citizen.
*
* @param orderId the id of the work order to select.
*/
public void setWorkOrder(int orderId) {
final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
if (citizen == null) {
return;
}
IWorkOrder wo = getColony().getWorkManager().getWorkOrder(orderId);
if (wo == null || (wo.getClaimedBy() != null && !wo.getClaimedBy().equals(getPosition()))) {
return;
}
if (citizen.getJob(JobBuilder.class).hasWorkOrder()) {
wo.setClaimedBy(citizen);
getColony().getWorkManager().setDirty(true);
return;
}
if (wo instanceof WorkOrderBuildDecoration) {
WorkOrderBuildDecoration bo = (WorkOrderBuildDecoration) wo;
citizen.getJob(JobBuilder.class).setWorkOrder(bo);
wo.setClaimedBy(citizen);
getColony().getWorkManager().setDirty(true);
markDirty();
}
}
Aggregations