Search in sources :

Example 21 with IWorkOrder

use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.

the class WorkManager method addWorkOrder.

/**
 * Adds work order to the work manager.
 *
 * @param order          Order adding.
 * @param readingFromNbt if being read from NBT.
 */
@Override
public void addWorkOrder(@NotNull final IWorkOrder order, final boolean readingFromNbt) {
    dirty = true;
    if (!(order instanceof WorkOrderMiner)) {
        for (final IWorkOrder or : workOrders.values()) {
            if (or.getLocation().equals(order.getLocation()) && or.getStructureName().equals(order.getStructureName())) {
                Log.getLogger().warn("Avoiding adding duplicate workOrder");
                removeWorkOrder(or);
                break;
            }
        }
        if (!readingFromNbt && !isWorkOrderWithinColony(order)) {
            MessageUtils.format(OUT_OF_COLONY, order.getDisplayName(), order.getLocation().getX(), order.getLocation().getZ()).sendTo(colony).forAllPlayers();
            return;
        }
    }
    if (order.getID() == 0) {
        topWorkOrderId++;
        order.setID(topWorkOrderId);
    }
    if (!readingFromNbt) {
        final StructureName structureName = new StructureName(order.getStructureName());
        if (order instanceof WorkOrderBuilding) {
            final int level = order.getTargetLevel();
            AdvancementUtils.TriggerAdvancementPlayersForColony(colony, player -> AdvancementTriggers.CREATE_BUILD_REQUEST.trigger(player, structureName, level));
        } else if (order instanceof WorkOrderDecoration) {
            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) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) CompoundNBT(net.minecraft.nbt.CompoundNBT) CLOSE_COLONY_CAP(com.minecolonies.coremod.MineColonies.CLOSE_COLONY_CAP) ICitizenData(com.minecolonies.api.colony.ICitizenData) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) Log(com.minecolonies.api.util.Log) ListNBT(net.minecraft.nbt.ListNBT) MessageUtils(com.minecolonies.api.util.MessageUtils) StructureName(com.ldtteam.structurize.management.StructureName) Colony(com.minecolonies.coremod.colony.Colony) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability) Tuple(net.minecraft.util.Tuple) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) NBT(net.minecraftforge.common.util.Constants.NBT) IColony(com.minecolonies.api.colony.IColony) OUT_OF_COLONY(com.minecolonies.api.util.constant.TranslationConstants.OUT_OF_COLONY) NotNull(org.jetbrains.annotations.NotNull) IWorkManager(com.minecolonies.api.colony.workorders.IWorkManager) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) StructureName(com.ldtteam.structurize.management.StructureName)

Example 22 with IWorkOrder

use of com.minecolonies.api.colony.workorders.IWorkOrder 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
 */
@Override
public void removeWorkOrder(final int orderId) {
    final IWorkOrder workOrder = workOrders.get(orderId);
    if (workOrder != null) {
        workOrders.remove(orderId);
        colony.removeWorkOrderInView(orderId);
        workOrder.onRemoved(colony);
        colony.markDirty();
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder)

Example 23 with IWorkOrder

use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.

the class WorkManager method onColonyTick.

/**
 * Process updates on the Colony Tick. Currently, does periodic Work Order cleanup.
 *
 * @param colony the colony being ticked.
 */
@Override
public void onColonyTick(@NotNull final IColony colony) {
    @NotNull final Iterator<IWorkOrder> iter = workOrders.values().iterator();
    while (iter.hasNext()) {
        final IWorkOrder o = iter.next();
        if (!o.isValid(this.colony)) {
            iter.remove();
            dirty = true;
        } else if (o.isDirty()) {
            dirty = true;
            o.resetChange();
        }
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with IWorkOrder

use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by Minecolonies.

the class DecorationBuildRequestMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
    if (colony == null) {
        return;
    }
    final PlayerEntity player = ctxIn.getSender();
    // Verify player has permission to change this hut its settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
    if (entity instanceof TileEntityDecorationController) {
        final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderDecoration).filter(entry -> entry.getValue().getLocation().equals(pos)).findFirst();
        if (wo.isPresent()) {
            colony.getWorkManager().removeWorkOrder(wo.get().getKey());
            return;
        }
        int difference = 0;
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof BlockDecorationController)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
                    return;
                }
                final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    difference = worldRotation - structureRotation;
                } else {
                    difference = 4 + worldRotation - structureRotation;
                }
            }
        }
        final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
        final int currentLevel = ((TileEntityDecorationController) entity).getTier();
        WorkOrderDecoration order;
        if (level > currentLevel) {
            order = WorkOrderDecoration.create(WorkOrderType.UPGRADE, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
        } else if (level == currentLevel) {
            order = WorkOrderDecoration.create(WorkOrderType.REPAIR, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
        } else {
            order = WorkOrderDecoration.create(WorkOrderType.BUILD, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
        }
        colony.getWorkManager().addWorkOrder(order, false);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WordUtils(org.apache.commons.lang3.text.WordUtils) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) WorkOrderType(com.minecolonies.api.colony.workorders.WorkOrderType) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler)

Example 25 with IWorkOrder

use of com.minecolonies.api.colony.workorders.IWorkOrder in project minecolonies by ldtteam.

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)

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