Skip to content

Commit daedfd2

Browse files
committed
2.0.23
1 parent 640c995 commit daedfd2

68 files changed

Lines changed: 3285 additions & 723 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "Build"
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- "**"
@@ -110,7 +111,7 @@ jobs:
110111
wget -P run/mods "$MOD_URL"
111112
112113
- name: Run ${{ matrix.version }} ${{ matrix.mod_loader }} client
113-
uses: 3arthqu4ke/mc-runtime-test@a099315cbed61f71bfd6c899a76ae5ab10f52adb # 4.3.1
114+
uses: 3arthqu4ke/mc-runtime-test@9d9ea4af8ef6d82648051f750c49905f75d0c3bb # v4.4.0
114115
with:
115116
mc: ${{ matrix.version }}
116117
modloader: ${{ matrix.mod_loader }}

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## 2.0.23
22

3-
- Improved initial config load times by 20-50% due to custom registry loading logic
3+
- Added support for editing structure template pools and its element weights
4+
- Added "start_height" as a configurable field for jigsaw-like structures
5+
- Added more icons to the biome dropdown
6+
- Fixed load/save of structure's "size" property
7+
- Fixed search to actually include only proper results
8+
- Fixed alphabetical sorting of namespaces, structures and structure sets
9+
- Improved compatibility with other mods implementing custom jigsaw structures
10+
- Lot of other small tweaks/fixes
411

512
## 2.0.22
613

buildSrc/src/main/kotlin/FabricLoomCompatPlugin.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.gradle.api.Project
44
import org.gradle.api.tasks.TaskProvider
55
import org.gradle.jvm.tasks.Jar
66
import org.gradle.kotlin.dsl.create
7+
import org.gradle.kotlin.dsl.named
78
import org.gradle.kotlin.dsl.the
89

