Skip to content

Commit 1d334ab

Browse files
authored
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).
1 parent 83b868c commit 1d334ab

8 files changed

+29
-2
lines changed

src/main/java/com/ldtteam/structurize/placement/AbstractBlueprintIterator.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
*/
1616
public abstract class AbstractBlueprintIterator implements IBlueprintIterator
1717
{
18-
1918
/**
2019
* The position we use as our uninitialized value.
2120
*/
2221
public static final BlockPos NULL_POS = new BlockPos(-1, -1, -1);
22+
2323
/**
2424
* The Structure position we are at. Defaulted to NULL_POS.
2525
*/
2626
protected final BlockPos.MutableBlockPos progressPos = new BlockPos.MutableBlockPos(-1, -1, -1);
2727

28+
/**
29+
* The previous position before the current progress position.
30+
*/
31+
protected final BlockPos.MutableBlockPos prevProgressPos = new BlockPos.MutableBlockPos(-1, -1, -1);
32+
2833
/**
2934
* The size of the structure.
3035
*/
@@ -118,6 +123,7 @@ else if (!isRemoving() && BlockUtils.areBlockStatesEqual(info.getBlockInfo().get
118123
@Override
119124
public void setProgressPos(final BlockPos localPosition)
120125
{
126+
this.prevProgressPos.set(this.progressPos);
121127
if (localPosition.equals(NULL_POS))
122128
{
123129
this.progressPos.set(localPosition);
@@ -163,6 +169,7 @@ public boolean isRemoving()
163169
@Override
164170
public void reset()
165171
{
172+
prevProgressPos.set(NULL_POS);
166173
progressPos.set(NULL_POS);
167174
includeEntities = false;
168175
isRemoving = false;
@@ -180,6 +187,12 @@ public BlockPos getProgressPos()
180187
return progressPos.immutable();
181188
}
182189

190+
@Override
191+
public BlockPos getPrevProgressPos()
192+
{
193+
return prevProgressPos.immutable();
194+
}
195+
183196
protected IStructureHandler getStructureHandler()
184197
{
185198
return structureHandler;

src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorDefault.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public Result increment()
3131

3232
private Result iterate(boolean up)
3333
{
34+
this.prevProgressPos.set(this.progressPos);
3435
if (this.progressPos.equals(NULL_POS))
3536
{
3637
this.progressPos.set(-1, up ? 0 : this.size.getY() -1, 0);

src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorHilbert.java

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public BlueprintIteratorHilbert(@NotNull final IStructureHandler structureHandle
3131
@Override
3232
public Result increment()
3333
{
34+
this.prevProgressPos.set(this.progressPos);
3435
if (this.progressPos.equals(NULL_POS))
3536
{
3637
this.index = 0;
@@ -44,6 +45,7 @@ public Result increment()
4445
@Override
4546
public Result decrement()
4647
{
48+
this.prevProgressPos.set(this.progressPos);
4749
if (this.progressPos.equals(NULL_POS))
4850
{
4951
this.index = (this.size.getY() & 1) == 0 ? this.positions.size() - 1 : 0;

src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircle.java

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public BlueprintIteratorInwardCircle(final IStructureHandler structureHandler)
3232
*/
3333
public Result iterate(final boolean up)
3434
{
35+
this.prevProgressPos.set(this.progressPos);
3536
if (this.progressPos.equals(NULL_POS))
3637
{
3738
this.progressPos.set(-1, up ? 0 : this.size.getY() - 1, 0);

src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorInwardCircleHeight.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public BlueprintIteratorInwardCircleHeight(final IStructureHandler structureHand
2222
@Override
2323
public Result increment()
2424
{
25+
this.prevProgressPos.set(this.progressPos);
2526
if (this.progressPos.equals(NULL_POS))
2627
{
2728
this.progressPos.set(0, 0, 0);
@@ -42,6 +43,7 @@ public Result increment()
4243
@Override
4344
public Result decrement()
4445
{
46+
this.prevProgressPos.set(this.progressPos);
4547
if (this.progressPos.equals(NULL_POS))
4648
{
4749
this.progressPos.set(0, topRightCorner.getY(), 0);

src/main/java/com/ldtteam/structurize/placement/BlueprintIteratorRandom.java

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public BlueprintIteratorRandom(final IStructureHandler structureHandler)
4343
*/
4444
public Result increment()
4545
{
46+
this.prevProgressPos.set(this.progressPos);
4647
if (this.progressPos.equals(NULL_POS))
4748
{
4849
this.progressPos.set(this.positions.get(0).getX(), 0, this.positions.get(0).getZ());
@@ -75,6 +76,7 @@ public Result increment()
7576
*/
7677
public Result decrement()
7778
{
79+
this.prevProgressPos.set(this.progressPos);
7880
if (this.progressPos.equals(NULL_POS))
7981
{
8082
this.progressPos.set(this.positions.get(0).getX(), this.size.getY() - 1, this.positions.get(0).getZ());

src/main/java/com/ldtteam/structurize/placement/IBlueprintIterator.java

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public interface IBlueprintIterator
8383
*/
8484
BlockPos getProgressPos();
8585

86+
/**
87+
* Get the last position before the progress pos of the iterator.
88+
* @return the prev progress pos.
89+
*/
90+
BlockPos getPrevProgressPos();
91+
8692
/**
8793
* Get the size of the blueprint which is iterated over
8894
* @return the size

src/main/java/com/ldtteam/structurize/placement/StructurePlacer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public StructurePhasePlacementResult executeStructureStep(
120120
{
121121
final BlockPos localPos = iterator.getProgressPos();
122122
final BlockPos worldPos = handler.getProgressPosInWorld(localPos);
123+
lastPos = iterator.getPrevProgressPos();
123124

124125
if (count >= handler.getStepsPerCall())
125126
{
@@ -129,7 +130,6 @@ public StructurePhasePlacementResult executeStructureStep(
129130
final BlockState localState = handler.getBluePrint().getBlockState(localPos);
130131
if (localState == null || world.isOutsideBuildHeight(worldPos))
131132
{
132-
lastPos = localPos;
133133
iterationResult = iterateFunction.get();
134134
continue;
135135
}

0 commit comments

Comments
 (0)