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);
}
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();
}
}
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();
}
}
}
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);
}
}
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);
}
}
Aggregations