Search in sources :

Example 1 with WorkOrderBuildMiner

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner in project minecolonies by Minecolonies.

the class MinerLevelManagementModule method serializeToView.

@Override
public void serializeToView(final PacketBuffer buf) {
    buf.writeInt(currentLevel);
    buf.writeInt(levels.size());
    for (@NotNull final Level level : levels) {
        buf.writeInt(level.getNumberOfBuiltNodes());
        buf.writeInt(level.getDepth());
    }
    final List<WorkOrderBuildMiner> list = building.getColony().getWorkManager().getOrderedList(WorkOrderBuildMiner.class, building.getPosition());
    buf.writeInt(list.size());
    for (@NotNull final WorkOrderBuildMiner wo : list) {
        wo.serializeViewNetworkData(buf);
    }
}
Also used : Level(com.minecolonies.coremod.entity.ai.citizen.miner.Level) NotNull(org.jetbrains.annotations.NotNull) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner)

Example 2 with WorkOrderBuildMiner

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner 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<>();
        for (final IWorkOrder workOrder : workManager.getWorkOrders().values()) {
            if (!(workOrder instanceof WorkOrderBuildMiner)) {
                workOrders.add(workOrder);
            }
        }
        players.forEach(player -> Network.getNetwork().sendToPlayer(new ColonyViewWorkOrderMessage(colony, workOrders), player));
        workManager.setDirty(false);
    }
}
Also used : IWorkManager(com.minecolonies.api.colony.workorders.IWorkManager) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) ArrayList(java.util.ArrayList) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewWorkOrderMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewWorkOrderMessage) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner) HashSet(java.util.HashSet)

Example 3 with WorkOrderBuildMiner

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner 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;
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ArrayList(java.util.ArrayList) JobBuilder(com.minecolonies.coremod.colony.jobs.JobBuilder) ICitizenData(com.minecolonies.api.colony.ICitizenData) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) NotNull(org.jetbrains.annotations.NotNull) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 4 with WorkOrderBuildMiner

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner in project minecolonies by Minecolonies.

the class BuildingMiner method initStructure.

/**
 * Initiates structure loading.
 *
 * @param mineNode     the node to load it for.
 * @param rotateTimes  The amount of time to rotate the structure.
 * @param structurePos The position of the structure.
 */
public static void initStructure(final Node mineNode, final int rotateTimes, final BlockPos structurePos, final BuildingMiner buildingMiner, final World world, final JobMiner job) {
    final String style = buildingMiner.getStyle();
    String requiredName = null;
    int rotateCount = 0;
    if (mineNode == null) {
        rotateCount = getRotationFromVector(buildingMiner);
        requiredName = getCorrectStyleLocation(style, Node.NodeType.SHAFT.getSchematicName(), world, buildingMiner);
    } else {
        rotateCount = rotateTimes;
        requiredName = getCorrectStyleLocation(style, mineNode.getStyle().getSchematicName(), world, buildingMiner);
    }
    if (requiredName != null && (job == null || job.getWorkOrder() == null)) {
        final WorkOrderBuildMiner wo = new WorkOrderBuildMiner(requiredName, requiredName, rotateCount, structurePos, false, buildingMiner.getPosition());
        wo.setClaimedBy(buildingMiner.getPosition());
        buildingMiner.getColony().getWorkManager().addWorkOrder(wo, false);
        if (job != null) {
            job.setWorkOrder(wo);
        } else {
            wo.setClaimedBy(buildingMiner.getPosition());
        }
    }
    buildingMiner.markDirty();
}
Also used : WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner)

Example 5 with WorkOrderBuildMiner

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner in project minecolonies by Minecolonies.

the class EntityAIQuarrier method loadRequirements.

@Override
public IAIState loadRequirements() {
    if (job.getWorkOrder() == null) {
        final IBuilding quarry = job.findQuarry();
        if (quarry == null || quarry.getFirstModuleOccurance(QuarryModule.class).isFinished()) {
            return IDLE;
        }
        final String name = Structures.SCHEMATICS_PREFIX + "/" + quarry.getStyle() + "/" + quarry.getSchematicName() + "shaft1";
        final WorkOrderBuildMiner wo = new WorkOrderBuildMiner(name, name, quarry.getRotation(), quarry.getPosition().below(2), false, getOwnBuilding().getPosition());
        getOwnBuilding().getColony().getWorkManager().addWorkOrder(wo, false);
        job.setWorkOrder(wo);
    }
    return super.loadRequirements();
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner)

Aggregations

WorkOrderBuildMiner (com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner)12 ICitizenData (com.minecolonies.api.colony.ICitizenData)4 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IWorkManager (com.minecolonies.api.colony.workorders.IWorkManager)2 IWorkOrder (com.minecolonies.api.colony.workorders.IWorkOrder)2 JobBuilder (com.minecolonies.coremod.colony.jobs.JobBuilder)2 JobMiner (com.minecolonies.coremod.colony.jobs.JobMiner)2 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)2 WorkOrderBuildRemoval (com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval)2 Level (com.minecolonies.coremod.entity.ai.citizen.miner.Level)2 ColonyViewWorkOrderMessage (com.minecolonies.coremod.network.messages.client.colony.ColonyViewWorkOrderMessage)2 HashSet (java.util.HashSet)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2