generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ```
- Loading branch information
Showing
3 changed files
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/net/quarrymod/blockentity/machine/tier3/MiningUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.quarrymod.blockentity.machine.tier3; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class MiningUtil { | ||
|
||
private MiningUtil() { | ||
// Hide constructor | ||
} | ||
|
||
/** | ||
* Creates an queue of positions that should be mined starting at the center of the position. | ||
* Positions are loaded in a circular pattern, for radius 2, this will be the loaded outcome. | ||
* 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 | ||
* @param radius to use around the position | ||
* @param miningPosition the position the center of the shaft. | ||
* @return A list of circular positions to mine. | ||
*/ | ||
public static Queue<BlockPos> createMiningPosition(int radius, BlockPos miningPosition) { | ||
LinkedList<BlockPos> minePositions = new LinkedList<>(); | ||
|
||
// Start from negative radius | ||
int k = -radius; | ||
int l = -radius; | ||
// Add 1 to prevent off-by-one errors. (including end) | ||
int m = radius + 1; | ||
int n = radius + 1; | ||
|
||
// | ||
// https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/?ref=lbp | ||
// Explanation of the algorithm: | ||
// k - starting row index ( negative radius ) | ||
// m - ending row index ( positive radius ) | ||
// l - starting column index ( negative radius ) | ||
// n - ending column index ( positive radius ) | ||
// | ||
|
||
int i; | ||
while (k < m && l < n) { | ||
// Add the first row from the remaining rows | ||
for (i = l; i < n; ++i) { | ||
minePositions.addFirst(miningPosition.add(k, 0, i)); | ||
} | ||
k++; | ||
|
||
// Add the last column from the remaining columns | ||
for (i = k; i < m; ++i) { | ||
minePositions.addFirst(miningPosition.add(i, 0, n - 1)); | ||
} | ||
n--; | ||
|
||
// Add last remaining from the row */ | ||
if (k < m) { | ||
for (i = n - 1; i >= l; --i) { | ||
minePositions.addFirst(miningPosition.add((m - 1), 0, i)); | ||
} | ||
m--; | ||
} | ||
|
||
// Add the first column from the remaining columns */ | ||
if (l < n) { | ||
for (i = m - 1; i >= k; --i) { | ||
minePositions.addFirst(miningPosition.add(i, 0, l)); | ||
} | ||
l++; | ||
} | ||
} | ||
return minePositions; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters