Skip to content

Commit

Permalink
use Minecraft's Direction8 instead of Vec2i for neighbor resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixaurora committed Sep 15, 2023
1 parent fe3d725 commit 4ff7668
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/main/java/net/pixaurora/janerator/graphing/Coordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
import java.util.ArrayList;
import java.util.List;

import org.joml.Vector2i;
import net.minecraft.core.Direction8;

public record Coordinate(int x, int z) {
private static final Vector2i[] NEIGHBOR_OFFSETS = new Vector2i[]{
new Vector2i(1, 0),
new Vector2i(1, 1),
new Vector2i(0, 1),
new Vector2i(-1, 1),
new Vector2i(-1, 0),
new Vector2i(-1, -1),
new Vector2i(0, -1),
new Vector2i(1, -1)
};

public int toListIndex(int chunkLength) {
return chunkLength * GraphingUtils.mod(this.x, chunkLength) + GraphingUtils.mod(this.z, chunkLength);
}
Expand Down Expand Up @@ -49,15 +38,23 @@ public Coordinate makeLegal() {
return this.makeLegal(16);
}

public Coordinate offsetBy(Vector2i delta) {
return new Coordinate(this.x + delta.x, this.z + delta.y);
public Coordinate offset(int x, int z) {
return new Coordinate(this.x + x, this.z + z);
}

public Coordinate offset(Direction8 direction) {
return this.offset(direction.getStepX(), direction.getStepZ());
}

public List<Coordinate> getNeighbors() {
List<Coordinate> neighbors = new ArrayList<>(NEIGHBOR_OFFSETS.length);
return this.getNeighbors(Direction8.values());
}

public List<Coordinate> getNeighbors(Direction8... neighborDirections) {
List<Coordinate> neighbors = new ArrayList<>(neighborDirections.length);

for (Vector2i neighborOffset : NEIGHBOR_OFFSETS) {
neighbors.add(this.offsetBy(neighborOffset));
for (Direction8 direction : neighborDirections) {
neighbors.add(this.offset(direction));
}

return neighbors;
Expand Down

0 comments on commit 4ff7668

Please sign in to comment.