Search in sources :

Example 26 with IWorkOrder

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);
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) StructureName(com.ldtteam.structurize.management.StructureName)

Example 27 with IWorkOrder

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();
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) JobBuilder(com.minecolonies.coremod.colony.jobs.JobBuilder) ICitizenData(com.minecolonies.api.colony.ICitizenData) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Aggregations

IWorkOrder (com.minecolonies.api.colony.workorders.IWorkOrder)27 NotNull (org.jetbrains.annotations.NotNull)9 BlockPos (net.minecraft.util.math.BlockPos)7 ICitizenData (com.minecolonies.api.colony.ICitizenData)5 IColony (com.minecolonies.api.colony.IColony)5 WorkOrderBuilding (com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)5 Nullable (org.jetbrains.annotations.Nullable)5 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)3 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)3 IWorkManager (com.minecolonies.api.colony.workorders.IWorkManager)3 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)3 Log (com.minecolonies.api.util.Log)3 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)3 JobBuilder (com.minecolonies.coremod.colony.jobs.JobBuilder)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 ListNBT (net.minecraft.nbt.ListNBT)3 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)2 StructureName (com.ldtteam.structurize.management.StructureName)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 Action (com.minecolonies.api.colony.permissions.Action)2