use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.
the class WorkManager method write.
/**
* Save the Work Manager.
*
* @param compound Compound to save to.
*/
@Override
public void write(@NotNull final CompoundNBT compound) {
// Work Orders
@NotNull final ListNBT list = new ListNBT();
for (@NotNull final IWorkOrder o : workOrders.values()) {
@NotNull final CompoundNBT orderCompound = new CompoundNBT();
o.write(orderCompound);
list.add(orderCompound);
}
compound.put(TAG_WORK_ORDERS, list);
}
use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.
the class AbstractEntityAIStructureWithWorkOrder method loadRequirements.
/**
* Takes the existing workorder, loads the structure and tests the worker order if it is valid.
*/
@Override
public IAIState loadRequirements() {
if (!job.hasBlueprint() || structurePlacer == null) {
loadStructure();
final IWorkOrder wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Starting and missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()), new Exception());
job.setWorkOrder(null);
return IDLE;
}
if (wo instanceof WorkOrderBuilding) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getLocation());
if (building == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Starting and missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()), new Exception());
return IDLE;
}
worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START, job.getWorkOrder().getDisplayName());
// Don't go through the CLEAR stage for repairs and upgrades
if (building.getBuildingLevel() > 0) {
wo.setCleared(true);
}
} else if (!(wo instanceof WorkOrderMiner)) {
worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START, job.getWorkOrder().getDisplayName());
}
return getState();
}
if (job.getWorkOrder().isRequested()) {
return afterStructureLoading();
}
// We need to deal with materials
requestMaterialsState();
return getState();
}
use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.
the class AbstractEntityAIStructureWithWorkOrder method executeSpecificCompleteActions.
@Override
public void executeSpecificCompleteActions() {
if (job.getBlueprint() == null && job.hasWorkOrder()) {
// fix for bad structures
job.complete();
}
if (job.getBlueprint() == null) {
return;
}
final IWorkOrder wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
} else {
// TODO: Preferably want to use the display name of the building (in order to respect custom name) however this will require an event rework so it stores text components rather than strings
String workOrderName = wo.getWorkOrderName();
sendCompletionMessage(wo);
switch(wo.getWorkOrderType()) {
case BUILD:
job.getColony().getEventDescriptionManager().addEventDescription(new BuildingBuiltEvent(wo.getLocation(), workOrderName));
break;
case UPGRADE:
job.getColony().getEventDescriptionManager().addEventDescription(new BuildingUpgradedEvent(wo.getLocation(), workOrderName, wo.getTargetLevel()));
break;
case REPAIR:
job.getColony().getEventDescriptionManager().addEventDescription(new BuildingRepairedEvent(wo.getLocation(), workOrderName, wo.getCurrentLevel()));
break;
case REMOVE:
job.getColony().getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getLocation(), workOrderName, wo.getCurrentLevel()));
break;
}
job.complete();
if (wo instanceof WorkOrderBuilding) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getLocation());
switch(wo.getWorkOrderType()) {
case BUILD:
case UPGRADE:
case REPAIR:
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()));
} else {
// Normally levels are done through the schematic data, but in case it is missing we do it manually here.
final TileEntity te = worker.level.getBlockEntity(building.getID());
if (te instanceof AbstractTileEntityColonyBuilding && ((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
building.onUpgradeComplete(wo.getTargetLevel());
building.setBuildingLevel(wo.getTargetLevel());
}
}
break;
case REMOVE:
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()));
} else {
building.setDeconstructed();
}
break;
}
}
}
building.resetNeededResources();
}
use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.
the class BuildingResourcesModule method serializeToView.
/**
* Method to serialize data to send it to the view.
*
* @param buf the used ByteBuffer.
*/
@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
updateAvailableResources();
buf.writeInt(neededResources.size());
double qty = 0;
for (@NotNull final BuildingBuilderResource resource : neededResources.values()) {
buf.writeItem(resource.getItemStack());
buf.writeInt(resource.getAvailable());
buf.writeInt(resource.getAmount());
qty += resource.getAmount();
}
final Set<ICitizenData> set = building.getAllAssignedCitizen();
final ICitizenData data = set.isEmpty() ? null : set.iterator().next();
if (data != null && data.getJob() instanceof AbstractJobStructure) {
final AbstractJobStructure<?, ?> structureBuilderJob = (AbstractJobStructure<?, ?>) data.getJob();
final IWorkOrder workOrder = structureBuilderJob.getWorkOrder();
if (workOrder != null) {
buf.writeComponent(workOrder.getDisplayName());
buf.writeDouble(workOrder.getAmountOfResources() == 0 ? 0 : qty / workOrder.getAmountOfResources());
buf.writeInt(totalStages);
buf.writeInt(currentStage);
return;
}
}
buf.writeComponent(new StringTextComponent(""));
buf.writeDouble(0.0);
buf.writeInt(0);
buf.writeInt(0);
}
use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.
the class ColonyPackageManager method sendWorkOrderPackets.
@Override
public void sendWorkOrderPackets() {
final IWorkManager workManager = colony.getWorkManager();
if (workManager.isDirty() || !newSubscribers.isEmpty()) {
final Set<ServerPlayerEntity> players = new HashSet<>();
players.addAll(closeSubscribers);
players.addAll(newSubscribers);
List<IWorkOrder> workOrders = new ArrayList<>(workManager.getWorkOrders().values());
players.forEach(player -> Network.getNetwork().sendToPlayer(new ColonyViewWorkOrderMessage(colony, workOrders), player));
workManager.setDirty(false);
}
}
Aggregations