Skip to content

Commit 672fd4e

Browse files
committed
2.0.27
1 parent 932701f commit 672fd4e

7 files changed

Lines changed: 129 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 2.0.27
2+
3+
- Added flatness check mode
4+
- Added max height difference for manual flatness check mode
5+
6+
## 2.0.26
7+
8+
- Fixed biome loading
9+
- Fixed crash related to loading of modded jigsaw structures
10+
- Fixed flatness check not working correctly for very small structures
11+
112
## 2.0.25
213

314
- Fixed biome loading

common/src/main/java/com/faboslav/structurify/common/config/client/gui/structure/FlatnessCheckOptions.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import com.faboslav.structurify.common.config.StructurifyConfig;
44
import com.faboslav.structurify.common.config.data.StructureLikeData;
55
import com.faboslav.structurify.common.config.data.StructureNamespaceData;
6+
import com.faboslav.structurify.common.config.data.StructureSetData;
7+
import com.faboslav.structurify.common.config.data.structure.BiomeCheckData;
68
import com.faboslav.structurify.common.config.data.structure.FlatnessCheckData;
79
import com.faboslav.structurify.common.util.LanguageUtil;
810
import dev.isxander.yacl3.api.LabelOption;
911
import dev.isxander.yacl3.api.Option;
1012
import dev.isxander.yacl3.api.OptionAddable;
1113
import dev.isxander.yacl3.api.OptionDescription;
1214
import dev.isxander.yacl3.api.controller.BooleanControllerBuilder;
15+
import dev.isxander.yacl3.api.controller.EnumControllerBuilder;
16+
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
1317
import net.minecraft.network.chat.Component;
1418
import org.jetbrains.annotations.Nullable;
1519

@@ -22,9 +26,11 @@ public final class FlatnessCheckOptions
2226
public static String OVERRIDE_GLOBAL_FLATNESS_CHECK_OPTION_NAME = "override_global_flatness_check";
2327
public static String FLATNESS_CHECK_IS_ENABLED_OPTION_NAME = "is_enabled";
2428
public static String FLATNESS_CHECK_ALLOW_NON_SOLID_BLOCKS_OPTION_NAME = "allow_non_solid_blocks";
29+
public static String FLATNESS_CHECK_MODE_OPTION_NAME = "mode";
30+
public static String FLATNESS_CHECK_MAX_HEIGHT_DIFFERENCE = "max_height_difference";
2531

