From 1d334ab8bf08ff25a19854713228f46f3162b30f Mon Sep 17 00:00:00 2001 From: Raycoms Date: Mon, 9 Dec 2024 18:12:43 +0100 Subject: [PATCH] save progress pos (#715) Save the last iterator pos before setting a new one as "prev progress pos". Only reset to this point when restarting (saves going back too far). --- .../placement/AbstractBlueprintIterator.java | 15 ++++++++++++++- .../placement/BlueprintIteratorDefault.java | 1 + .../placement/BlueprintIteratorHilbert.java | 2 ++ .../placement/BlueprintIteratorInwardCircle.java | 1 + .../BlueprintIteratorInwardCircleHeight.java | 2 ++ .../placement/BlueprintIteratorRandom.java | 2 ++ .../structurize/placement/IBlueprintIterator.java | 6 ++++++ .../structurize/placement/StructurePlacer.java | 2 +- 8 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ldtteam/structurize/placement/AbstractBlueprintIterator.java b/src/main/java/com/ldtteam/structurize/placement/AbstractBlueprintIterator.java index 46d179c7f0..22089ba705 100644 --- a/src/main/java/com/ldtteam/structurize/placement/AbstractBlueprintIterator.java +++ b/src/main/java/com/ldtteam/structurize/placement/AbstractBlueprintIterator.java @@ -15,16 +15,21 @@ */ public abstract class AbstractBlueprintIterator implements IBlueprintIterator { - /** * The position we use as our uninitialized value. */ public static final BlockPos NULL_POS = new BlockPos(-1, -1, -1); + /** * The Structure position we are at. Defaulted to NULL_POS. */ protected final BlockPos.MutableBlockPos progressPos = new BlockPos.MutableBlockPos(-1, -1, -1); + /** + * The previous position before the current progress position. + */ + protected final BlockPos.MutableBlockPos prevProgressPos = new BlockPos.MutableBlockPos(-1, -1, -1); + /** * The size of the structure. */ @@ -118,6 +123,7 @@ else if (!isRemoving() && BlockUtils.areBlockStatesEqual(info.getBlockInfo().get @Override public void setProgressPos(final BlockPos localPosition) { + this.prevProgressPos.set(this.progressPos); if (localPosition.equals(NULL_POS)) { this.progressPos.set(localPosition); @@ -163,6 +169,7 @@ public boolean isRemoving() @Override public void reset() { + prevProgressPos.set(NULL_POS); progressPos.set(NULL_POS); includeEntities = false; isRemoving = false; @@ -180,6 +187,12 @@ public BlockPos getProgressPos() return progressPos.immutable(); } + @Override + public BlockPos getPrevProgressPos() + { + return prevProgressPos.immutable(); + } + protected IStructureHandler getStructureHandler() { return structureHandler; diff --git a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorDefault.java b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorDefault.java index 8c4f2478d9..9573a48d6f 100644 --- a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorDefault.java +++ b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorDefault.java @@ -31,6 +31,7 @@ public Result increment() private Result iterate(boolean up) { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.progressPos.set(-1, up ? 0 : this.size.getY() -1, 0); diff --git a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorHilbert.java b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorHilbert.java index 1163551f72..60450d1247 100644 --- a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorHilbert.java +++ b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorHilbert.java @@ -31,6 +31,7 @@ public BlueprintIteratorHilbert(@NotNull final IStructureHandler structureHandle @Override public Result increment() { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.index = 0; @@ -44,6 +45,7 @@ public Result increment() @Override public Result decrement() { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.index = (this.size.getY() & 1) == 0 ? this.positions.size() - 1 : 0; diff --git a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircle.java b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircle.java index febaa07bf2..26ec95bc6f 100644 --- a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircle.java +++ b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircle.java @@ -32,6 +32,7 @@ public BlueprintIteratorInwardCircle(final IStructureHandler structureHandler) */ public Result iterate(final boolean up) { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.progressPos.set(-1, up ? 0 : this.size.getY() - 1, 0); diff --git a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircleHeight.java b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircleHeight.java index 7e4f356be8..56b5866043 100644 --- a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircleHeight.java +++ b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircleHeight.java @@ -22,6 +22,7 @@ public BlueprintIteratorInwardCircleHeight(final IStructureHandler structureHand @Override public Result increment() { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.progressPos.set(0, 0, 0); @@ -42,6 +43,7 @@ public Result increment() @Override public Result decrement() { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.progressPos.set(0, topRightCorner.getY(), 0); diff --git a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorRandom.java b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorRandom.java index ed2896b40d..3c38167d47 100644 --- a/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorRandom.java +++ b/src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorRandom.java @@ -43,6 +43,7 @@ public BlueprintIteratorRandom(final IStructureHandler structureHandler) */ public Result increment() { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.progressPos.set(this.positions.get(0).getX(), 0, this.positions.get(0).getZ()); @@ -75,6 +76,7 @@ public Result increment() */ public Result decrement() { + this.prevProgressPos.set(this.progressPos); if (this.progressPos.equals(NULL_POS)) { this.progressPos.set(this.positions.get(0).getX(), this.size.getY() - 1, this.positions.get(0).getZ()); diff --git a/src/main/java/com/ldtteam/structurize/placement/IBlueprintIterator.java b/src/main/java/com/ldtteam/structurize/placement/IBlueprintIterator.java index d791b2636e..15404823e2 100644 --- a/src/main/java/com/ldtteam/structurize/placement/IBlueprintIterator.java +++ b/src/main/java/com/ldtteam/structurize/placement/IBlueprintIterator.java @@ -83,6 +83,12 @@ public interface IBlueprintIterator */ BlockPos getProgressPos(); + /** + * Get the last position before the progress pos of the iterator. + * @return the prev progress pos. + */ + BlockPos getPrevProgressPos(); + /** * Get the size of the blueprint which is iterated over * @return the size diff --git a/src/main/java/com/ldtteam/structurize/placement/StructurePlacer.java b/src/main/java/com/ldtteam/structurize/placement/StructurePlacer.java index f859891fa4..6f57431c94 100644 --- a/src/main/java/com/ldtteam/structurize/placement/StructurePlacer.java +++ b/src/main/java/com/ldtteam/structurize/placement/StructurePlacer.java @@ -120,6 +120,7 @@ public StructurePhasePlacementResult executeStructureStep( { final BlockPos localPos = iterator.getProgressPos(); final BlockPos worldPos = handler.getProgressPosInWorld(localPos); + lastPos = iterator.getPrevProgressPos(); if (count >= handler.getStepsPerCall()) { @@ -129,7 +130,6 @@ public StructurePhasePlacementResult executeStructureStep( final BlockState localState = handler.getBluePrint().getBlockState(localPos); if (localState == null || world.isOutsideBuildHeight(worldPos)) { - lastPos = localPos; iterationResult = iterateFunction.get(); continue; }