Skip to content

Commit 98e58b1

Browse files
committed
1.0.6
- Better handling of mushrooms (blocks and plants), delete your plant_mappings config file to get new entries. - Add SMOOTHING_PRIORITY setting (UP = always keep higher layer value, DOWN = smooth layers near edge, DOWN is new default value) - Remove old diagonal code
1 parent 7015ff7 commit 98e58b1

File tree

7 files changed

+119
-58
lines changed

7 files changed

+119
-58
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ Remove layers in the specified chunk radius (default: 3, max: 32). Automatically
3333

3434
### Configuration
3535
```
36-
/layerConfig show # Display current configuration
36+
/layerConfig show # Display current configuration
3737
/layerConfig mode <basic|extended|extreme> # Set generation mode
38-
/layerConfig distance <blocks> # Set max layer distance (3-25)
39-
/layerConfig edgeThreshold <blocks> # Set edge height threshold (1-5)
40-
/layerConfig smoothingCycles <cycles> # Set smoothing cycles (0-20)
41-
/layerConfig roundingMode <up|down|nearest> # Set rounding mode
42-
/layerConfig preset <basic|extended|extreme> # Apply preset configuration
43-
/layerConfig reload # Reload config from file
38+
/layerConfig distance <blocks> # Set max layer distance (3-25)
39+
/layerConfig edgeThreshold <blocks> # Set edge height threshold (1-5)
40+
/layerConfig smoothingCycles <cycles> # Set smoothing cycles (0-20)
41+
/layerConfig roundingMode <up|down|nearest> # Set rounding mode
42+
/layerConfig smoothingPriority <up|down> # Set smoothing priority
43+
/layerConfig preset <basic|extended|extreme> # Apply preset configuration
44+
/layerConfig reload # Reload config from file
4445
```
4546

4647
### Presets
@@ -66,6 +67,7 @@ Configuration files are automatically created in `config/crlayers/` on first run
6667
- `edge_height_threshold`: Minimum height difference to detect edges
6768
- `smoothing_cycles`: Number of smoothing passes
6869
- `smoothing_rounding_mode`: Rounding method (UP, DOWN, NEAREST)
70+
- `smoothing_priority`: UP (preserve gradients) or DOWN (smooth near edges)
6971