2632
public static Map<String, Option<?>> addFlatnessCheckOptions(
27-
OptionAddable builder,
33+
OptionAddable groupBuilder,
2834
StructurifyConfig config,
2935
String id
3036
) {
@@ -56,7 +62,7 @@ public static Map<String, Option<?>> addFlatnessCheckOptions(
5662

5763
title = Component.literal("\n" + FLATNESS_CHECK_SYMBOL + " ").append(title);
5864

59-
builder.option(LabelOption.create(title.withStyle(style -> style.withBold(true))));
65+
groupBuilder.option(LabelOption.create(title.withStyle(style -> style.withBold(true))));
6066

6167
@Nullable Option<Boolean> isOverridingGlobalFlatnessCheckOption;
6268

@@ -76,7 +82,7 @@ public static Map<String, Option<?>> addFlatnessCheckOptions(
7682
.build();
7783

7884
flatnessCheckOptions.put(OVERRIDE_GLOBAL_FLATNESS_CHECK_OPTION_NAME, isOverridingGlobalFlatnessCheckOption);
79-
builder.option(isOverridingGlobalFlatnessCheckOption);
85+
groupBuilder.option(isOverridingGlobalFlatnessCheckOption);
8086
} else {
8187
isOverridingGlobalFlatnessCheckOption = null;
8288
}
@@ -111,7 +117,7 @@ public static Map<String, Option<?>> addFlatnessCheckOptions(
111117
.build();
112118

113119
flatnessCheckOptions.put(FLATNESS_CHECK_IS_ENABLED_OPTION_NAME, isEnabledOption);
114-
builder.option(isEnabledOption);
120+
groupBuilder.option(isEnabledOption);
115121

116122
var allowNonSolidBlocksOption = Option.<Boolean>createBuilder()
117123
.name(Component.translatable("gui.structurify.structures.structure.allow_non_solid_blocks_in_flatness_check.title"))
@@ -133,7 +139,41 @@ public static Map<String, Option<?>> addFlatnessCheckOptions(
133139
.coloured(true)).build();
134140

135141
flatnessCheckOptions.put(FLATNESS_CHECK_ALLOW_NON_SOLID_BLOCKS_OPTION_NAME, allowNonSolidBlocksOption);
136-
builder.option(allowNonSolidBlocksOption);
142+
groupBuilder.option(allowNonSolidBlocksOption);
143+
144+
var modeOption = Option.<FlatnessCheckData.FlatnessCheckMode>createBuilder()
145+
.name(Component.translatable("gui.structurify.structures.structure.flatness_check.mode.title"))
146+
.description(OptionDescription.of(Component.translatable("gui.structurify.structures.structure.flatness_check.mode.description")))
147+
.available(isEnabled)
148+
.binding(
149+
FlatnessCheckData.MODE_DEFAULT_VALUE,
150+
flatnessCheckData::getMode,
151+
flatnessCheckData::setMode
152+
).controller(opt -> EnumControllerBuilder.create(opt)
153+
.enumClass(FlatnessCheckData.FlatnessCheckMode.class)
154+
.formatValue(flatnessCheckMode -> Component.translatable("gui.structurify.structures.structure.flatness_check.mode." + flatnessCheckMode.name().toLowerCase()))).build();
155+
156+
flatnessCheckOptions.put(FLATNESS_CHECK_MODE_OPTION_NAME, modeOption);
157+
groupBuilder.option(modeOption);
158+
159+
var maxHeightDifferenceOption = Option.<Integer>createBuilder()
160+
.name(Component.translatable("gui.structurify.structures.structure.flatness_check.max_height_difference.title"))
161+
.description(OptionDescription.of(Component.translatable("gui.structurify.structures.structure.flatness_check.max_height_difference.description")))
162+
.available(isEnabled)
163+
.binding(
164+
FlatnessCheckData.MAX_HEIGHT_DIFFERENCE_DEFAULT_VALUE,
165+
flatnessCheckData::getMaxHeightDifference,
166+
flatnessCheckData::setMaxHeightDifference
167+
)
168+
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(FlatnessCheckData.MIN_HEIGHT_DIFFERENCE, FlatnessCheckData.MAX_HEIGHT_DIFFERENCE).step(1)).build();
169+
170+
flatnessCheckOptions.put(FLATNESS_CHECK_MAX_HEIGHT_DIFFERENCE, maxHeightDifferenceOption);
171+
groupBuilder.option(maxHeightDifferenceOption);
172+
173+
modeOption.addListener((opt, flatnessCheckMode) -> {
174+
boolean isMaxHeightDifferenceAvailable = flatnessCheckMode == FlatnessCheckData.FlatnessCheckMode.MANUAL;
175+
maxHeightDifferenceOption.setAvailable(isMaxHeightDifferenceAvailable);
176+
});
137177

138178
if (isOverridingGlobalFlatnessCheckOption != null) {
139179
isOverridingGlobalFlatnessCheckOption.addListener((opt, currentOverrideGlobalFlatnessCheck) -> {
@@ -154,6 +194,11 @@ public static Map<String, Option<?>> addFlatnessCheckOptions(
154194
}
155195

156196
allowNonSolidBlocksOption.setAvailable(currentIsEnabled);
197+
modeOption.setAvailable(currentIsEnabled);
198+
199+
if(modeOption.pendingValue() == FlatnessCheckData.FlatnessCheckMode.MANUAL) {
200+
maxHeightDifferenceOption.setAvailable(currentIsEnabled);
201+
}
157202
});
158203

159204
return flatnessCheckOptions;

common/src/main/java/com/faboslav/structurify/common/config/data/structure/FlatnessCheckData.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ public final class FlatnessCheckData
55
public static final boolean OVERRIDE_GLOBAL_FLATNESS_CHECK_DEFAULT_VALUE = false;
66
public final static boolean IS_ENABLED_DEFAULT_VALUE = false;
77
public final static boolean ALLOW_NON_SOLID_BLOCKS_DEFAULT_VALUE = false;
8+
public final static FlatnessCheckMode MODE_DEFAULT_VALUE = FlatnessCheckMode.AUTO;
9+
public final static int MAX_HEIGHT_DIFFERENCE_DEFAULT_VALUE = 21;
10+
11+
public static final int MIN_HEIGHT_DIFFERENCE = 0;
12+
public static final int MAX_HEIGHT_DIFFERENCE = 128;
813

914
private boolean overrideGlobalFlatnessCheck = OVERRIDE_GLOBAL_FLATNESS_CHECK_DEFAULT_VALUE;
1015
private boolean defaultOverrideGlobalFlatnessCheck = OVERRIDE_GLOBAL_FLATNESS_CHECK_DEFAULT_VALUE;
1116
private boolean isEnabled = IS_ENABLED_DEFAULT_VALUE;
1217
private boolean defaultIsEnabled = IS_ENABLED_DEFAULT_VALUE;
18+
private FlatnessCheckMode mode = MODE_DEFAULT_VALUE;
19+
private int maxHeightDifference = MAX_HEIGHT_DIFFERENCE_DEFAULT_VALUE;
1320
private boolean allowNonSolidBlocks = ALLOW_NON_SOLID_BLOCKS_DEFAULT_VALUE;
1421

1522
public FlatnessCheckData() {
@@ -58,7 +65,29 @@ public boolean areNonSolidBlocksAllowed() {
5865
return this.allowNonSolidBlocks;
5966
}
6067

68+
public FlatnessCheckMode getMode() {
69+
return this.mode;
70+
}
71+
72+
public void setMode(FlatnessCheckMode mode) {
73+
this.mode = mode;
74+
}
75+
76+
public int getMaxHeightDifference() {
77+
return this.maxHeightDifference;
78+
}
79+
80+
public void setMaxHeightDifference(int maxHeightDifference) {
81+
this.maxHeightDifference = maxHeightDifference;
82+
}
83+
6184
public void allowNonSolidBlocks(boolean allowNonSolidBlocks) {
6285
this.allowNonSolidBlocks = allowNonSolidBlocks;
6386
}
87+
88+
public enum FlatnessCheckMode
89+
{
90+
AUTO,
91+
MANUAL
92+
}
6493
}

common/src/main/java/com/faboslav/structurify/common/config/serialization/FlatnessCheckDataSerializer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.faboslav.structurify.common.config.serialization;
22

3+
import com.faboslav.structurify.common.config.data.structure.BiomeCheckData;
34
import com.faboslav.structurify.common.config.data.structure.FlatnessCheckData;
45
import com.google.gson.JsonObject;
56

@@ -8,6 +9,8 @@ public final class FlatnessCheckDataSerializer
89
private static final String OVERRIDE_GLOBAL_FLATNESS_CHECK_PROPERTY = "override_global_flatness_check";
910
private static final String ENABLE_FLATNESS_CHECK_PROPERTY = "enable_flatness_check";
1011
private static final String FLATNESS_CHECK_ALLOW_NON_SOLID_PROPERTY = "flatness_check_allow_non_solid_blocks";
12+
private static final String FLATNESS_CHECK_MODE_PROPERTY = "flatness_check_mode";
13+
private static final String FLATNESS_CHECK_MAX_HEIGHT_DIFFERENCE = "flatness_check_max_height_difference";
1114

1215
public static void load(JsonObject structureJson, FlatnessCheckData flatnessCheckData) {
1316
if (structureJson.has(OVERRIDE_GLOBAL_FLATNESS_CHECK_PROPERTY)) {
@@ -24,11 +27,23 @@ public static void load(JsonObject structureJson, FlatnessCheckData flatnessChec
2427
var allowNonSolidBlocks = structureJson.get(FLATNESS_CHECK_ALLOW_NON_SOLID_PROPERTY).getAsBoolean();
2528
flatnessCheckData.allowNonSolidBlocks(allowNonSolidBlocks);
2629
}
30+
31+
if (structureJson.has(FLATNESS_CHECK_MODE_PROPERTY)) {
32+
var flatnessCheckMode = structureJson.get(FLATNESS_CHECK_MODE_PROPERTY).getAsString();
33+
flatnessCheckData.setMode(FlatnessCheckData.FlatnessCheckMode.valueOf(flatnessCheckMode));
34+
}
35+
36+
if (structureJson.has(FLATNESS_CHECK_MAX_HEIGHT_DIFFERENCE)) {
37+
var maxHeightDifference = structureJson.get(FLATNESS_CHECK_MAX_HEIGHT_DIFFERENCE).getAsInt();
38+
flatnessCheckData.setMaxHeightDifference(maxHeightDifference);
39+
}
2740
}
2841

2942
public static void save(JsonObject structureJson, FlatnessCheckData flatnessCheckData) {
3043
structureJson.addProperty(OVERRIDE_GLOBAL_FLATNESS_CHECK_PROPERTY, flatnessCheckData.isOverridingGlobalFlatnessCheck());
3144
structureJson.addProperty(ENABLE_FLATNESS_CHECK_PROPERTY, flatnessCheckData.isEnabled());
3245
structureJson.addProperty(FLATNESS_CHECK_ALLOW_NON_SOLID_PROPERTY, flatnessCheckData.areNonSolidBlocksAllowed());
46+
structureJson.addProperty(FLATNESS_CHECK_MODE_PROPERTY, flatnessCheckData.getMode().name());
47+
structureJson.addProperty(FLATNESS_CHECK_MAX_HEIGHT_DIFFERENCE, flatnessCheckData.getMaxHeightDifference());
3348
}
3449
}

common/src/main/java/com/faboslav/structurify/common/world/level/structure/checks/StructureFlatnessCheck.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,17 @@ public static boolean checkFlatness(
8989
var structureArea = structureCheckData.getStructureArea();
9090

9191
Set<StructureFlatnessCheckSample> flatnessCheckSamples = new HashSet<>();
92-
93-
int flatnessCheckHeightThreshold = Mth.clamp(
94-
(int) Math.round(Math.sqrt(structureArea) * 0.35),
95-
3,
96-
24
97-
);
92+
int maxHeightDifference;
93+
94+
if(flatnessCheckData.getMode() == FlatnessCheckData.FlatnessCheckMode.AUTO) {
95+
maxHeightDifference = Mth.clamp(
96+
(int) Math.round(Math.sqrt(structureArea) * 0.35),
97+
3,
98+
24
99+
);
100+
} else {
101+
maxHeightDifference = flatnessCheckData.getMaxHeightDifference();
102+
}
98103

99104
int totalFlatnessChecks = structurePieceSamples.length;
100105
int nonSolidFlatnessChecks = 0;
@@ -115,16 +120,16 @@ public static boolean checkFlatness(
115120

116121
if (firstOceanFloorOccupiedHeight > maxHeight) {
117122
maxHeight = firstOceanFloorOccupiedHeight;
118-
if (maxHeight - minHeight > flatnessCheckHeightThreshold) {
119-
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, flatnessCheckHeightThreshold, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, false));
123+
if (maxHeight - minHeight > maxHeightDifference) {
124+
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, maxHeightDifference, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, false));
120125
return false;
121126
}
122127
}
123128

124129
if (firstOceanFloorOccupiedHeight < minHeight) {
125130
minHeight = firstOceanFloorOccupiedHeight;
126-
if (maxHeight - minHeight > flatnessCheckHeightThreshold) {
127-
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, flatnessCheckHeightThreshold, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, false));
131+
if (maxHeight - minHeight > maxHeightDifference) {
132+
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, maxHeightDifference, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, false));
128133
return false;
129134
}
130135
}
@@ -144,7 +149,7 @@ public static boolean checkFlatness(
144149
nonSolidFlatnessChecks++;
145150

146151
if (nonSolidFlatnessChecks >= nonSolidFlatnessChecksThreshold) {
147-
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, flatnessCheckHeightThreshold, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, false));
152+
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, maxHeightDifference, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, false));
148153
return false;
149154
}
150155
}
@@ -155,7 +160,7 @@ public static boolean checkFlatness(
155160
}
156161

