Search in sources :

Example 1 with WorkOrderBuildDecoration

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();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) BlockPos(net.minecraft.util.math.BlockPos) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 2 with WorkOrderBuildDecoration

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());
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 3 with WorkOrderBuildDecoration

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;
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 4 with WorkOrderBuildDecoration

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();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) BuildingBuilder(com.minecolonies.coremod.colony.buildings.BuildingBuilder) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 5 with WorkOrderBuildDecoration

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;
}
Also used : AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Aggregations

WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)5 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)4 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 AbstractWorkOrder (com.minecolonies.coremod.colony.workorders.AbstractWorkOrder)1 BlockPos (net.minecraft.util.math.BlockPos)1