Search in sources :

Example 11 with IWorkOrder

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);
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) CompoundNBT(net.minecraft.nbt.CompoundNBT) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with IWorkOrder

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();
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WorkOrderMiner(com.minecolonies.coremod.colony.workorders.WorkOrderMiner) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Example 13 with IWorkOrder

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();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingRepairedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingRepairedEvent) BuildingDeconstructedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingDeconstructedEvent) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) BuildingBuiltEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingBuiltEvent) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BuildingUpgradedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingUpgradedEvent) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Example 14 with IWorkOrder

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);
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) ICitizenData(com.minecolonies.api.colony.ICitizenData) StringTextComponent(net.minecraft.util.text.StringTextComponent) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with IWorkOrder

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);
    }
}
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) HashSet(java.util.HashSet)

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