Skip to content

Commit d30cde9

Browse files
committed
Rename recurseDirections to CARDINAL_UPRIGHT_OFFSETS and determine it algorithmically
1 parent 5d39f43 commit d30cde9

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134

135135
import java.util.ArrayDeque;
136136
import java.util.ArrayList;
137+
import java.util.Arrays;
137138
import java.util.Collections;
138139
import java.util.HashMap;
139140
import java.util.HashSet;
@@ -2716,7 +2717,7 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws
27162717
continue;
27172718
}
27182719

2719-
for (BlockVector3 recurseDirection : recurseDirections) {
2720+
for (BlockVector3 recurseDirection : CARDINAL_UPRIGHT_OFFSETS) {
27202721
final BlockVector3 neighbor = current.add(recurseDirection);
27212722

27222723
if (!region.contains(neighbor)) {
@@ -2735,7 +2736,7 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws
27352736
final Set<BlockVector3> newVisible = new HashSet<>();
27362737
for (int i = 1; i < thickness; ++i) {
27372738
outer: for (BlockVector3 position : region) {
2738-
for (BlockVector3 recurseDirection : recurseDirections) {
2739+
for (BlockVector3 recurseDirection : CARDINAL_UPRIGHT_OFFSETS) {
27392740
BlockVector3 neighbor = position.add(recurseDirection);
27402741

27412742
if (visible.contains(neighbor)) {
@@ -3074,7 +3075,7 @@ public int morph(BlockVector3 position, double brushSize, int minErodeFaces, int
30743075
totalFaces = 0;
30753076
highestFreq = 0;
30763077
highestState = blockState;
3077-
for (BlockVector3 vec3 : recurseDirections) {
3078+
for (BlockVector3 vec3 : CARDINAL_UPRIGHT_OFFSETS) {
30783079
BlockState adj = currentBuffer[x + 1 + vec3.x()][y + 1 + vec3.y()][z + 1 + vec3.z()];
30793080

30803081
if (!adj.getBlockType().getMaterial().isLiquid() && !adj.getBlockType().getMaterial().isAir()) {
@@ -3127,7 +3128,7 @@ public int morph(BlockVector3 position, double brushSize, int minErodeFaces, int
31273128
totalFaces = 0;
31283129
highestFreq = 0;
31293130
highestState = blockState;
3130-
for (BlockVector3 vec3 : recurseDirections) {
3131+
for (BlockVector3 vec3 : CARDINAL_UPRIGHT_OFFSETS) {
31313132
BlockState adj = currentBuffer[x + 1 + vec3.x()][y + 1 + vec3.y()][z + 1 + vec3.z()];
31323133
if (adj.getBlockType().getMaterial().isLiquid() || adj.getBlockType().getMaterial().isAir()) {
31333134
continue;
@@ -3170,14 +3171,18 @@ public int morph(BlockVector3 position, double brushSize, int minErodeFaces, int
31703171
return changed;
31713172
}
31723173

3173-
private static final BlockVector3[] recurseDirections = {
3174-
Direction.NORTH.toBlockVector(),
3175-
Direction.EAST.toBlockVector(),
3176-
Direction.SOUTH.toBlockVector(),
3177-
Direction.WEST.toBlockVector(),
3178-
Direction.UP.toBlockVector(),
3179-
Direction.DOWN.toBlockVector(),
3180-
};
3174+
/**
3175+
* Contains all cardinal and upright directions.
3176+
*/
3177+
private static final Direction[] CARDINAL_UPRIGHT_DIRECTIONS = Arrays.stream(Direction.values())
3178+
.filter(direction -> direction.isCardinal() || direction.isUpright())
3179+
.toArray(Direction[]::new);
3180+
/**
3181+
* Contains the offset vectors for all cardinal and upright directions.
3182+
*/
3183+
private static final BlockVector3[] CARDINAL_UPRIGHT_OFFSETS = Arrays.stream(CARDINAL_UPRIGHT_DIRECTIONS)
3184+
.map(Direction::toBlockVector)
3185+
.toArray(BlockVector3[]::new);
31813186

31823187
private static double lengthSq(double x, double y, double z) {
31833188
return (x * x) + (y * y) + (z * z);

0 commit comments

Comments
 (0)