Skip to content

Commit f5ff952

Browse files
committed
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 52be8f6 commit f5ff952

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
@@ -14,16 +14,21 @@
1414
*/
1515
public abstract class AbstractBlueprintIterator implements IBlueprintIterator
1616
{
17-
1817
/**
1918
* The position we use as our uninitialized value.
2019
*/
2120
public static final BlockPos NULL_POS = new BlockPos(-1, -1, -1);
21+
2222
/**
2323
* The Structure position we are at. Defaulted to NULL_POS.
2424
*/
2525
protected final BlockPos.MutableBlockPos progressPos = new BlockPos.MutableBlockPos(-1, -1, -1);
2626

27+
/**
28+
* The previous position before the current progress position.
29+
*/
30+
protected final BlockPos.MutableBlockPos prevProgressPos = new BlockPos.MutableBlockPos(-1, -1, -1);
31+
2732
/**
2833
* The size of the structure.
2934
*/
@@ -117,6 +122,7 @@ else if (!isRemoving() && BlockUtils.areBlockStatesEqual(info.getBlockInfo().get
117122
@Override
118123
public void setProgressPos(final BlockPos localPosition)
119124
{
125+
this.prevProgressPos.set(this.progressPos);
120126
if (localPosition.equals(NULL_POS))
121127
{
122128
this.progressPos.set(localPosition);
@@ -162,6 +168,7 @@ public boolean isRemoving()
162168
@Override
163169
public void reset()
164170
{
171+
prevProgressPos.set(NULL_POS);
165172
progressPos.set(NULL_POS);
166173
includeEntities = false;
167174
isRemoving = false;
@@ -179,6 +186,12 @@ public BlockPos getProgressPos()
179186
return progressPos.immutable();
180187
}
181188

189+
@Override
190+
public BlockPos getPrevProgressPos()
191+
{
192+
return prevProgressPos.immutable();
193+
}
194+
182195
protected IStructureHandler getStructureHandler()
183196
{
184197
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
@@ -125,6 +125,7 @@ public StructurePhasePlacementResult executeStructureStep(
125125
{
126126
final BlockPos localPos = iterator.getProgressPos();
127127
final BlockPos worldPos = handler.getProgressPosInWorld(localPos);
128+
lastPos = iterator.getPrevProgressPos();
128129

129130
if (count >= handler.getStepsPerCall())
130131
{
@@ -134,7 +135,6 @@ public StructurePhasePlacementResult executeStructureStep(
134135
final BlockState localState = handler.getBluePrint().getBlockState(localPos);
135136
if (localState == null || world.isOutsideBuildHeight(worldPos))
136137
{
137-
lastPos = localPos;
138138
iterationResult = iterateFunction.get();
139139
continue;
140140
}

0 commit comments

Comments
 (0)