Skip to content

Commit 3cf97a0

Browse files
authored
Merge pull request #46 from TED-inc/1.19-dev
Use circular outwards pattern on mining (all) blocks. ``` 25 > 24 > 23 > 22 > 21 V 10 > 9 > 8 > 7 20 ^ V V 11 2 > [1] 6 19 ^ ^ V V 12 3 < 4 < 5 18 ^ V 13 < 14 < 15 < 16 < 17 ```
2 parents 6ecdeb3 + 8910d03 commit 3cf97a0

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.19+build.1
88
loader_version=0.14.7
99

1010
# Mod Properties
11-
mod_version = 1.0.0
11+
mod_version = 1.0.1
1212
maven_group = com.quarrymod
1313
archives_base_name = quarry-reborn-1.19.0
1414

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package net.quarrymod.blockentity.machine.tier3;
2+
3+
import java.util.LinkedList;
4+
import java.util.Queue;
5+
import net.minecraft.util.math.BlockPos;
6+
7+
public class MiningUtil {
8+
9+
private MiningUtil() {
10+
// Hide constructor
11+
}
12+
13+
/**
14+
* Creates an queue of positions that should be mined starting at the center of the position.
15+
* Positions are loaded in a circular pattern, for radius 2, this will be the loaded outcome.
16+
* 25 > 24 > 23 > 22 > 21
17+
* V
18+
* 10 > 9 > 8 > 7 20
19+
* ^ V V
20+
* 11 2 > [1] 6 19
21+
* ^ ^ V V
22+
* 12 3 < 4 < 5 18
23+
* ^ V
24+
* 13 < 14 < 15 < 16 < 17
25+
* @param radius to use around the position
26+
* @param miningPosition the position the center of the shaft.
27+
* @return A list of circular positions to mine.
28+
*/
29+
public static Queue<BlockPos> createMiningPosition(int radius, BlockPos miningPosition) {
30+
LinkedList<BlockPos> minePositions = new LinkedList<>();
31+
32+
// Start from negative radius
33+
int k = -radius;
34+
int l = -radius;
35+
// Add 1 to prevent off-by-one errors. (including end)
36+
int m = radius + 1;
37+
int n = radius + 1;
38+
39+
//
40+
// https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/?ref=lbp
41+
// Explanation of the algorithm:
42+
// k - starting row index ( negative radius )
43+
// m - ending row index ( positive radius )
44+
// l - starting column index ( negative radius )
45+
// n - ending column index ( positive radius )
46+
//
47+
48+
int i;
49+
while (k < m && l < n) {
50+
// Add the first row from the remaining rows
51+
for (i = l; i < n; ++i) {
52+
minePositions.addFirst(miningPosition.add(k, 0, i));
53+
}
54+
k++;
55+
56+
// Add the last column from the remaining columns
57+
for (i = k; i < m; ++i) {
58+
minePositions.addFirst(miningPosition.add(i, 0, n - 1));
59+
}
60+
n--;
61+
62+
// Add last remaining from the row */
63+
if (k < m) {
64+
for (i = n - 1; i >= l; --i) {
65+
minePositions.addFirst(miningPosition.add((m - 1), 0, i));
66+
}
67+
m--;
68+
}
69+
70+
// Add the first column from the remaining columns */
71+
if (l < n) {
72+
for (i = m - 1; i >= k; --i) {
73+
minePositions.addFirst(miningPosition.add(i, 0, l));
74+
}
75+
l++;
76+
}
77+
}
78+
return minePositions;
79+
}
80+
81+
82+
}

src/main/java/net/quarrymod/blockentity/machine/tier3/QuarryBlockEntity.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,21 +312,12 @@ private void updateRemainingBlocks() {
312312

313313
private Queue<BlockPos> createMiningArea() {
314314
Queue<BlockPos> blocks = new LinkedList<>();
315-
// No area to check when the height is of the miner.
315+
// No area to check when the height is the same as the one of the miner.
316316
if (currentY == pos.getY()) {
317317
return blocks;
318318
}
319319

320-
final BlockPos upperBlockPos = pos.add(currentRadius, 0, currentRadius);
321-
final BlockPos lowerBlockPos = pos.add(-currentRadius, 0, -currentRadius);
322-
323-
for (int currentZ = lowerBlockPos.getZ(); currentZ < upperBlockPos.getZ(); currentZ++) {
324-
for (int currentX = lowerBlockPos.getX(); currentX < upperBlockPos.getX(); currentX++) {
325-
blocks.add(new BlockPos(currentX, currentY, currentZ));
326-
}
327-
}
328-
329-
return blocks;
320+
return MiningUtil.createMiningPosition(currentRadius, new BlockPos(pos.getX(), currentY, pos.getZ()));
330321
}
331322

332323
@SuppressWarnings("ConstantConditions")

0 commit comments

Comments
 (0)