Skip to content

Commit

Permalink
Merge pull request #45 from TED-inc/feature/1.18-dev
Browse files Browse the repository at this point in the history
Mining in circular pattern
```
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
DissiNL authored Jun 21, 2022
2 parents a15a24d + cf01cd7 commit f6b369d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.18.2+build.3
loader_version=0.14.4

# Mod Properties
mod_version = 0.7.2
mod_version = 0.7.3
maven_group = com.quarrymod
archives_base_name = quarry-reborn-1.18.2

Expand Down
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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
Expand Down Expand Up @@ -314,23 +313,15 @@ private void updateRemainingBlocks() {

private Queue<BlockPos> createMiningArea() {
Queue<BlockPos> 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")
private void performMineLogic(BlockPos blockPos, boolean fillHole) {
if (!canMineBlock(blockPos)) {
Expand Down

0 comments on commit f6b369d

Please sign in to comment.