910
open class FabricLoomCompatPlugin : Plugin<Project> {
@@ -45,15 +46,13 @@ open class FabricLoomCompatPlugin : Plugin<Project> {
4546

4647
open class FabricExtensions(val project: Project, val isNew: Boolean) {
4748
val modJar: TaskProvider<Jar> by lazy {
48-
val candidate = if (isNew) project.tasks.named("jar")
49-
else project.tasks.named("remapJar")
50-
candidate as TaskProvider<Jar>
49+
if (isNew) project.tasks.named<Jar>("jar")
50+
else project.tasks.named<Jar>("remapJar")
5151
}
5252

5353
val modSourcesJar: TaskProvider<Jar> by lazy {
54-
val candidate = if (isNew) project.tasks.named("sourcesJar")
55-
else project.tasks.named("remapSourcesJar")
56-
candidate as TaskProvider<Jar>
54+
if (isNew) project.tasks.named<Jar>("sourcesJar")
55+
else project.tasks.named<Jar>("remapSourcesJar")
5756
}
5857
}
5958
}

common/src/main/java/com/faboslav/structurify/common/Structurify.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ public static Identifier makeId(String path) {
3939
*///?}
4040
}
4141

42+
public static Identifier makeId(String namespace, String path) {
43+
//? if >=1.21 {
44+
return Identifier.tryBuild(
45+
namespace,
46+
path
47+
);
48+
//?} else {
49+
/*return new Identifier(
50+
namespace,
51+
path
52+
);
53+
*///?}
54+
}
55+
4256
public static Identifier makeNamespacedId(String id) {
4357
//? if >=1.21 {
4458
return Identifier.parse(
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package com.faboslav.structurify.common.api;
2+
3+
import net.minecraft.world.level.levelgen.Heightmap;
4+
import net.minecraft.world.level.levelgen.heightproviders.HeightProvider;
5+
import org.jetbrains.annotations.Nullable;
6+
7+
//? if >= 1.21.9 {
8+
import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure;
9+
//?}
10+
11+
import java.util.Objects;
12+
import java.util.Optional;
13+
14+
public interface StructurifyJigsawStructure extends StructurifyStructure
15+
{
16+
default void invalidateStructureJigsawData() {
17+
structurify$setMaxDepth(null);
18+
structurify$setStartHeight(null);
19+
structurify$setProjectStartToHeightmap(null);
20+
structurify$setMaxDistanceFromCenter(null);
21+
}
22+
23+
@Nullable Integer structurify$getMaxDepth();
24+
void structurify$setMaxDepth(@Nullable Integer maxDepth);
25+
26+
default int structurify$getMaxDepth(int originalMaxDepth) {
27+
if (this.structurify$getMaxDepth() == null) {
28+
var structureData = this.structurify$getStructureData();
29+
30+
if (structureData == null) {
31+
this.structurify$setMaxDepth(originalMaxDepth);
32+
} else {
33+
var size = structureData.getJigsawData().getSize();
34+
this.structurify$setMaxDepth(Objects.requireNonNullElse(size, originalMaxDepth));
35+
}
36+
}
37+
38+
return this.structurify$getMaxDepth();
39+
}
40+
41+
@Nullable HeightProvider structurify$getStartHeight();
42+
void structurify$setStartHeight(@Nullable HeightProvider startHeight);
43+
44+
default HeightProvider structurify$getStartHeight(HeightProvider originalStartHeight) {
45+
if (this.structurify$getStartHeight() == null) {
46+
var structureData = this.structurify$getStructureData();
47+
48+
if (structureData == null) {
49+
this.structurify$setStartHeight(originalStartHeight);
50+
} else {
51+
var heightProviderData = structureData.getJigsawData().getHeightProviderData();
52+
53+
if (heightProviderData == null) {
54+
this.structurify$setStartHeight(originalStartHeight);
55+
} else {
56+
this.structurify$setStartHeight(heightProviderData.toHeightProvider());
57+
}
58+
}
59+
}
60+
61+
return this.structurify$getStartHeight();
62+
}
63+
64+
@Nullable Optional<Heightmap.Types> structurify$getProjectStartToHeightmap();
65+
void structurify$setProjectStartToHeightmap(@Nullable Optional<Heightmap.Types> projectStartToHeightmap);
66+
67+
default Optional<Heightmap.Types> structurify$getProjectStartToHeightmap(Optional<Heightmap.Types> originalProjectStartToHeightmap) {
68+
if (this.structurify$getProjectStartToHeightmap() == null) {
69+
var structureData = this.structurify$getStructureData();
70+
71+
if (structureData == null) {
72+
this.structurify$setProjectStartToHeightmap(originalProjectStartToHeightmap);
73+
} else {
74+
var projectStartToHeightmap = structureData.getJigsawData().getProjectStartToHeightmap();
75+
76+
if(projectStartToHeightmap == null) {
77+
this.structurify$setProjectStartToHeightmap(originalProjectStartToHeightmap);
78+
} else {
79+
this.structurify$setProjectStartToHeightmap(projectStartToHeightmap.toDataValue());
80+
}
81+
}
82+
}
83+
84+
return this.structurify$getProjectStartToHeightmap();
85+
}
86+
87+
//? if >= 1.21.9 {
88+
@Nullable JigsawStructure.MaxDistance structurify$getMaxDistanceFromCenter();
89+
//?} else {
90+
/*@Nullable Integer structurify$getMaxDistanceFromCenter();
91+
*///?}
92+
93+
//? if >= 1.21.9 {
94+
void structurify$setMaxDistanceFromCenter(@Nullable JigsawStructure.MaxDistance maxDistanceFromCenter);
95+
//?} else {
96+
/*void structurify$setMaxDistanceFromCenter(@Nullable Integer maxDistanceFromCenter);
97+
*///?}
98+
99+
//? if >= 1.21.9 {
100+
default JigsawStructure.MaxDistance structurify$getMaxDistanceFromCenter(JigsawStructure.MaxDistance originalMaxDistanceFromCenter)
101+
//?} else {
102+
/*default int structurify$getMaxDistanceFromCenter(Integer originalMaxDistanceFromCenter)
103+
*///?}
104+
{
105+
if(this.structurify$getMaxDistanceFromCenter() == null) {
106+
var structureData = this.structurify$getStructureData();
107+
108+
if (structureData == null) {
109+
this.structurify$setMaxDistanceFromCenter(originalMaxDistanceFromCenter);
110+
} else {
111+
var verticalMaxDistanceFromCenter = structureData.getJigsawData().getVerticalMaxDistanceFromCenter();
112+
var horizontalMaxDistanceFromCenter = structureData.getJigsawData().getVerticalMaxDistanceFromCenter();
113+
114+
if(verticalMaxDistanceFromCenter == null || horizontalMaxDistanceFromCenter == null) {
115+
this.structurify$setMaxDistanceFromCenter(originalMaxDistanceFromCenter);
116+
} else {
117+
//? if >= 1.21.9 {
118+
this.structurify$setMaxDistanceFromCenter(new JigsawStructure.MaxDistance(
119+
structureData.getJigsawData().getHorizontalMaxDistanceFromCenter(),
120+
structureData.getJigsawData().getVerticalMaxDistanceFromCenter()
121+
));
122+
//?} else {
123+
/*this.structurify$setMaxDistanceFromCenter(horizontalMaxDistanceFromCenter);
124+
*///?}
125+
}
126+
}
127+
}
128+
129+
return this.structurify$getMaxDistanceFromCenter();
130+
}
131+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.faboslav.structurify.common.api;
2+
3+
import com.mojang.datafixers.util.Pair;
4+
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
5+
import net.minecraft.world.level.levelgen.structure.pools.StructurePoolElement;
6+
import org.jetbrains.annotations.Nullable;
7+
import org.spongepowered.asm.mixin.gen.Accessor;
8+
9+
import java.util.List;
10+
11+
public interface StructurifyTemplatePool
12+
{
13+
void structurify$setStructureTemplatePoolId(@Nullable String structureTemplatePoolId);
14+
15+
@Nullable
16+
String structurify$getStructureTemplatePoolId();
17+
}

common/src/main/java/com/faboslav/structurify/common/config/StructurifyConfig.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import com.faboslav.structurify.common.config.serialization.StructureDataSerializer;
66
import com.faboslav.structurify.common.config.serialization.StructureNamespaceDataSerializer;
77
import com.faboslav.structurify.common.config.serialization.StructureSetDataSerializer;
8+
import com.faboslav.structurify.common.config.serialization.StructureTemplatePoolDataSerializer;
89
import com.faboslav.structurify.common.events.common.UpdateRegistriesEvent;
910
import com.faboslav.structurify.common.platform.PlatformHooks;
1011
import com.faboslav.structurify.common.registry.StructurifyRegistryManagerProvider;
12+
import com.faboslav.structurify.common.registry.StructurifyTemplatePoolProvider;
1113
import com.google.gson.*;
1214

1315
import java.io.IOException;
@@ -39,6 +41,7 @@ public final class StructurifyConfig
3941
private Map<String, StructureNamespaceData> structureNamespaceData = new TreeMap<>();
4042
private Map<String, StructureData> structureData = new TreeMap<>();
4143
private Map<String, StructureSetData> structureSetData = new TreeMap<>();
44+
private Map<String, StructureTemplatePoolData> structureTemplatePoolsData = new TreeMap<>();
4245

4346
public final static boolean ENABLE_GLOBAL_SPACING_AND_SEPARATION_MODIFIER_DEFAULT_VALUE = false;
4447
public final static double GLOBAL_SPACING_AND_SEPARATION_MODIFIER_DEFAULT_VALUE = 1.0D;
@@ -54,6 +57,7 @@ public final class StructurifyConfig
5457
private static final String STRUCTURES_PROPERTY = "structures";
5558
private static final String STRUCTURE_NAMESPACES_PROPERTY = "structure_namespaces";
5659
private static final String STRUCTURE_SETS_PROPERTY = "structure_sets";
60+
private static final String STRUCTURE_TEMPLATE_POOLS_PROPERTY = "structure_template_pools";
5761

5862

5963
public Map<String, StructureNamespaceData> getStructureNamespaceData() {
@@ -68,6 +72,20 @@ public Map<String, StructureSetData> getStructureSetData() {
6872
return this.structureSetData;
6973
}
7074

75+
public Map<String, StructureTemplatePoolData> getStructureTemplatePoolsData() {
76+
return this.structureTemplatePoolsData;
77+
}
78+
79+
public Map<String, StructureTemplatePoolData> getStructureTemplatePoolsDataForStructure(String structureId) {
80+
Set<String> structureTemplatePools = StructurifyTemplatePoolProvider.getStructureTemplatePoolIds().get(structureId);
81+
return this.structureTemplatePoolsData.entrySet().stream()
82+
.filter(entry -> structureTemplatePools != null && structureTemplatePools.contains(entry.getKey()))
83+
.collect(java.util.stream.Collectors.toMap(
84+
Map.Entry::getKey,
85+
Map.Entry::getValue
86+
));
87+
}
88+
7189
public DebugData getDebugData() {
7290
return this.debugData;
7391
}
@@ -93,6 +111,7 @@ public void load() {
93111
this.structureNamespaceData = WorldgenDataProvider.getStructureNamespaces();
94112
this.structureData = WorldgenDataProvider.getStructures();
95113
this.structureSetData = WorldgenDataProvider.getStructureSets();
114+
this.structureTemplatePoolsData = WorldgenDataProvider.getStructureTemplatePools();
96115

97116
if (!Files.exists(configPath)) {
98117
return;
@@ -105,6 +124,7 @@ public void load() {
105124
this.loadStructureNamespaces(json);
106125
this.loadStructures(json);
107126
this.loadStructureSets(json);
127+
this.loadStructureTemplatePools(json);
108128

109129
Structurify.getLogger().info("Structurify config loaded");
110130
this.isLoaded = true;
@@ -227,6 +247,33 @@ private void loadStructureSets(JsonObject json) {
227247
}
228248
}
229249

250+
private void loadStructureTemplatePools(JsonObject json) {
251+
if (!json.has(STRUCTURE_TEMPLATE_POOLS_PROPERTY)) {
252+
return;
253+
}
254+
255+
var structureTemplatePools = json.getAsJsonArray(STRUCTURE_TEMPLATE_POOLS_PROPERTY);
256+
257+
for (JsonElement structureTemplatePool : structureTemplatePools) {
258+
var structureTemplatePoolJson = structureTemplatePool.getAsJsonObject();
259+
260+
if (!structureTemplatePoolJson.has(StructureSetDataSerializer.NAME_PROPERTY)) {
261+
Structurify.getLogger().info("Found invalid structure template pool entry, skipping.");
262+
continue;
263+
}
264+
265+
var structureTemplatePoolName = structureTemplatePoolJson.get(StructureSetDataSerializer.NAME_PROPERTY).getAsString();
266+
267+
if (!this.structureTemplatePoolsData.containsKey(structureTemplatePoolName)) {
268+
Structurify.getLogger().info("Found invalid structure template pool identifier of \"{}\", skipping.", structureTemplatePoolName);
269+
continue;
270+
}
271+
272+
var structureTemplatePoolData = this.structureTemplatePoolsData.get(structureTemplatePoolName);
273+
StructureTemplatePoolDataSerializer.load(structureTemplatePoolJson, structureTemplatePoolData);
274+
}
275+
}
276+
230277
public void save() {
231278
this.save(true);
232279
}
@@ -256,6 +303,7 @@ public void save(boolean syncRegistries) {
256303
this.saveStructureNamespacesData(json, true);
257304
this.saveStructuresData(json, true);
258305
this.saveStructureSetsData(json, true);
306+
this.saveStructureTemplatePoolsData(json, true);
259307

260308
Files.createDirectories(configPath.getParent());
261309
Files.createFile(configPath);
@@ -306,6 +354,7 @@ public void dump() {
306354
this.saveStructureNamespacesData(json, false);
307355
this.saveStructuresData(json, false);
308356
this.saveStructureSetsData(json, false);
357+
this.saveStructureTemplatePoolsData(json, false);
309358

310359
Files.createDirectories(configDumpPath.getParent());
311360
Files.createFile(configDumpPath);
@@ -375,6 +424,21 @@ private void saveStructureSetsData(JsonObject json, boolean saveOnlyChanged) {
375424
json.add(STRUCTURE_SETS_PROPERTY, structureSets);
376425
}
377426

427+
private void saveStructureTemplatePoolsData(JsonObject json, boolean saveOnlyChanged) {
428+
JsonArray structureTemplatePools = new JsonArray();
429+
430+
this.structureTemplatePoolsData.entrySet().stream()
431+
.filter(entry -> !saveOnlyChanged || !entry.getValue().isUsingDefaultValues())
432+
.forEach(structureTemplatePoolDataEntry -> {
433+
var structureTemplatePoolName = structureTemplatePoolDataEntry.getKey();
434+
var structureTemplatePoolData = structureTemplatePoolDataEntry.getValue();
435+
436+
StructureTemplatePoolDataSerializer.save(structureTemplatePools, structureTemplatePoolName, structureTemplatePoolData);
437+
});
438+
439+
json.add(STRUCTURE_TEMPLATE_POOLS_PROPERTY, structureTemplatePools);
440+
}
441+
378442
private Path getBackupConfigPath() {
379443
String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"));
380444
return Path.of(BACKUP_CONFIG_DIR.toString(), Structurify.MOD_ID + "_backup_" + dateTime + ".json");

0 commit comments

Comments
 (0)