XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

MyDimension

【Java】我的维度模组

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/MyDimension

重构蓝图与缺料任务预览及工作流管理

本次更新重构了蓝图和缺料任务的客户端预览与工作流管理,实现多层预览状态的独立管理,支持并行显示和操作。优化了 BuilderToolScreen 的工作流可视化与取消操作,提升 UI 清晰度和交互体验。细化了 resume 同步时机,避免预览闪烁。调整了渲染与交互细节,确保各层互不干扰。补充了多层预览和同步相关测试用例,提升代码可维护性和扩展性。

47599ba
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

14 个文件 +605 -99
Modified gradle.properties +1 -1
@@ -11,7 +11,7 @@ loader_version_range=[47,)
11 11 mod_id=mydimension
12 12 mod_name=\u6211\u7684\u7ef4\u5ea6
13 13 mod_license=CC0-1.0
14 mod_version=2.5.1
14 mod_version=2.5.2
15 15 mod_group_id=com.xfestudio.mydimension
16 16 maven_group=com.xfestudio
17 17 archives_base_name=mydimension
Modified src/main/java/com/xfestudio/mydimension/builder/blueprint/BlueprintTaskManager.java +6 -0
@@ -1,5 +1,6 @@
1 1 package com.xfestudio.mydimension.builder.blueprint;
2 2
3 import com.xfestudio.mydimension.builder.BuilderNetworkBridge;
3 4 import com.xfestudio.mydimension.builder.BuilderOperationManager;
4 5 import com.xfestudio.mydimension.builder.BuilderRuntime;
5 6 import com.xfestudio.mydimension.builder.PendingBuildData;
@@ -165,6 +166,7 @@ public final class BlueprintTaskManager {
165 166 // The executor has either compensated the entire unrecorded batch or left a
166 167 // CONFLICTED marker for manual recovery. Never advance into the next batch.
167 168 active.remove(player.getUUID());
169 BuilderNetworkBridge.sync(player);
168 170 return false;
169 171 }
170 172 if (!task.soundPlayed && result.sound() != null) {
@@ -201,6 +203,9 @@ public final class BlueprintTaskManager {
201 203 player.displayClientMessage(Component.translatable("message.mydimension.builder.blueprint_waiting",
202 204 task.missing.size()), true);
203 205 }
206 // This is the authoritative end of the pending -> active hand-off. A completed task clears
207 // the retained yellow preview; a still-missing task replaces it with the new remainder.
208 BuilderNetworkBridge.sync(player);
204 209 }
205 210
206 211 public boolean cancel(ServerPlayer player, ItemStack scepter) {
@@ -237,6 +242,7 @@ public final class BlueprintTaskManager {
237 242 task.transactionId, task.dimension, BuilderTransaction.Type.BLUEPRINT,
238 243 task.recordHistory, true,
239 244 task.soundPlayed, completed, total, remaining, System.currentTimeMillis()));
245 BuilderNetworkBridge.sync(player);
240 246 }
241 247
242 248 static int accumulatedCompleted(int completed, int changed) {
Modified src/main/java/com/xfestudio/mydimension/client/builder/BuilderClientEvents.java +0 -1
@@ -133,7 +133,6 @@ public final class BuilderClientEvents {
133 133 if (cancelTarget == null) return;
134 134 switch (cancelTarget) {
135 135 case DEPLOYMENT -> {
136 BuilderClientServices.send(new BuilderClientCommand.CancelBlueprint());
137 136 BuilderClientNetworkBridge.cancelPlacementPreview();
138 137 }
139 138 case SELECTION -> BuilderClientNetworkBridge.cancelSourceSelection();
Modified src/main/java/com/xfestudio/mydimension/client/builder/BuilderClientNetworkBridge.java +18 -35
@@ -193,20 +193,16 @@ public final class BuilderClientNetworkBridge implements BuilderClientBridge,
193 193 .map(cell -> new BuilderPreviewState.Cell(cell.pos(), cell.state(),
194 194 BuilderPreviewState.Kind.valueOf(cell.kind().name()), cell.ghost()))
195 195 .toList();
196 BuilderPreviewState.Snapshot current = BuilderPreviewState.get().snapshot();
197 BuilderPreviewState.Selection selection = BuilderPreviewState.mergeSelection(
198 dimension, packet.first(), packet.second(), current);
199 boolean cancelable = BuilderPreviewState.mergeCancelable(packet.cancelable(),
200 packet.blueprintPreview(), selection);
201 BuilderPreviewState.Snapshot incoming = new BuilderPreviewState.Snapshot(
202 dimension, cells, selection, packet.activeJobId(), packet.blueprintPreview(),
203 cancelable, packet.revision());
204 boolean emptyServerWorkflow = packet.cells().isEmpty() && packet.first() == null
205 && packet.second() == null && packet.activeJobId() == null
206 && !packet.blueprintPreview() && !packet.cancelable();
207 BuilderPreviewState.Snapshot merged = BuilderPreviewState.mergeServerSnapshot(
208 current, incoming, emptyServerWorkflow);
209 if (merged != current) BuilderPreviewState.get().accept(merged);
196 BuilderPreviewState state = BuilderPreviewState.get();
197 BuilderPreviewState.Snapshot current = state.snapshot();
198 UUID currentJobId = current == null ? null : current.activeJobId();
199 // Pending blueprint work is moved from SavedData into the active worker before this
200 // preview packet is built. The paired lightweight snapshot still carries its transaction
201 // id, so that brief empty packet is not a real completion and must not erase yellow cells.
202 boolean preserveTransientEmpty = cells.isEmpty() && packet.activeJobId() == null
203 && currentJobId != null && currentJobId.equals(snapshot.activeJobId());
204 state.updateMissingPreview(dimension, cells, packet.activeJobId(), packet.cancelable(),
205 packet.revision(), preserveTransientEmpty);
210 206 }
211 207
212 208 @Override
@@ -237,10 +233,11 @@ public final class BuilderClientNetworkBridge implements BuilderClientBridge,
237 233 selection = new BuilderPreviewState.Selection(dimension, target.blockPos(), null);
238 234 ModNetwork.CHANNEL.sendToServer(new BlueprintSelectionStartPacket(target.blockPos()));
239 235 }
240 int revision = current == null ? 1 : current.revision() + 1;
241 236 boolean complete = selection.first() != null && selection.second() != null;
242 BuilderPreviewState.get().accept(new BuilderPreviewState.Snapshot(dimension, List.of(), selection,
243 null, complete, true, revision));
237 // Completing a source cuboid does not itself create a movable deployment. That only becomes
238 // active after the validated capture download is available and refreshBlueprintPreview()
239 // has built its destination cells.
240 BuilderPreviewState.get().updateSelection(selection);
244 241 if (complete) {
245 242 requestSelectionCopy();
246 243 }
@@ -530,10 +527,8 @@ public final class BuilderClientNetworkBridge implements BuilderClientBridge,
530 527 anchor = hit.getBlockPos().relative(hit.getDirection()).offset(offset);
531 528 }
532 529 blueprintTargetMissTicks = 0;
533 BuilderPreviewState.Snapshot currentPreview = BuilderPreviewState.get().snapshot();
534 boolean currentGenerationIntact = currentPreview != null
535 && currentPreview.blueprintPreview()
536 && currentPreview.cells().size() == selectedBlueprint.blocks().size();
530 boolean currentGenerationIntact = BuilderPreviewState.get()
531 .hasCompleteDeploymentGeneration(selectedBlueprint.blocks().size());
537 532 if (!force && anchor.equals(lastPreviewAnchor) && currentGenerationIntact) return;
538 533 lastPreviewAnchor = anchor;
539 534 BlueprintPlacementPlan plan = BlueprintPlacementPlan.create(selectedBlueprint, transform, anchor);
@@ -548,23 +543,11 @@ public final class BuilderClientNetworkBridge implements BuilderClientBridge,
548 543 return new BuilderPreviewState.Cell(block.worldPos(), block.state(), kind,
549 544 kind == BuilderPreviewState.Kind.BUILD);
550 545 }).toList();
551 BuilderPreviewState.Snapshot old = BuilderPreviewState.get().snapshot();
552 int revision = old == null ? 1 : old.revision() + 1;
553 BuilderPreviewState.Selection selection = old == null
554 ? new BuilderPreviewState.Selection(minecraft.level.dimension(), null, null) : old.selection();
555 BuilderPreviewState.get().accept(new BuilderPreviewState.Snapshot(minecraft.level.dimension(), cells,
556 selection, null, true, true, revision));
546 BuilderPreviewState.get().updateDeploymentPreview(minecraft.level.dimension(), cells);
557 547 }
558 548
559 549 private static void clearBlueprintCells(Minecraft minecraft) {
560 BuilderPreviewState.Snapshot old = BuilderPreviewState.get().snapshot();
561 BuilderPreviewState.Selection selection = old == null
562 ? new BuilderPreviewState.Selection(minecraft.level.dimension(), null, null)
563 : old.selection();
564 int revision = old == null ? 1 : old.revision() + 1;
565 BuilderPreviewState.get().accept(new BuilderPreviewState.Snapshot(
566 minecraft.level.dimension(), List.of(), selection, null,
567 true, true, revision));
550 BuilderPreviewState.get().updateDeploymentPreview(minecraft.level.dimension(), List.of());
568 551 }
569 552
570 553 private void placeBlueprint(BuilderClientCommand.Target target) {
Modified src/main/java/com/xfestudio/mydimension/client/builder/BuilderPreviewRenderer.java +8 -2
@@ -268,7 +268,8 @@ public final class BuilderPreviewRenderer {
268 268 }
269 269 }
270 270
271 BuilderPreviewState.Selection selection = snapshot == null ? null : snapshot.selection();
271 BuilderPreviewState.Selection selection = snapshot == null || snapshot.blueprintPreview()
272 ? null : snapshot.selection();
272 273 if (selection != null && selection.active()) {
273 274 if (selection.first() != null) {
274 275 AABB bounds = new AABB(selection.first()).inflate(0.006D);
@@ -294,6 +295,8 @@ public final class BuilderPreviewRenderer {
294 295 }
295 296 }
296 297
298 // Follow the same fully published generation as the cached cell VBOs. Reading the newest
299 // state here would move the outer frame before its replacement geometry is ready.
297 300 AABB blueprintBounds = blueprintBounds(snapshot);
298 301 if (blueprintBounds != null && withinDistance(blueprintBounds, camera, maximumDistanceSqr)) {
299 302 BuilderPreviewGeometry.emitBox(pose, quads, blueprintBounds.inflate(0.004D),
@@ -340,6 +343,8 @@ public final class BuilderPreviewRenderer {
340 343 int maxY = Integer.MIN_VALUE;
341 344 int maxZ = Integer.MIN_VALUE;
342 345 for (BuilderPreviewState.Cell cell : snapshot.cells()) {
346 // Retained missing work never belongs to the deployment focus/frame volume.
347 if (cell.kind() == BuilderPreviewState.Kind.MISSING) continue;
343 348 minX = Math.min(minX, cell.pos().getX());
344 349 minY = Math.min(minY, cell.pos().getY());
345 350 minZ = Math.min(minZ, cell.pos().getZ());
@@ -347,7 +352,8 @@ public final class BuilderPreviewRenderer {
347 352 maxY = Math.max(maxY, cell.pos().getY());
348 353 maxZ = Math.max(maxZ, cell.pos().getZ());
349 354 }
350 return new AABB(minX, minY, minZ, maxX + 1.0D, maxY + 1.0D, maxZ + 1.0D);
355 return minX == Integer.MAX_VALUE ? null
356 : new AABB(minX, minY, minZ, maxX + 1.0D, maxY + 1.0D, maxZ + 1.0D);
351 357 }
352 358
353 359 private static int previewDistance(Minecraft minecraft) {
Modified src/main/java/com/xfestudio/mydimension/client/builder/BuilderPreviewState.java +192 -36
@@ -150,6 +150,19 @@ public final class BuilderPreviewState {
150 150 private volatile Focus focus;
151 151 @Nullable
152 152 private volatile Candidate controlCandidate;
153 @Nullable
154 private ResourceKey<Level> layerDimension;
155 @Nullable
156 private Selection layerSelection;
157 @Nullable
158 private UUID layerActiveJobId;
159 private List<Cell> surfaceCells = List.of();
160 private List<Cell> missingCells = List.of();
161 private List<Cell> deploymentCells = List.of();
162 private boolean deploymentActive;
163 private boolean serverCancelable;
164 private boolean layersInitialized;
165 private int layerRevision;
153 166 private record PublishedPreview(Snapshot snapshot,
154 167 Map<BlockPos, MissingTarget> interactiveGroups,
155 168 @Nullable AABB blueprintBounds) {
@@ -171,7 +184,113 @@ public final class BuilderPreviewState {
171 184 return frame == null ? null : frame.snapshot();
172 185 }
173 186
187 /**
188 * Replaces every preview layer from one already-composed snapshot. Production callers should
189 * prefer the layer-specific update methods below so unrelated workflows cannot erase each
190 * other; this entry point remains useful at the immutable boundary and in focused tests.
191 */
174 192 public void accept(Snapshot value) {
193 resetLayers(value.dimension());
194 layerSelection = value.selection();
195 layerActiveJobId = value.activeJobId();
196 missingCells = value.cells().stream()
197 .filter(cell -> cell.kind() == Kind.MISSING).toList();
198 List<Cell> ordinary = value.cells().stream()
199 .filter(cell -> cell.kind() != Kind.MISSING).toList();
200 deploymentActive = value.blueprintPreview();
201 deploymentCells = deploymentActive ? ordinary : List.of();
202 surfaceCells = deploymentActive ? List.of() : ordinary;
203 serverCancelable = value.cancelable() && value.activeJobId() != null;
204 layerRevision = value.revision();
205 publishComposite();
206 }
207
208 /** Replaces only the locally planned build/demolish surface. */
209 public void updateSurfacePreview(ResourceKey<Level> dimension, List<Cell> cells) {
210 ensureDimension(dimension);
211 surfaceCells = List.copyOf(cells);
212 advanceRevision(0);
213 publishComposite();
214 }
215
216 /** Removes only the locally planned surface, retaining selection and material-waiting work. */
217 public void clearSurfacePreview() {
218 if (!layersInitialized || surfaceCells.isEmpty()) return;
219 surfaceCells = List.of();
220 advanceRevision(0);
221 publishComposite();
222 }
223
224 /** Replaces only the copied source cuboid. */
225 public void updateSelection(Selection selection) {
226 ensureDimension(selection.dimension());
227 layerSelection = selection;
228 advanceRevision(0);
229 publishComposite();
230 }
231
232 /**
233 * Replaces only the server-owned material-waiting layer. A transient empty packet may be
234 * ignored while the lightweight server snapshot still advertises the same active job (the
235 * blueprint worker temporarily moves that job out of persistent pending storage while it runs).
236 */
237 public void updateMissingPreview(ResourceKey<Level> dimension, List<Cell> cells,
238 @Nullable UUID activeJobId, boolean cancelable,
239 int revision, boolean preserveTransientEmpty) {
240 ensureDimension(dimension);
241 if (preserveTransientEmpty && cells.isEmpty() && activeJobId == null
242 && layerActiveJobId != null) {
243 return;
244 }
245 missingCells = cells.stream()
246 .filter(cell -> cell.kind() == Kind.MISSING).toList();
247 layerActiveJobId = activeJobId;
248 serverCancelable = cancelable && activeJobId != null;
249 advanceRevision(revision);
250 publishComposite();
251 }
252
253 /** Activates or refreshes the movable deployment without destroying background workflows. */
254 public void updateDeploymentPreview(ResourceKey<Level> dimension, List<Cell> cells) {
255 ensureDimension(dimension);
256 deploymentActive = true;
257 deploymentCells = List.copyOf(cells);
258 // A surface target is meaningful only at the location from which it was planned. Once a
259 // deployment takes control of targeting, discard that stale layer; it is replanned on the
260 // first tick after the deployment is cancelled.
261 surfaceCells = List.of();
262 advanceRevision(0);
263 publishComposite();
264 }
265
266 private void publishComposite() {
267 if (!layersInitialized) {
268 published = null;
269 focus = null;
270 return;
271 }
272 Selection selection = layerSelection == null
273 || !Objects.equals(layerSelection.dimension(), layerDimension)
274 ? new Selection(layerDimension, null, null) : layerSelection;
275 List<Cell> foreground = deploymentActive ? deploymentCells : surfaceCells;
276 Map<BlockPos, Cell> visible = new LinkedHashMap<>(
277 Math.max(16, foreground.size() + missingCells.size()));
278 for (Cell cell : foreground) visible.put(cell.pos(), cell);
279 if (!deploymentActive) {
280 // Missing material is actionable and therefore wins a same-position collision with a
281 // passive surface projection. While a deployment is active it exclusively owns the
282 // world overlay and focus; missing work remains retained in this layer and returns as
283 // soon as placement is cancelled.
284 for (Cell cell : missingCells) visible.put(cell.pos(), cell);
285 }
286 boolean cancelable = deploymentActive || selection.active()
287 || serverCancelable && layerActiveJobId != null;
288 Snapshot snapshot = new Snapshot(layerDimension, List.copyOf(visible.values()), selection,
289 layerActiveJobId, deploymentActive, cancelable, layerRevision);
290 publishSnapshot(snapshot, deploymentActive ? deploymentCells : List.of());
291 }
292
293 private void publishSnapshot(Snapshot value, List<Cell> deploymentBoundsCells) {
175 294 focus = null;
176 295 if (value.cells().isEmpty()) {
177 296 published = new PublishedPreview(value, Map.of(), null);
@@ -188,18 +307,18 @@ public final class BuilderPreviewState {
188 307 if (cell.kind() == Kind.MISSING) {
189 308 targets.put(cell.pos(), cell);
190 309 }
191 if (value.blueprintPreview()) {
192 minX = Math.min(minX, cell.pos().getX());
193 minY = Math.min(minY, cell.pos().getY());
194 minZ = Math.min(minZ, cell.pos().getZ());
195 maxX = Math.max(maxX, cell.pos().getX());
196 maxY = Math.max(maxY, cell.pos().getY());
197 maxZ = Math.max(maxZ, cell.pos().getZ());
198 }
310 }
311 for (Cell cell : deploymentBoundsCells) {
312 minX = Math.min(minX, cell.pos().getX());
313 minY = Math.min(minY, cell.pos().getY());
314 minZ = Math.min(minZ, cell.pos().getZ());
315 maxX = Math.max(maxX, cell.pos().getX());
316 maxY = Math.max(maxY, cell.pos().getY());
317 maxZ = Math.max(maxZ, cell.pos().getZ());
199 318 }
200 319 Map<BlockPos, MissingTarget> groups = targets.isEmpty()
201 320 ? Map.of() : indexMissingGroups(targets);
202 AABB bounds = value.blueprintPreview() && minX != Integer.MAX_VALUE
321 AABB bounds = deploymentActive && minX != Integer.MAX_VALUE
203 322 ? new AABB(minX, minY, minZ, maxX + 1.0D, maxY + 1.0D, maxZ + 1.0D)
204 323 : null;
205 324 // Publish the immutable snapshot and all derived indexes together. Readers can never
@@ -211,48 +330,79 @@ public final class BuilderPreviewState {
211 330 focus = null;
212 331 controlCandidate = null;
213 332 published = null;
333 clearLayers();
214 334 }
215 335
216 336 public void clearLocalWorkflow() {
217 Snapshot value = snapshot();
218 if (value != null) {
219 accept(new Snapshot(value.dimension(), List.of(),
220 new Selection(value.dimension(), null, null), null,
221 false, false, value.revision() + 1));
222 }
337 if (!layersInitialized) return;
338 surfaceCells = List.of();
339 missingCells = List.of();
340 deploymentCells = List.of();
341 deploymentActive = false;
342 layerActiveJobId = null;
343 serverCancelable = false;
344 layerSelection = new Selection(layerDimension, null, null);
345 advanceRevision(0);
346 publishComposite();
223 347 focus = null;
224 348 }
225 349
226 350 /** Removes only the transformed placement, retaining the copied source cuboid. */
227 351 public void clearPlacementPreview() {
228 Snapshot value = snapshot();
229 if (value == null || !value.blueprintPreview()) return;
230 List<Cell> remaining = value.cells().stream()
231 .filter(cell -> cell.kind() == Kind.MISSING).toList();
232 boolean stillCancelable = value.selection().active() || value.activeJobId() != null;
233 accept(new Snapshot(value.dimension(), remaining, value.selection(), value.activeJobId(),
234 false, stillCancelable, value.revision() + 1));
352 if (!layersInitialized || !deploymentActive) return;
353 deploymentActive = false;
354 deploymentCells = List.of();
355 advanceRevision(0);
356 publishComposite();
235 357 }
236 358
237 359 /** Removes only the copied source selection, retaining deployment or missing previews. */
238 360 public void clearSelection() {
239 Snapshot value = snapshot();
240 if (value == null || !value.selection().active()) return;
241 boolean stillCancelable = value.blueprintPreview() || value.activeJobId() != null;
242 accept(new Snapshot(value.dimension(), value.cells(),
243 new Selection(value.dimension(), null, null), value.activeJobId(),
244 value.blueprintPreview(), stillCancelable, value.revision() + 1));
361 if (!layersInitialized || layerSelection == null || !layerSelection.active()) return;
362 layerSelection = new Selection(layerDimension, null, null);
363 advanceRevision(0);
364 publishComposite();
245 365 }
246 366
247 367 /** Removes only the yellow task cells after a transaction-specific cancellation. */
248 368 public void clearMissingPreview() {
249 Snapshot value = snapshot();
250 if (value == null || value.activeJobId() == null) return;
251 List<Cell> remaining = value.cells().stream()
252 .filter(cell -> cell.kind() != Kind.MISSING).toList();
253 boolean stillCancelable = value.blueprintPreview() || value.selection().active();
254 accept(new Snapshot(value.dimension(), remaining, value.selection(), null,
255 value.blueprintPreview(), stillCancelable, value.revision() + 1));
369 if (!layersInitialized || layerActiveJobId == null) return;
370 missingCells = List.of();
371 layerActiveJobId = null;
372 serverCancelable = false;
373 advanceRevision(0);
374 publishComposite();
375 }
376
377 private void ensureDimension(ResourceKey<Level> dimension) {
378 if (!layersInitialized || !Objects.equals(layerDimension, dimension)) {
379 resetLayers(dimension);
380 }
381 }
382
383 private void resetLayers(ResourceKey<Level> dimension) {
384 clearLayers();
385 layerDimension = dimension;
386 layerSelection = new Selection(dimension, null, null);
387 layersInitialized = true;
388 }
389
390 private void clearLayers() {
391 layerDimension = null;
392 layerSelection = null;
393 layerActiveJobId = null;
394 surfaceCells = List.of();
395 missingCells = List.of();
396 deploymentCells = List.of();
397 deploymentActive = false;
398 serverCancelable = false;
399 layersInitialized = false;
400 layerRevision = 0;
401 }
402
403 private void advanceRevision(int suggestedRevision) {
404 int next = layerRevision == Integer.MAX_VALUE ? 1 : layerRevision + 1;
405 layerRevision = Math.max(next, suggestedRevision);
256 406 }
257 407
258 408 public boolean isBlueprintPreviewActive() {
@@ -260,6 +410,11 @@ public final class BuilderPreviewState {
260 410 return value != null && value.blueprintPreview();
261 411 }
262 412
413 /** Checks the deployment layer itself; composite cells can additionally contain missing work. */
414 public boolean hasCompleteDeploymentGeneration(int expectedCells) {
415 return deploymentActive && deploymentCells.size() == Math.max(0, expectedCells);
416 }
417
263 418 public boolean hasSaveableSelection() {
264 419 Snapshot value = snapshot();
265 420 return value != null && value.selection() != null && value.selection().complete();
@@ -409,7 +564,8 @@ public final class BuilderPreviewState {
409 564 ? frame.interactiveGroups() : Map.of();
410 565 AABB visibleDeploymentBounds = snapshotVisible && value.blueprintPreview()
411 566 ? frame.blueprintBounds() : null;
412 AABB visibleSelectionBounds = snapshotVisible && value.selection() != null
567 AABB visibleSelectionBounds = snapshotVisible && !value.blueprintPreview()
568 && value.selection() != null
413 569 ? value.selection().bounds() : null;
414 570 if (groups.isEmpty() && visibleDeploymentBounds == null
415 571 && visibleSelectionBounds == null && !candidateVisible) {
Modified src/main/java/com/xfestudio/mydimension/client/builder/BuilderSurfacePreviewPlanner.java +7 -11
@@ -37,8 +37,9 @@ public final class BuilderSurfacePreviewPlanner {
37 37 public static void update(Minecraft minecraft) {
38 38 if (minecraft.player == null || minecraft.level == null) return;
39 39 BuilderPreviewState.Snapshot workflow = BuilderPreviewState.get().snapshot();
40 if (workflow != null && (workflow.activeJobId() != null || workflow.blueprintPreview()
41 || workflow.selection().active())) {
40 // A movable deployment owns the placement target. Source selections and material-waiting
41 // jobs are independent overlays and must not suppress ordinary surface prediction.
42 if (workflow != null && workflow.blueprintPreview()) {
42 43 reset();
43 44 return;
44 45 }
@@ -46,7 +47,7 @@ public final class BuilderSurfacePreviewPlanner {
46 47 HitResult picked = minecraft.player.pick(settings.reach(), 1.0F, false);
47 48 if (!(picked instanceof BlockHitResult hit) || picked.getType() != HitResult.Type.BLOCK) {
48 49 if (showingSurfacePreview && ++targetMissTicks < TARGET_MISS_GRACE_TICKS) return;
49 if (showingSurfacePreview) BuilderPreviewState.get().clear();
50 if (showingSurfacePreview) BuilderPreviewState.get().clearSurfacePreview();
50 51 reset();
51 52 return;
52 53 }
@@ -55,7 +56,7 @@ public final class BuilderSurfacePreviewPlanner {
55 56 if (!BuilderInteractionPolicy.permitsScepter(Screen.hasShiftDown(), targetState)) {
56 57 // Interaction-priority targets hide a previous surface preview immediately. The
57 58 // ordinary right-click path is then free to reach the block itself.
58 if (workflow != null) BuilderPreviewState.get().clear();
59 BuilderPreviewState.get().clearSurfacePreview();
59 60 reset();
60 61 return;
61 62 }
@@ -70,15 +71,10 @@ public final class BuilderSurfacePreviewPlanner {
70 71 && !hasPreviewDrift(minecraft.level, key)) return;
71 72
72 73 List<BuilderPreviewState.Cell> cells = plan(minecraft.level, hit, settings, override);
73 BuilderPreviewState.Selection empty = new BuilderPreviewState.Selection(minecraft.level.dimension(),
74 null, null);
75 int revision = workflow == null ? 1 : workflow.revision() + 1;
76 BuilderPreviewState.Snapshot planned = new BuilderPreviewState.Snapshot(
77 minecraft.level.dimension(), cells, empty, null, false, false, revision);
78 BuilderPreviewState.get().accept(planned);
74 BuilderPreviewState.get().updateSurfacePreview(minecraft.level.dimension(), cells);
79 75 lastKey = key;
80 76 showingSurfacePreview = true;
81 lastPlannedSnapshot = planned;
77 lastPlannedSnapshot = BuilderPreviewState.get().snapshot();
82 78 lastCells = cells;
83 79 validationCursor = 0;
84 80 lastFace = hit.getDirection();
Modified src/main/java/com/xfestudio/mydimension/client/builder/BuilderToolScreen.java +126 -12
@@ -23,6 +23,8 @@ public class BuilderToolScreen extends Screen {
23 23 private static final int PANEL_WIDTH = 540;
24 24 private static final int PANEL_HEIGHT = 322;
25 25 private static final int PAGE_ROWS = 6;
26 private static final int WORKFLOW_ROW_TOP = 145;
27 private static final int WORKFLOW_ROW_HEIGHT = 22;
26 28
27 29 private final ClientBlueprintLibrary library = ClientBlueprintLibrary.get();
28 30 private Tab tab = Tab.OPERATIONS;
@@ -33,6 +35,9 @@ public class BuilderToolScreen extends Screen {
33 35 private EditBox buildLimit;
34 36 private EditBox demolishLimit;
35 37 private EditBox aclPlayer;
38 private Button missingWorkflowCancel;
39 private Button selectionWorkflowCancel;
40 private Button deploymentWorkflowCancel;
36 41 private int anchorOffset;
37 42 private int blueprintOffset;
38 43 private int historyOffset;
@@ -49,6 +54,9 @@ public class BuilderToolScreen extends Screen {
49 54 @Override
50 55 protected void init() {
51 56 snapshot = BuilderClientServices.snapshot();
57 missingWorkflowCancel = null;
58 selectionWorkflowCancel = null;
59 deploymentWorkflowCancel = null;
52 60 if (!snapshot.enabled() && tab != Tab.BLUEPRINTS && tab != Tab.SETTINGS) tab = Tab.BLUEPRINTS;
53 61 localMode = snapshot.mode();
54 62 localMatch = snapshot.surfaceMatch();
@@ -116,23 +124,24 @@ public class BuilderToolScreen extends Screen {
116 124 }).bounds(left, top + 82, 172, 20).build();
117 125 addRenderableWidget(history);
118 126
119 Button cancel = Button.builder(Component.translatable("screen.mydimension.realmwright.cancel_job"), button -> {
120 BuilderClientServices.send(new BuilderClientCommand.CancelActive(snapshot.activeJobId()));
121 BuilderPreviewState.get().clearLocalWorkflow();
122 }).bounds(left, top + 108, 172, 20).build();
123 cancel.active = snapshot.activeJobId() != null;
124 addRenderableWidget(cancel);
125
126 127 Button undo = Button.builder(Component.translatable("screen.mydimension.realmwright.undo"),
127 128 button -> BuilderClientServices.send(new BuilderClientCommand.Undo()))
128 .bounds(left + 184, top + 108, 86, 20).build();
129 .bounds(left, top + 108, 86, 20).build();
129 130 undo.active = snapshot.canUndo();
130 131 addRenderableWidget(undo);
131 132 Button redo = Button.builder(Component.translatable("screen.mydimension.realmwright.redo"),
132 133 button -> BuilderClientServices.send(new BuilderClientCommand.Redo()))
133 .bounds(left + 282, top + 108, 86, 20).build();
134 .bounds(left + 98, top + 108, 86, 20).build();
134 135 redo.active = snapshot.canRedo();
135 136 addRenderableWidget(redo);
137
138 missingWorkflowCancel = addRenderableWidget(workflowCancelButton(left, top,
139 WorkflowKind.MISSING));
140 selectionWorkflowCancel = addRenderableWidget(workflowCancelButton(left, top,
141 WorkflowKind.SELECTION));
142 deploymentWorkflowCancel = addRenderableWidget(workflowCancelButton(left, top,
143 WorkflowKind.DEPLOYMENT));
144 updateWorkflowButtons();
136 145 }
137 146
138 147 private void initSupplies() {
@@ -287,6 +296,7 @@ public class BuilderToolScreen extends Screen {
287 296 if (buildLimit != null) buildLimit.tick();
288 297 if (demolishLimit != null) demolishLimit.tick();
289 298 if (aclPlayer != null) aclPlayer.tick();
299 updateWorkflowButtons();
290 300 }
291 301
292 302 @Override
@@ -336,9 +346,7 @@ public class BuilderToolScreen extends Screen {
336 346 left, top + 42, 0xFFBFC9D8, false);
337 347 graphics.drawString(font, Component.translatable("screen.mydimension.realmwright.demolish_limit"),
338 348 left + 132, top + 42, 0xFFBFC9D8, false);
339 String progress = snapshot.totalBlocks() <= 0 ? snapshot.status()
340 : snapshot.completedBlocks() + " / " + snapshot.totalBlocks() + " " + snapshot.status();
341 graphics.drawString(font, progress, left, top + 140, 0xFFE7EDF7, false);
349 renderWorkflowRows(graphics, left, top);
342 350 }
343 351 case SUPPLIES -> {
344 352 if (snapshot.anchors().isEmpty()) {
@@ -465,6 +473,103 @@ public class BuilderToolScreen extends Screen {
465 473 : "screen.mydimension.realmwright.history_recording.off");
466 474 }
467 475
476 private Button workflowCancelButton(int left, int top, WorkflowKind kind) {
477 Button button = Button.builder(Component.translatable("gui.cancel"), ignored -> cancelWorkflow(kind))
478 .bounds(left + 318, top + WORKFLOW_ROW_TOP, 56, 18).build();
479 button.visible = false;
480 return button;
481 }
482
483 private void cancelWorkflow(WorkflowKind kind) {
484 switch (kind) {
485 case MISSING -> {
486 BuilderPreviewState previewState = BuilderPreviewState.get();
487 UUID jobId = previewState.activeJobId();
488 if (jobId == null) jobId = BuilderClientServices.snapshot().activeJobId();
489 if (jobId != null) {
490 BuilderClientServices.send(new BuilderClientCommand.CancelActive(jobId));
491 previewState.clearMissingPreview();
492 }
493 }
494 case SELECTION -> BuilderClientNetworkBridge.cancelSourceSelection();
495 case DEPLOYMENT -> BuilderClientNetworkBridge.cancelPlacementPreview();
496 }
497 updateWorkflowButtons();
498 }
499
500 private void renderWorkflowRows(GuiGraphics graphics, int left, int top) {
501 List<WorkflowRow> rows = workflowRows(snapshot, BuilderPreviewState.get().snapshot());
502 graphics.drawString(font, Component.translatable("screen.mydimension.realmwright.workflow.title"),
503 left, top + 133, 0xFFBFC9D8, false);
504 if (rows.isEmpty()) {
505 graphics.drawString(font,
506 Component.translatable("screen.mydimension.realmwright.workflow.empty"),
507 left, top + WORKFLOW_ROW_TOP + 5, 0xFF8995A7, false);
508 return;
509 }
510 for (int index = 0; index < rows.size(); index++) {
511 int y = top + WORKFLOW_ROW_TOP + index * WORKFLOW_ROW_HEIGHT;
512 graphics.fill(left, y, left + 310, y + 18, 0x7A1C2633);
513 Component clipped = Component.literal(font.plainSubstrByWidth(
514 rows.get(index).label().getString(), 298));
515 graphics.drawString(font, clipped, left + 6, y + 5, 0xFFE7EDF7, false);
516 }
517 }
518
519 private void updateWorkflowButtons() {
520 if (missingWorkflowCancel == null || selectionWorkflowCancel == null
521 || deploymentWorkflowCancel == null) return;
522 missingWorkflowCancel.visible = false;
523 selectionWorkflowCancel.visible = false;
524 deploymentWorkflowCancel.visible = false;
525 List<WorkflowRow> rows = workflowRows(snapshot, BuilderPreviewState.get().snapshot());
526 for (int index = 0; index < rows.size(); index++) {
527 Button button = switch (rows.get(index).kind()) {
528 case MISSING -> missingWorkflowCancel;
529 case SELECTION -> selectionWorkflowCancel;
530 case DEPLOYMENT -> deploymentWorkflowCancel;
531 };
532 button.setY(contentTop() + WORKFLOW_ROW_TOP + index * WORKFLOW_ROW_HEIGHT);
533 button.visible = true;
534 button.active = true;
535 }
536 }
537
538 static List<WorkflowRow> workflowRows(BuilderClientSnapshot server,
539 BuilderPreviewState.Snapshot preview) {
540 java.util.ArrayList<WorkflowRow> rows = new java.util.ArrayList<>(3);
541 UUID activeJobId = preview != null && preview.activeJobId() != null
542 ? preview.activeJobId() : server.activeJobId();
543 if (activeJobId != null) {
544 int missing = preview == null ? 0 : (int) preview.cells().stream()
545 .filter(cell -> cell.kind() == BuilderPreviewState.Kind.MISSING).count();
546 int completed = Math.max(0, server.completedBlocks());
547 int total = Math.max(Math.max(0, server.totalBlocks()), completed + missing);
548 int remaining = Math.max(missing, Math.max(0, total - completed));
549 rows.add(new WorkflowRow(WorkflowKind.MISSING,
550 Component.translatable("screen.mydimension.realmwright.workflow.missing",
551 completed, total, remaining)));
552 }
553 if (preview != null && preview.selection() != null && preview.selection().active()) {
554 BlockPos first = preview.selection().first();
555 BlockPos second = preview.selection().second();
556 Component label = second == null
557 ? Component.translatable("screen.mydimension.realmwright.workflow.selection_partial")
558 : Component.translatable("screen.mydimension.realmwright.workflow.selection",
559 Math.abs(first.getX() - second.getX()) + 1,
560 Math.abs(first.getY() - second.getY()) + 1,
561 Math.abs(first.getZ() - second.getZ()) + 1);
562 rows.add(new WorkflowRow(WorkflowKind.SELECTION, label));
563 }
564 if (preview != null && preview.blueprintPreview()) {
565 long blocks = preview.cells().stream()
566 .filter(cell -> cell.kind() != BuilderPreviewState.Kind.MISSING).count();
567 rows.add(new WorkflowRow(WorkflowKind.DEPLOYMENT,
568 Component.translatable("screen.mydimension.realmwright.workflow.deployment", blocks)));
569 }
570 return List.copyOf(rows);
571 }
572
468 573 private Component anchorLabel(BuilderClientSnapshot.AnchorView anchor) {
469 574 BlockPos pos = BlockPos.of(anchor.packedPos());
470 575 return Component.literal(anchor.name() + " " + anchor.status().name().toLowerCase(java.util.Locale.ROOT)
@@ -530,4 +635,13 @@ public class BuilderToolScreen extends Screen {
530 635 this.translationKey = translationKey;
531 636 }
532 637 }
638
639 enum WorkflowKind {
640 MISSING,
641 SELECTION,
642 DEPLOYMENT
643 }
644
645 record WorkflowRow(WorkflowKind kind, Component label) {
646 }
533 647 }
Modified src/main/java/com/xfestudio/mydimension/network/builder/BuilderCommandPacket.java +23 -1
@@ -13,6 +13,7 @@ import com.xfestudio.mydimension.builder.ResonantAnchorTarget;
13 13 import com.xfestudio.mydimension.builder.SurfaceMatchMode;
14 14 import com.xfestudio.mydimension.builder.anchor.AnchorBindings;
15 15 import com.xfestudio.mydimension.builder.blueprint.BlueprintServerService;
16 import com.xfestudio.mydimension.builder.history.BuilderTransaction;
16 17 import com.xfestudio.mydimension.config.BuilderConfig;
17 18 import com.xfestudio.mydimension.network.ModNetwork;
18 19 import com.xfestudio.mydimension.registry.ModItems;
@@ -226,6 +227,15 @@ public final class BuilderCommandPacket {
226 227 return;
227 228 }
228 229
230 if (packet.action == Action.RESUME) {
231 // A blueprint resume moves the durable waiting task into the tick-driven task manager.
232 // Publishing here would therefore observe the intentional hand-off gap and send an empty
233 // missing-material preview. The task manager publishes once it reaches a terminal or
234 // paused state; ordinary surface resumes remain synchronous and publish below.
235 resume(player, scepter, packet.id);
236 return;
237 }
238
229 239 switch (packet.action) {
230 240 case SET_MODE -> RealmwrightData.setMode(scepter, packet.mode);
231 241 case SET_MATCH -> RealmwrightData.setMatchMode(scepter, packet.match);
@@ -237,7 +247,7 @@ public final class BuilderCommandPacket {
237 247 }
238 248 case SET_HISTORY_RECORDING -> RealmwrightData.setRecordsHistory(scepter, packet.first != 0);
239 249 case USE -> { }
240 case RESUME -> resume(player, scepter, packet.id);
250 case RESUME -> { }
241 251 case CANCEL -> cancel(player, scepter, packet.id);
242 252 case CANCEL_BLUEPRINT -> cancelBlueprint(player, scepter);
243 253 case UNDO -> {
@@ -312,12 +322,24 @@ public final class BuilderCommandPacket {
312 322 if (pending == null) {
313 323 player.displayClientMessage(Component.translatable(
314 324 "message.mydimension.builder.no_pending_task"), true);
325 // Clear a genuinely stale client-side yellow preview. The deferred blueprint branch
326 // below is used only after a matching task has successfully entered the active manager.
327 BuilderNetworkBridge.sync(player);
315 328 return;
316 329 }
317 330 BuilderOperationManager.Result result = BuilderOperationManager.resumePending(player, scepter);
318 331 if (!result.accepted() && result.rejectionKey() != null) {
319 332 player.displayClientMessage(Component.translatable(result.rejectionKey()), true);
320 333 }
334 if (!defersResumeSynchronization(pending.type(), result.accepted())) {
335 BuilderNetworkBridge.sync(player);
336 }
337 }
338
339 /** Blueprint execution finishes asynchronously; every other resume has its final state now. */
340 static boolean defersResumeSynchronization(BuilderTransaction.Type type, boolean accepted) {
341 return accepted
342 && type == BuilderTransaction.Type.BLUEPRINT;
321 343 }
322 344
323 345 private static void cancel(ServerPlayer player, ItemStack scepter, @Nullable UUID requestedJob) {
Modified src/main/resources/assets/mydimension/lang/en_us.json +6 -0
@@ -167,6 +167,12 @@
167 167 "screen.mydimension.realmwright.demolish_limit": "Demolish batch limit",
168 168 "screen.mydimension.realmwright.apply": "Apply",
169 169 "screen.mydimension.realmwright.cancel_job": "Cancel incomplete/blueprint job",
170 "screen.mydimension.realmwright.workflow.title": "Current workflows",
171 "screen.mydimension.realmwright.workflow.empty": "There are no incomplete or blueprint workflows.",
172 "screen.mydimension.realmwright.workflow.missing": "Incomplete/blueprint task: %s / %s complete, %s remaining",
173 "screen.mydimension.realmwright.workflow.selection_partial": "Blueprint source: first corner selected",
174 "screen.mydimension.realmwright.workflow.selection": "Blueprint source: %s×%s×%s",
175 "screen.mydimension.realmwright.workflow.deployment": "Blueprint deployment: %s blocks",
170 176 "screen.mydimension.realmwright.undo": "Undo",
171 177 "screen.mydimension.realmwright.redo": "Redo",
172 178 "screen.mydimension.realmwright.no_anchors": "No anchors are bound. Use the scepter on an anchor to bind it.",
Modified src/main/resources/assets/mydimension/lang/zh_cn.json +6 -0
@@ -168,6 +168,12 @@
168 168 "screen.mydimension.realmwright.demolish_limit": "拆除批次上限",
169 169 "screen.mydimension.realmwright.apply": "应用",
170 170 "screen.mydimension.realmwright.cancel_job": "取消待补/蓝图任务",
171 "screen.mydimension.realmwright.workflow.title": "当前工作流",
172 "screen.mydimension.realmwright.workflow.empty": "当前没有待处理的缺料或蓝图工作流。",
173 "screen.mydimension.realmwright.workflow.missing": "待补/蓝图任务:已完成 %s / %s,待处理 %s 格",
174 "screen.mydimension.realmwright.workflow.selection_partial": "蓝图源选区:已设置第一个角点",
175 "screen.mydimension.realmwright.workflow.selection": "蓝图源选区:%s×%s×%s",
176 "screen.mydimension.realmwright.workflow.deployment": "待部署蓝图:%s 格",
171 177 "screen.mydimension.realmwright.undo": "撤销",
172 178 "screen.mydimension.realmwright.redo": "重做",
173 179 "screen.mydimension.realmwright.no_anchors": "尚未绑定供材锚;手持权杖右键锚点即可绑定。",
Modified src/test/java/com/xfestudio/mydimension/client/builder/BuilderPreviewFocusTest.java +130 -0
@@ -179,6 +179,131 @@ class BuilderPreviewFocusTest {
179 179 assertTrue(merged.selection().complete());
180 180 }
181 181
182 @Test
183 void sourceSelectionMissingTaskAndSurfacePreviewRemainIndependent() {
184 BuilderPreviewState state = new BuilderPreviewState();
185 BuilderPreviewState.Cell surface = surface(0, 0, 0);
186 BuilderPreviewState.Cell missing = missing(1, 0, 0);
187 UUID jobId = UUID.randomUUID();
188 BuilderPreviewState.Selection selection = new BuilderPreviewState.Selection(
189 DIMENSION, new BlockPos(4, 5, 6), new BlockPos(7, 8, 9));
190
191 state.updateSurfacePreview(DIMENSION, List.of(surface));
192 state.updateSelection(selection);
193 state.updateMissingPreview(DIMENSION, List.of(missing), jobId, true, 8, false);
194
195 BuilderPreviewState.Snapshot snapshot = state.snapshot();
196 assertNotNull(snapshot);
197 assertEquals(List.of(surface, missing), snapshot.cells());
198 assertEquals(selection, snapshot.selection());
199 assertEquals(jobId, snapshot.activeJobId());
200 assertFalse(snapshot.blueprintPreview());
201 assertTrue(snapshot.cancelable());
202 }
203
204 @Test
205 void deploymentExclusivelyOwnsWorldOverlayWithoutLosingMissingLayer() {
206 BuilderPreviewState state = new BuilderPreviewState();
207 BuilderPreviewState.Cell deployment = surface(2, 3, 4);
208 BuilderPreviewState.Cell collidingMissing = missing(2, 3, 4);
209 BuilderPreviewState.Cell remoteMissing = missing(30, 40, 50);
210
211 state.updateMissingPreview(DIMENSION, List.of(collidingMissing, remoteMissing),
212 UUID.randomUUID(), true, 2, false);
213 state.updateDeploymentPreview(DIMENSION, List.of(deployment));
214
215 assertEquals(List.of(deployment), state.snapshot().cells());
216 assertEquals(new AABB(2, 3, 4, 3, 4, 5), state.blueprintBounds(),
217 "independent missing cells must not enlarge the deployment focus volume");
218
219 state.clearPlacementPreview();
220
221 assertEquals(List.of(collidingMissing, remoteMissing), state.snapshot().cells(),
222 "hidden missing work must return immediately after deployment cancellation");
223 }
224
225 @Test
226 void deploymentHidesOnlySurfaceAndCancellationRestoresBackgroundWorkflow() {
227 BuilderPreviewState state = new BuilderPreviewState();
228 BuilderPreviewState.Cell surface = surface(0, 0, 0);
229 BuilderPreviewState.Cell missing = missing(1, 0, 0);
230 BuilderPreviewState.Cell deployment = surface(2, 0, 0);
231 UUID jobId = UUID.randomUUID();
232 BuilderPreviewState.Selection selection = new BuilderPreviewState.Selection(
233 DIMENSION, new BlockPos(5, 5, 5), new BlockPos(6, 6, 6));
234 state.updateSurfacePreview(DIMENSION, List.of(surface));
235 state.updateSelection(selection);
236 state.updateMissingPreview(DIMENSION, List.of(missing), jobId, true, 4, false);
237
238 state.updateDeploymentPreview(DIMENSION, List.of(deployment));
239
240 assertTrue(state.snapshot().blueprintPreview());
241 assertFalse(state.snapshot().cells().contains(surface));
242 assertEquals(List.of(deployment), state.snapshot().cells());
243 assertEquals(selection, state.snapshot().selection());
244 assertEquals(jobId, state.snapshot().activeJobId());
245
246 state.clearPlacementPreview();
247
248 assertFalse(state.snapshot().blueprintPreview());
249 assertEquals(List.of(missing), state.snapshot().cells());
250 assertEquals(selection, state.snapshot().selection());
251 assertEquals(jobId, state.snapshot().activeJobId());
252 }
253
254 @Test
255 void completingSelectionDoesNotPretendToBeADeployment() {
256 BuilderPreviewState state = new BuilderPreviewState();
257 BuilderPreviewState.Selection selection = new BuilderPreviewState.Selection(
258 DIMENSION, new BlockPos(1, 2, 3), new BlockPos(4, 5, 6));
259
260 state.updateSelection(selection);
261
262 assertTrue(state.hasSaveableSelection());
263 assertFalse(state.isBlueprintPreviewActive());
264 assertNull(state.blueprintBounds());
265 }
266
267 @Test
268 void transientEmptyServerPreviewKeepsSameAdvertisedJob() {
269 BuilderPreviewState state = new BuilderPreviewState();
270 BuilderPreviewState.Cell surface = surface(0, 0, 0);
271 BuilderPreviewState.Cell missing = missing(1, 0, 0);
272 UUID jobId = UUID.randomUUID();
273 state.updateSurfacePreview(DIMENSION, List.of(surface));
274 state.updateMissingPreview(DIMENSION, List.of(missing), jobId, true, 3, false);
275 BuilderPreviewState.Snapshot before = state.snapshot();
276
277 state.updateMissingPreview(DIMENSION, List.of(), null, false, 4, true);
278
279 assertSame(before, state.snapshot());
280 assertEquals(jobId, state.activeJobId());
281 assertEquals(List.of(surface, missing), state.snapshot().cells());
282
283 state.updateMissingPreview(DIMENSION, List.of(), null, false, 5, false);
284
285 assertNull(state.activeJobId());
286 assertEquals(List.of(surface), state.snapshot().cells());
287 }
288
289 @Test
290 void clearingSurfaceDoesNotClearSelectionOrMissingTask() {
291 BuilderPreviewState state = new BuilderPreviewState();
292 BuilderPreviewState.Cell missing = missing(2, 0, 0);
293 UUID jobId = UUID.randomUUID();
294 BuilderPreviewState.Selection selection = new BuilderPreviewState.Selection(
295 DIMENSION, new BlockPos(3, 3, 3), null);
296 state.updateSurfacePreview(DIMENSION, List.of(surface(0, 0, 0)));
297 state.updateSelection(selection);
298 state.updateMissingPreview(DIMENSION, List.of(missing), jobId, true, 2, false);
299
300 state.clearSurfacePreview();
301
302 assertEquals(List.of(missing), state.snapshot().cells());
303 assertEquals(selection, state.snapshot().selection());
304 assertEquals(jobId, state.snapshot().activeJobId());
305 }
306
182 307 private static Map<BlockPos, BuilderPreviewState.MissingTarget> index(
183 308 BuilderPreviewState.Cell... cells) {
184 309 Map<BlockPos, BuilderPreviewState.Cell> byPosition = new LinkedHashMap<>();
@@ -191,4 +316,9 @@ class BuilderPreviewFocusTest {
191 316 return new BuilderPreviewState.Cell(new BlockPos(x, y, z), null,
192 317 BuilderPreviewState.Kind.MISSING, true);
193 318 }
319
320 private static BuilderPreviewState.Cell surface(int x, int y, int z) {
321 return new BuilderPreviewState.Cell(new BlockPos(x, y, z), null,
322 BuilderPreviewState.Kind.BUILD, false);
323 }
194 324 }
Added src/test/java/com/xfestudio/mydimension/client/builder/BuilderToolScreenWorkflowTest.java +57 -0
Added src/test/java/com/xfestudio/mydimension/network/builder/BuilderCommandResumeSyncTest.java +25 -0