157162
flatnessCheckSamples.forEach((flatnessCheckSample) -> Structurify.getConfig().getDebugData().addStructureFlatnessCheckSample(structureCenterChunkPos, flatnessCheckSample));
158-
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, flatnessCheckHeightThreshold, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, true));
163+
Structurify.getConfig().getDebugData().addStructureFlatnessCheckInfo(structureCenterChunkPos, new StructureFlatnessCheckOverview(structureId, structureStart.getBoundingBox(), structurePieces, structureArea, minHeight, maxHeight, maxHeightDifference, totalFlatnessChecks, nonSolidFlatnessChecks, nonSolidFlatnessChecksThreshold, true));
159164

160165
return true;
161166
}

common/src/main/resources/assets/structurify/lang/en_us.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
"gui.structurify.structures.structure.enable_flatness_check.description": "The structure will only generate if the terrain under the structure is flat.",
4848
"gui.structurify.structures.structure.allow_non_solid_blocks_in_flatness_check.title": "Allow non solid blocks",
4949
"gui.structurify.structures.structure.allow_non_solid_blocks_in_flatness_check.description": "Liquid, air and other \"special\" blocks will count as solid blocks and will not fail the check.",
50+
"gui.structurify.structures.structure.flatness_check.mode.title": "Mode",
51+
"gui.structurify.structures.structure.flatness_check.mode.description": "The mode based on how flatness check checks for height differences.\n\nAuto: Max. height difference is calculated automatically per each structure area and number of pieces.\n\nManual: Max. height difference is specified by the input field below.",
52+
"gui.structurify.structures.structure.flatness_check.mode.auto": "Auto",
53+
"gui.structurify.structures.structure.flatness_check.mode.manual": "Manual",
54+
"gui.structurify.structures.structure.flatness_check.max_height_difference.title": "Max. height difference (in blocks)",
55+
"gui.structurify.structures.structure.flatness_check.max_height_difference.description": "The maximum allowed height difference between the highest and lowest terrain positions within the checked area. Structures will only generate if the terrain variation does not exceed this value.",
5056
"gui.structurify.structures.biome_check": "Biome check",
5157
"gui.structurify.structures.biome_check_group.title": "Biome check settings",
5258
"gui.structurify.structures.structure.detail_button.tooltip": "Opens „%s“ structure settings",

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ java.version=
1111
mod.name=Structurify
1212
mod.id=structurify
1313
mod.group=com.faboslav.structurify
14-
mod.version=2.0.25
14+
mod.version=2.0.27
1515
mod.author=Faboslav
1616
mod.description=Configuration mod that makes customizing world generation features easy and accessible without creating datapacks.
1717
mod.license=CC-BY-NC-ND-4.0

0 commit comments

Comments
 (0)