diff --git a/gradle.properties b/gradle.properties index 5988dbc..f571829 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.19+build.1 loader_version=0.14.7 # Mod Properties -mod_version = 1.0.0 +mod_version = 1.0.1 maven_group = com.quarrymod archives_base_name = quarry-reborn-1.19.0 diff --git a/src/main/java/net/quarrymod/blockentity/machine/tier3/MiningUtil.java b/src/main/java/net/quarrymod/blockentity/machine/tier3/MiningUtil.java new file mode 100644 index 0000000..eb9f9d3 --- /dev/null +++ b/src/main/java/net/quarrymod/blockentity/machine/tier3/MiningUtil.java @@ -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 createMiningPosition(int radius, BlockPos miningPosition) { + LinkedList 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; + } + + +} diff --git a/src/main/java/net/quarrymod/blockentity/machine/tier3/QuarryBlockEntity.java b/src/main/java/net/quarrymod/blockentity/machine/tier3/QuarryBlockEntity.java index 002f06b..7bc65a8 100644 --- a/src/main/java/net/quarrymod/blockentity/machine/tier3/QuarryBlockEntity.java +++ b/src/main/java/net/quarrymod/blockentity/machine/tier3/QuarryBlockEntity.java @@ -312,21 +312,12 @@ private void updateRemainingBlocks() { private Queue createMiningArea() { Queue blocks = new LinkedList<>(); - // No area to check when the height is of the miner. + // No area to check when the height is the same as the one of the miner. if (currentY == pos.getY()) { return blocks; } - final BlockPos upperBlockPos = pos.add(currentRadius, 0, currentRadius); - final BlockPos lowerBlockPos = pos.add(-currentRadius, 0, -currentRadius); - - for (int currentZ = lowerBlockPos.getZ(); currentZ < upperBlockPos.getZ(); currentZ++) { - for (int currentX = lowerBlockPos.getX(); currentX < upperBlockPos.getX(); currentX++) { - blocks.add(new BlockPos(currentX, currentY, currentZ)); - } - } - - return blocks; + return MiningUtil.createMiningPosition(currentRadius, new BlockPos(pos.getX(), currentY, pos.getZ())); } @SuppressWarnings("ConstantConditions")