Search in sources :

Example 1 with AbstractWorkOrder

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

the class WorkManager method writeToNBT.

/**
 * Save the Work Manager.
 *
 * @param compound Compound to save to.
 */
public void writeToNBT(@NotNull final NBTTagCompound compound) {
    // Work Orders
    @NotNull final NBTTagList list = new NBTTagList();
    for (@NotNull final AbstractWorkOrder o : workOrders.values()) {
        @NotNull final NBTTagCompound orderCompound = new NBTTagCompound();
        o.writeToNBT(orderCompound);
        list.appendTag(orderCompound);
    }
    compound.setTag(TAG_WORK_ORDERS, list);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AbstractWorkOrder

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

the class WorkManager method removeWorkOrder.

/**
 * Removes a work order from the work manager.
 *
 * @param orderId ID of the order to remove
 */
public void removeWorkOrder(final int orderId) {
    final AbstractWorkOrder workOrder = workOrders.get(orderId);
    workOrders.remove(orderId);
    colony.removeWorkOrderInView(orderId);
    workOrder.onRemoved(colony);
    colony.markDirty();
}
Also used : AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder)

Example 3 with AbstractWorkOrder

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

the class WorkManager method onWorldTick.

/**
 * Process updates on the World Tick.
 * Currently, does periodic Work Order cleanup.
 *
 * @param event {@link net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent}.
 */
public void onWorldTick(@NotNull final TickEvent.WorldTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        @NotNull final Iterator<AbstractWorkOrder> iter = workOrders.values().iterator();
        while (iter.hasNext()) {
            final AbstractWorkOrder o = iter.next();
            if (!o.isValid(colony)) {
                iter.remove();
                dirty = true;
            } else if (o.hasChanged()) {
                dirty = true;
                o.resetChange();
            }
        }
        if ((event.world.getWorldTime() % WORK_ORDER_FULFILL_INCREMENT) == 0) {
            workOrders.values().stream().filter(o -> !o.isClaimed()).sorted(Comparator.comparingInt(AbstractWorkOrder::getPriority).reversed()).forEach(o -> o.attemptToFulfill(colony));
        }
    }
}
Also used : AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with AbstractWorkOrder

use of com.minecolonies.coremod.colony.workorders.AbstractWorkOrder 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.gameplay.allowPlayerSchematics) {
        return false;
    }
    final Set<String> md5Set = getCachedMD5s();
    if (md5Set.size() < Configurations.gameplay.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.gameplay.maxCachedSchematics) {
        final StructureName sn = new StructureName(iterator.next());
        if (deleteCachedStructure(sn)) {
            iterator.remove();
        }
    }
    return md5Set.size() + countInUseStructures < Configurations.gameplay.maxCachedSchematics;
}
Also used : AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 5 with AbstractWorkOrder

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

the class WorkManager method readFromNBT.

/**
 * Restore the Work Manager.
 *
 * @param compound Compound to read from.
 */
public void readFromNBT(@NotNull final NBTTagCompound compound) {
    // Work Orders
    final NBTTagList list = compound.getTagList(TAG_WORK_ORDERS, NBT.TAG_COMPOUND);
    for (int i = 0; i < list.tagCount(); ++i) {
        final NBTTagCompound orderCompound = list.getCompoundTagAt(i);
        @Nullable final AbstractWorkOrder o = AbstractWorkOrder.createFromNBT(orderCompound);
        if (o != null) {
            addWorkOrder(o, true);
            // This is just a failsafe cleanup; this should not happen under normal circumstances
            if (o.isClaimed() && colony.getCitizenManager().getCitizen(o.getClaimedBy()) == null) {
                o.clearClaimedBy();
            }
            topWorkOrderId = Math.max(topWorkOrderId, o.getID());
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AbstractWorkOrder (com.minecolonies.coremod.colony.workorders.AbstractWorkOrder)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 NotNull (org.jetbrains.annotations.NotNull)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)1 Nullable (org.jetbrains.annotations.Nullable)1