use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method loadStructure.
/**
* Load the struction into the AI.
*/
private void loadStructure() {
WorkOrderBuildDecoration workOrder = null;
workOrder = job.getWorkOrder();
if (workOrder == null) {
return;
}
final BlockPos pos = workOrder.getBuildingLocation();
if (workOrder instanceof WorkOrderBuild && worker.getColony().getBuilding(pos) == null) {
Log.getLogger().warn("AbstractBuilding does not exist - removing build request");
worker.getColony().getWorkManager().removeWorkOrder(workOrder);
return;
}
final int tempRotation = workOrder.getRotation(world);
loadStructure(workOrder.getStructureName(), tempRotation, pos, workOrder.isMirrored());
workOrder.setCleared(false);
workOrder.setRequested(false);
//We need to deal with materials
requestMaterialsIfRequired();
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method initiate.
private void initiate() {
if (!job.hasStructure()) {
workFrom = null;
loadStructure();
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Starting and missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
return;
}
if (wo instanceof WorkOrderBuild) {
final AbstractBuilding building = job.getColony().getBuilding(wo.getBuildingLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Starting and missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), wo.getBuildingLocation()));
return;
}
worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, job.getStructure().getName());
//Don't go through the CLEAR stage for repairs and upgrades
if (building.getBuildingLevel() > 0) {
wo.setCleared(true);
}
} else {
worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, wo.getName());
}
}
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method checkIfExecute.
private boolean checkIfExecute() {
setDelay(1);
if (!job.hasWorkOrder()) {
return true;
}
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (job.getColony().getBuilding(wo.getBuildingLocation()) == null && wo instanceof WorkOrderBuild) {
job.complete();
return true;
}
if (!job.hasStructure()) {
initiate();
}
return false;
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method executeSpecificCompleteActions.
@Override
public void executeSpecificCompleteActions() {
if (job.getStructure() == null && job.hasWorkOrder()) {
//fix for bad structures
job.complete();
}
if (job.getStructure() == null) {
return;
}
final String structureName = job.getStructure().getName();
worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDCOMPLETE, structureName);
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
} else {
final WorkOrderBuild woh = (wo instanceof WorkOrderBuild) ? (WorkOrderBuild) wo : null;
if (woh == null && structureName.contains(WAYPOINT_STRING)) {
worker.getColony().addWayPoint(wo.getBuildingLocation(), world.getBlockState(wo.getBuildingLocation()));
} else if (woh != null) {
final AbstractBuilding building = job.getColony().getBuilding(wo.getBuildingLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), woh.getBuildingLocation()));
} else {
building.setBuildingLevel(woh.getUpgradeLevel());
}
}
job.complete();
}
final BuildingBuilder workerBuilding = (BuildingBuilder) getOwnBuilding();
workerBuilding.resetNeededResources();
resetTask();
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration in project minecolonies by Minecolonies.
the class Structures method canStoreNewSchematic.
/**
* check that we can store the schematic.
* According to the total number of schematic allowed on the server
*
* @return true if we can store more schematics
*/
private static boolean canStoreNewSchematic() {
if (MineColonies.isClient()) {
return true;
}
if (!Configurations.allowPlayerSchematics) {
return false;
}
final Set<String> md5Set = getCachedMD5s();
if (md5Set.size() < Configurations.maxCachedSchematics) {
return true;
}
int countInUseStructures = 0;
for (final Colony c : ColonyManager.getColonies()) {
for (final AbstractWorkOrder workOrder : c.getWorkManager().getWorkOrders().values()) {
if (workOrder instanceof WorkOrderBuildDecoration) {
final String schematicName = ((WorkOrderBuildDecoration) workOrder).getStructureName();
if (md5Set.contains(schematicName)) {
md5Set.remove(schematicName);
countInUseStructures++;
}
}
}
}
//md5Set containd only the unused one
final Iterator<String> iterator = md5Set.iterator();
while (iterator.hasNext() && md5Set.size() + countInUseStructures >= Configurations.maxCachedSchematics) {
final StructureName sn = new StructureName(iterator.next());
if (deleteCachedStructure(sn)) {
iterator.remove();
}
}
return md5Set.size() + countInUseStructures < Configurations.maxCachedSchematics;
}
Aggregations