7072
**block_mappings.json**: Vanilla to Conquest Reforged block mappings
7173
```json

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx2G
33
org.gradle.parallel=true
44

55
# Mod Properties
6-
mod_version=1.0.5
6+
mod_version=1.0.6
77
maven_group=io.arona74
88
archives_base_name=crlayers
99

src/main/java/io/arona74/crlayers/LayerConfig.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ public enum RoundingMode {
7373
NEAREST // Round to nearest integer
7474
}
7575

76+
/**
77+
* Smoothing priority mode
78+
* UP: Only apply smoothing if it increases the value (preserves extended/extreme gradients)
79+
* DOWN: Same as UP except near edge where it will use smoothed value even if it go down from existing value (traditional smoothing)
80+
*/
81+
public static SmoothingPriority SMOOTHING_PRIORITY = SmoothingPriority.DOWN;
82+
83+
public enum SmoothingPriority {
84+
UP, // Always preserve higher gradient values (only smooth if it increases value)
85+
DOWN // Traditional smoothing near edges and always up everywhere else
86+
}
87+
7688
static {
7789
loadConfig();
7890
}
@@ -152,6 +164,15 @@ private static void parseConfig(Reader reader) {
152164
CRLayers.LOGGER.warn("Invalid rounding mode in config, using default");
153165
}
154166
}
167+
168+
if (config.has("smoothing_priority")) {
169+
try {
170+
SMOOTHING_PRIORITY = SmoothingPriority.valueOf(
171+
config.get("smoothing_priority").getAsString().toUpperCase());
172+
} catch (IllegalArgumentException e) {
173+
CRLayers.LOGGER.warn("Invalid smoothing priority in config, using default");
174+
}
175+
}
155176
}
156177

157178
private static void createExternalConfig() {
@@ -204,6 +225,8 @@ public static void save() {
204225
config.addProperty("smoothing_cycles", SMOOTHING_CYCLES);
205226
config.addProperty("_comment_smoothing_rounding_mode", "How to round averages during smoothing: UP (aggressive), DOWN (conservative), NEAREST (balanced)");
206227
config.addProperty("smoothing_rounding_mode", SMOOTHING_ROUNDING_MODE.name());
228+
config.addProperty("_comment_smoothing_priority", "Smoothing priority: UP (preserve higher gradient values), DOWN (traditional smoothing near edges)");
229+
config.addProperty("smoothing_priority", SMOOTHING_PRIORITY.name());
207230

208231
try (Writer writer = Files.newBufferedWriter(configPath)) {
209232
GSON.newBuilder().setPrettyPrinting().create().toJson(config, writer);

src/main/java/io/arona74/crlayers/LayerGenerator.java

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ private void smoothingPass(int currentY,
501501
int sum = 0;
502502
int count = 0;
503503
int maxCardinalNeighborValue = 0;
504+
boolean hasEBlockNeighbor = false;
504505

505506
// Only consider the 4 cardinal neighbors
506507
for (int[] offset : cardinalOffsets) {
@@ -513,6 +514,7 @@ private void smoothingPass(int currentY,
513514
} else if (eBlocks.contains(neighbor)) {
514515
sum += 0;
515516
count++;
517+
hasEBlockNeighbor = true;
516518
} else if (layerValues.containsKey(neighbor)) {
517519
int neighborValue = layerValues.get(neighbor);
518520
sum += neighborValue;
@@ -546,9 +548,23 @@ private void smoothingPass(int currentY,
546548
if (value < 1) value = 1; // safety clamp
547549
}
548550

549-
// IMPORTANT: Only apply smoothing if it INCREASES the value (preserves extended gradients)
550-
if (existingValue == null || value > existingValue) {
551-
newValues.put(lBlock, value);
551+
// Apply smoothing based on priority mode
552+
if (LayerConfig.SMOOTHING_PRIORITY == LayerConfig.SmoothingPriority.UP) {
553+
// UP: Only apply smoothing if it INCREASES the value (preserves extended gradients)
554+
if (existingValue == null || value > existingValue) {
555+
newValues.put(lBlock, value);
556+
}
557+
} else {
558+
// DOWN: Hybrid approach
559+
if (hasEBlockNeighbor) {
560+
// Near edges: Traditional smoothing (always apply)
561+
newValues.put(lBlock, value);
562+
} else {
563+
// Away from edges: Preserve gradients (only apply if higher, like UP mode)
564+
if (existingValue == null || value > existingValue) {
565+
newValues.put(lBlock, value);
566+
}
567+
}
552568
}
553569
}
554570
}
@@ -567,16 +583,12 @@ private void spreadLayersFromHBlocks(int currentY,
567583
Map<BlockPos, Integer> layerValues,
568584
int maxDistance) {
569585

570-
// 8 directions: N, NE, E, SE, S, SW, W, NW
586+
// 4 directions: N, E, S, W
571587
int[][] directions = {
572588
{0, -1}, // N
573-
{1, -1}, // NE (diagonal)
574589
{1, 0}, // E
575-
{1, 1}, // SE (diagonal)
576590
{0, 1}, // S
577-
{-1, 1}, // SW (diagonal)
578591
{-1, 0}, // W
579-
{-1, -1} // NW (diagonal)
580592
};
581593

582594
// Track path length statistics
@@ -587,7 +599,6 @@ private void spreadLayersFromHBlocks(int currentY,
587599
for (BlockPos hBlock : hBlocks) {
588600
for (int dirIdx = 0; dirIdx < directions.length; dirIdx++) {
589601
int[] dir = directions[dirIdx];
590-
boolean isDiagonal = (dir[0] != 0 && dir[1] != 0);
591602

592603
// Walk in this direction and collect L blocks
593604
List<BlockPos> pathLBlocks = new ArrayList<>();
@@ -619,7 +630,7 @@ private void spreadLayersFromHBlocks(int currentY,
619630
int pathLength = pathLBlocks.size();
620631
pathLengthCounts.put(pathLength, pathLengthCounts.getOrDefault(pathLength, 0) + 1);
621632
pathsWithLayers++;
622-
applyGradient(pathLBlocks, isDiagonal, layerValues);
633+
applyGradient(pathLBlocks, layerValues);
623634
}
624635
}
625636
}
@@ -645,9 +656,9 @@ private String formatPathStats(Map<Integer, Integer> pathLengthCounts) {
645656
/**
646657
* Apply gradient to a path of L blocks
647658
*/
648-
private void applyGradient(List<BlockPos> path, boolean isDiagonal, Map<BlockPos, Integer> layerValues) {
659+
private void applyGradient(List<BlockPos> path, Map<BlockPos, Integer> layerValues) {
649660
int availableBlocks = path.size();
650-
int[] gradient = getGradientForSpace(availableBlocks, isDiagonal);
661+
int[] gradient = getGradient(availableBlocks);
651662

652663
for (int i = 0; i < path.size() && i < gradient.length; i++) {
653664
BlockPos pos = path.get(i);
@@ -661,28 +672,23 @@ private void applyGradient(List<BlockPos> path, boolean isDiagonal, Map<BlockPos
661672
}
662673
}
663674

664-
/**
665-
* Get gradient array for given available space
666-
*/
667-
private int[] getGradientForSpace(int space, boolean isDiagonal) {
668-
if (isDiagonal) {
669-
return getDiagonalGradient(space);
670-
} else {
671-
return getNormalGradient(space);
672-
}
673-
}
674-
675-
private int[] getNormalGradient(int space) {
675+
private int[] getGradient(int space) {
676676
// EXTREME mode: use extreme gradients with triple repeated values
677677
if (LayerConfig.MODE == LayerConfig.GenerationMode.EXTREME) {
678678
return getExtremeNormalGradient(space);
679679
}
680-
681680
// EXTENDED mode: use extended gradients with repeated values
682681
if (LayerConfig.MODE == LayerConfig.GenerationMode.EXTENDED) {
683682
return getExtendedNormalGradient(space);
684683
}
684+
// BASIC mode: linear gradients
685+
if (LayerConfig.MODE == LayerConfig.GenerationMode.BASIC) {
686+
return getNormalGradient(space);
687+
}
688+
return new int[0];
689+
}
685690

691+
private int[] getNormalGradient(int space) {
686692
// BASIC mode: linear gradients
687693
if (space >= 7) {
688694
return new int[]{7, 6, 5, 4, 3, 2, 1};
@@ -724,22 +730,9 @@ private int[] getExtendedNormalGradient(int space) {
724730
return new int[]{7, 6, 5, 4, 4, 3, 2, 1};
725731
}
726732
// For space <= 7, fall back to basic gradients
727-
else if (space >= 7) {
728-
return new int[]{7, 6, 5, 4, 3, 2, 1};
729-
} else if (space >= 6) {
730-
return new int[]{7, 6, 5, 3, 2, 1};
731-
} else if (space >= 5) {
732-
return new int[]{6, 5, 4, 2, 1};
733-
} else if (space >= 4) {
734-
return new int[]{7, 5, 3, 1};
735-
} else if (space >= 3) {
736-
return new int[]{6, 4, 2};
737-
} else if (space >= 2) {
738-
return new int[]{5, 2};
739-
} else if (space >= 1) {
740-
return new int[]{4};
733+
else {
734+
return getNormalGradient(space);
741735
}
742-
return new int[0];
743736
}
744737

745738
/**
@@ -768,12 +761,6 @@ private int[] getExtremeNormalGradient(int space) {
768761
return getExtendedNormalGradient(space);
769762
}
770763
}
771-
772-
private int[] getDiagonalGradient(int space) {
773-
// Diagonal gradients are currently disabled (return empty array)
774-
// You can enable them if needed for more coverage
775-
return new int[0];
776-
}
777764

778765
/**
779766
* Place all layer blocks
@@ -1027,7 +1014,15 @@ private BlockPos findSurfaceBlock(BlockPos pos) {
10271014
surfacePos = surfacePos.down();
10281015
continue;
10291016
}
1030-
1017+
1018+
// Skip mushroom blocks (big mushroom structures)
1019+
if (block == Blocks.BROWN_MUSHROOM_BLOCK ||
1020+
block == Blocks.RED_MUSHROOM_BLOCK ||
1021+
block == Blocks.MUSHROOM_STEM) {
1022+
surfacePos = surfacePos.down();
1023+
continue;
1024+
}
1025+
10311026
// Skip plants and flowers
10321027
if (block.getDefaultState().isIn(net.minecraft.registry.tag.BlockTags.FLOWERS) ||
10331028
block.getDefaultState().isIn(net.minecraft.registry.tag.BlockTags.SAPLINGS) ||

src/main/java/io/arona74/crlayers/LayerGeneratorCommand.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
6868
})
6969
.executes(LayerGeneratorCommand::setRoundingMode)))
7070

71+
.then(CommandManager.literal("smoothingPriority")
72+
.then(CommandManager.argument("priority", StringArgumentType.word())
73+
.suggests((context, builder) -> {
74+
builder.suggest("up");
75+
builder.suggest("down");
76+
return builder.buildFuture();
77+
})
78+
.executes(LayerGeneratorCommand::setSmoothingPriority)))
79+
7180
.then(CommandManager.literal("reload")
7281
.executes(LayerGeneratorCommand::reloadConfig))
7382

@@ -209,7 +218,9 @@ private static int showConfig(CommandContext<ServerCommandSource> context) {
209218
"§eSmoothing Cycles: §f%d", LayerConfig.SMOOTHING_CYCLES)), false);
210219
source.sendFeedback(() -> Text.literal(String.format(
211220
"§eRounding Mode: §f%s", LayerConfig.SMOOTHING_ROUNDING_MODE.name())), false);
212-
221+
source.sendFeedback(() -> Text.literal(String.format(
222+
"§eSmoothing Priority: §f%s", LayerConfig.SMOOTHING_PRIORITY.name())), false);
223+
213224
String modeDesc = switch (LayerConfig.MODE) {
214225
case BASIC -> "§7Linear gradient up to 7: 7→6→5→4→3→2→1";
215226
case EXTENDED -> "§7Gradual steps up to 14: 7,7→6,6→5,5→4,4→3,3→2,2→1,1";
@@ -304,6 +315,29 @@ private static int setRoundingMode(CommandContext<ServerCommandSource> context)
304315
return 1;
305316
}
306317

318+
private static int setSmoothingPriority(CommandContext<ServerCommandSource> context) {
319+
ServerCommandSource source = context.getSource();
320+
String priorityName = StringArgumentType.getString(context, "priority").toLowerCase();
321+
322+
LayerConfig.SmoothingPriority priority = switch (priorityName) {
323+
case "up" -> LayerConfig.SmoothingPriority.UP;
324+
case "down" -> LayerConfig.SmoothingPriority.DOWN;
325+
default -> {
326+
source.sendError(Text.literal("§cUnknown smoothing priority. Use: up or down"));
327+
yield null;
328+
}
329+
};
330+
331+
if (priority == null) return 0;
332+
333+
LayerConfig.SMOOTHING_PRIORITY = priority;
334+
LayerConfig.save();
335+
source.sendFeedback(() -> Text.literal(
336+
String.format("§aSet smoothing priority to: §f%s", priority.name())), true);
337+
338+
return 1;
339+
}
340+
307341
private static int reloadConfig(CommandContext<ServerCommandSource> context) {
308342
ServerCommandSource source = context.getSource();
309343

@@ -333,20 +367,23 @@ private static int applyPreset(CommandContext<ServerCommandSource> context) {
333367
LayerConfig.EDGE_HEIGHT_THRESHOLD = 1;
334368
LayerConfig.SMOOTHING_CYCLES = 6;
335369
LayerConfig.SMOOTHING_ROUNDING_MODE = LayerConfig.RoundingMode.DOWN;
370+
LayerConfig.SMOOTHING_PRIORITY = LayerConfig.SmoothingPriority.DOWN;
336371
}
337372
case "extended" -> {
338373
LayerConfig.MODE = LayerConfig.GenerationMode.EXTENDED;
339374
LayerConfig.MAX_LAYER_DISTANCE = 14;
340375
LayerConfig.EDGE_HEIGHT_THRESHOLD = 1;
341376
LayerConfig.SMOOTHING_CYCLES = 13;
342377
LayerConfig.SMOOTHING_ROUNDING_MODE = LayerConfig.RoundingMode.DOWN;
378+
LayerConfig.SMOOTHING_PRIORITY = LayerConfig.SmoothingPriority.DOWN;
343379
}
344380
case "extreme" -> {
345381
LayerConfig.MODE = LayerConfig.GenerationMode.EXTREME;
346382
LayerConfig.MAX_LAYER_DISTANCE = 21;
347383
LayerConfig.EDGE_HEIGHT_THRESHOLD = 1;
348384
LayerConfig.SMOOTHING_CYCLES = 20;
349385
LayerConfig.SMOOTHING_ROUNDING_MODE = LayerConfig.RoundingMode.DOWN;
386+
LayerConfig.SMOOTHING_PRIORITY = LayerConfig.SmoothingPriority.DOWN;
350387
}
351388
default -> {
352389
source.sendError(Text.literal("§cUnknown preset. Use: basic, extended, or extreme"));

src/main/resources/layer_config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
"_comment_smoothing_cycles": "Number of smoothing passes after layer spreading. More cycles = smoother transitions. Recommended: 4-8",
1010
"smoothing_cycles": 6,
1111
"_comment_smoothing_rounding_mode": "How to round averages during smoothing: UP (aggressive), DOWN (conservative), NEAREST (balanced)",
12-
"smoothing_rounding_mode": "NEAREST"
12+
"smoothing_rounding_mode": "DOWN",
13+
"_comment_smoothing_priority": "Smoothing priority: UP (preserve higher gradient values), DOWN (traditional smoothing near edges)",
14+
"smoothing_priority": "DOWN"
1315
}

src/main/resources/plant_mappings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"minecraft:sunflower": "conquest:sunflower",
2222
"minecraft:lilac": "conquest:lilac",
2323
"minecraft:rose_bush": "conquest:rose_bush",
24-
"minecraft:peony": "conquest:peony"
24+
"minecraft:peony": "conquest:peony",
25+
"minecraft:brown_mushroom": "conquest:brown_mushroom",
26+
"minecraft:red_mushroom": "conquest:red_mushroom"
2527
}
2628
}

0 commit comments

Comments
 (0)