diff --git a/src/main/java/net/pixaurora/janerator/config/ConfigFileManager.java b/src/main/java/net/pixaurora/janerator/config/ConfigFileManager.java index 0d0c5cd..a626e84 100644 --- a/src/main/java/net/pixaurora/janerator/config/ConfigFileManager.java +++ b/src/main/java/net/pixaurora/janerator/config/ConfigFileManager.java @@ -115,6 +115,7 @@ private JaneratorConfig createDefault() { ), new NormalShading("grassy_mushroom"), Optional.of(new NormalShading("rainbow_outline")), + false, false ) ) diff --git a/src/main/java/net/pixaurora/janerator/graphing/Coordinate.java b/src/main/java/net/pixaurora/janerator/graphing/Coordinate.java index 04bf7e8..2bbcc92 100644 --- a/src/main/java/net/pixaurora/janerator/graphing/Coordinate.java +++ b/src/main/java/net/pixaurora/janerator/graphing/Coordinate.java @@ -68,11 +68,7 @@ public Coordinate offsetIn(Direction8 direction) { return this.offset(direction.getStepX(), direction.getStepZ()); } - public List getNeighbors() { - return this.getNeighbors(Direction8.values()); - } - - public List getNeighbors(Direction8... neighborDirections) { + public List getNeighbors(Direction8[] neighborDirections) { List neighbors = new ArrayList<>(neighborDirections.length); for (Direction8 direction : neighborDirections) { diff --git a/src/main/java/net/pixaurora/janerator/graphing/GraphedChunk.java b/src/main/java/net/pixaurora/janerator/graphing/GraphedChunk.java index addb692..4df1ddd 100644 --- a/src/main/java/net/pixaurora/janerator/graphing/GraphedChunk.java +++ b/src/main/java/net/pixaurora/janerator/graphing/GraphedChunk.java @@ -8,6 +8,7 @@ import java.util.Map; import java.util.function.Function; +import net.minecraft.core.Direction8; import net.minecraft.world.level.ChunkPos; import net.pixaurora.janerator.graphing.grapher.ChunkGrapher; @@ -70,13 +71,13 @@ public List getShaded() { return shadedCoordinates; } - public List getOutlines() { + public List getOutlines(Direction8[] neighborsToCheck) { List outlinedPortion = new ArrayList<>(); Map neighboringChunks = new HashMap<>(8); for (Coordinate coordinate : this.getShaded()) { - boolean hasContrastingNeighbor = coordinate.getNeighbors() + boolean hasContrastingNeighbor = coordinate.getNeighbors(neighborsToCheck) .stream() .anyMatch( neighbor -> { diff --git a/src/main/java/net/pixaurora/janerator/graphing/OutlineType.java b/src/main/java/net/pixaurora/janerator/graphing/OutlineType.java new file mode 100644 index 0000000..adad262 --- /dev/null +++ b/src/main/java/net/pixaurora/janerator/graphing/OutlineType.java @@ -0,0 +1,18 @@ +package net.pixaurora.janerator.graphing; + +import net.minecraft.core.Direction8; + +public enum OutlineType { + ADJACENT_ONLY(Direction8.WEST, Direction8.SOUTH, Direction8.NORTH, Direction8.EAST), + INCLUDES_DIAGONALS(Direction8.values()); + + private final Direction8[] neighborsToCheck; + + private OutlineType(Direction8... neighborsToCheck) { + this.neighborsToCheck = neighborsToCheck; + } + + public Direction8[] getNeighborsToCheck() { + return this.neighborsToCheck; + } +} diff --git a/src/main/java/net/pixaurora/janerator/graphing/grapher/GrowingTileGrapher.java b/src/main/java/net/pixaurora/janerator/graphing/grapher/GrowingTileGrapher.java index a30d651..65e898d 100644 --- a/src/main/java/net/pixaurora/janerator/graphing/grapher/GrowingTileGrapher.java +++ b/src/main/java/net/pixaurora/janerator/graphing/grapher/GrowingTileGrapher.java @@ -13,6 +13,7 @@ import net.pixaurora.janerator.graphing.GraphFunction; import net.pixaurora.janerator.graphing.GraphFunctionDefinition; import net.pixaurora.janerator.graphing.GraphedChunk; +import net.pixaurora.janerator.graphing.OutlineType; public class GrowingTileGrapher implements ChunkGrapher { public static final Codec CODEC = RecordCodecBuilder.create( @@ -130,8 +131,6 @@ public boolean isCornerShaded(Coordinate realPos, Tile xTile, Tile zTile, Coordi return this.cornerFunction.get().evaluate(cornerX, cornerZ) == 1.0; } - public static final Direction8[] CROSS = new Direction8[]{Direction8.WEST, Direction8.SOUTH, Direction8.NORTH, Direction8.EAST}; - @Override public boolean isPointShaded(Coordinate pos) { Tile xTile = this.convertToTile(pos.x()); @@ -144,7 +143,7 @@ public boolean isPointShaded(Coordinate pos) { Coordinate offset = noOffset; int nudges = 0; - for (Direction8 direction : CROSS) { + for (Direction8 direction : OutlineType.INCLUDES_DIAGONALS.getNeighborsToCheck()) { Coordinate neighborPos = tilePos.offsetIn(direction); if (shade != this.isTileShaded(neighborPos)) { diff --git a/src/main/java/net/pixaurora/janerator/shade/JaneratorLayer.java b/src/main/java/net/pixaurora/janerator/shade/JaneratorLayer.java index 0dfc718..51766e6 100644 --- a/src/main/java/net/pixaurora/janerator/shade/JaneratorLayer.java +++ b/src/main/java/net/pixaurora/janerator/shade/JaneratorLayer.java @@ -9,6 +9,7 @@ import net.minecraft.world.level.ChunkPos; import net.pixaurora.janerator.graphing.GraphedChunk; +import net.pixaurora.janerator.graphing.OutlineType; import net.pixaurora.janerator.graphing.grapher.ChunkGrapher; import net.pixaurora.janerator.shade.method.ShadeData; import net.pixaurora.janerator.shade.method.ShadingMethod; @@ -19,6 +20,7 @@ public class JaneratorLayer implements JaneratorLayerData { ChunkGrapher.CODEC.fieldOf("grapher").forGetter(JaneratorLayer::getGrapher), ShadingMethod.CODEC.fieldOf("shading").forGetter(JaneratorLayer::getShading), ShadingMethod.CODEC.optionalFieldOf("outline_shading").forGetter(JaneratorLayer::getOutlineShading), + Codec.BOOL.fieldOf("outlines_include_diagonal").orElse(false).forGetter(JaneratorLayer::outlinesIncludeDiagonals), Codec.BOOL.fieldOf("generate_structures").orElse(false).forGetter(JaneratorLayer::generateStructures) ).apply(instance, JaneratorLayer::new) ); @@ -27,14 +29,16 @@ public class JaneratorLayer implements JaneratorLayerData { private final ShadingMethod shadingMethod; private final Optional outlineShading; + private final OutlineType outlinesIncludeDiagonal; private final boolean generateStructures; - public JaneratorLayer(ChunkGrapher grapher, ShadingMethod shadingMethod, Optional outlineShading, boolean generateStructures) { + public JaneratorLayer(ChunkGrapher grapher, ShadingMethod shadingMethod, Optional outlineShading, boolean outlinesIncludeDiagonal, boolean generateStructures) { this.grapher = grapher; this.shadingMethod = shadingMethod; this.outlineShading = outlineShading; + this.outlinesIncludeDiagonal = outlinesIncludeDiagonal ? OutlineType.INCLUDES_DIAGONALS : OutlineType.ADJACENT_ONLY; this.generateStructures = generateStructures; } @@ -51,6 +55,10 @@ public Optional getOutlineShading() { return outlineShading; } + public boolean outlinesIncludeDiagonals() { + return outlinesIncludeDiagonal == OutlineType.INCLUDES_DIAGONALS; + } + public List involvedGeneratorKeys() { List keys = new ArrayList<>(this.shadingMethod.involvedGeneratorKeys()); this.outlineShading.ifPresent(outlineShading -> keys.addAll(outlineShading.involvedGeneratorKeys())); @@ -67,7 +75,7 @@ public List shadesIn(ChunkPos chunk) { GraphedChunk graph = this.grapher.getChunkGraph(chunk); List shades = new ArrayList<>(this.shadingMethod.shadeIn(graph.getShaded(), chunk)); - this.outlineShading.ifPresent(outline -> shades.addAll(outline.shadeIn(graph.getOutlines(), chunk))); + this.outlineShading.ifPresent(outline -> shades.addAll(outline.shadeIn(graph.getOutlines(this.outlinesIncludeDiagonal.getNeighborsToCheck()), chunk))); return shades; } diff --git a/src/main/java/net/pixaurora/janerator/shade/method/PieShading.java b/src/main/java/net/pixaurora/janerator/shade/method/PieShading.java index d783bff..fbfeb4e 100644 --- a/src/main/java/net/pixaurora/janerator/shade/method/PieShading.java +++ b/src/main/java/net/pixaurora/janerator/shade/method/PieShading.java @@ -44,8 +44,8 @@ private int getSlice(Coordinate pos) { return Math.min(currentSlice, lastSliceIndex); // Because there is a straight 1-thick line that is out of bounds otherwise } - @Override - public String getShade(Coordinate pos) { - return this.generatorKeys.get(this.getSlice(pos)); - } + @Override + public String getShade(Coordinate pos) { + return this.generatorKeys.get(this.getSlice(pos)); + } }