Skip to content

Commit 40c0d0d

Browse files
committed
Preserve legacy Mineralogy upgrades on NeoForge 1.21.1
1 parent aa5fb97 commit 40c0d0d

14 files changed

Lines changed: 1269 additions & 13 deletions

‎CHANGELOG.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Version 4.0.6
22

3+
* Preserve generated worlds made with Mineralogy 1.10, 1.12, or 5.x by reading their saved mod metadata and exact legacy configuration before creating the OreSpawn world profile.
4+
* Write human-readable, idempotent upgrade reports for legacy OreSpawn and Mineralogy imports while retaining source files and existing chunks unchanged.
5+
* Qualify existing OreSpawn 4.0.5 global and per-world profiles without changing explicit Custom values or provider definitions.
36
* Fix provider top and filler materials being generated one block below exposed ground.
47
* Apply underwater materials from the corrected ground and ceiling materials to roof undersides.
58
* Preserve trees, vegetation, structures and block entities by running surface replacement before late features.

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,23 @@ Important files:
3939
| `<world>/serverconfig/orespawn-worldgen.json` | Complete settings snapshot for one world |
4040
| `config/<modid>-orespawn.json` | Optional modpack override for one provider |
4141
| `config/orespawn-guide/README.md` | Guide exported automatically on first load |
42+
| `config/orespawn-upgrade-report.txt` | Human summary produced when legacy OreSpawn rules are imported |
43+
| `<world>/serverconfig/orespawn-upgrade-report.txt` | Human summary produced when a generated legacy Mineralogy world is pinned to its saved settings |
4244

4345
Profile edits affect newly generated chunks. Ore and flat-bedrock retrogen are
4446
separate opt-in features; OreSpawn never retro-generates rock strata.
4547
Stable Layers honours exact biome-ID geome influences on dynamic biome
4648
registries and spreads close geome transitions across layers rather than
4749
changing an entire vertical rock column at one boundary.
4850

51+
When an already-generated world has saved Mineralogy 1.10, 1.12, or 5.x mod
52+
metadata but no OreSpawn world profile, OreSpawn reads the matching published
53+
configuration contract and records the exact engine, numeric settings, rock
54+
order, and white/blacklists in the new world profile. Saved-world identity
55+
wins over stale files in the installation. A fresh world is never reclassified
56+
merely because an old `mineralogy.cfg` or `mineralogy-common.toml` remains in
57+
the instance.
58+
4959
To move a configured single-player world to a dedicated server, copy the
5060
world's `serverconfig/orespawn-worldgen.json` with the world and install the
5161
same provider mods on the server.

‎docs/CONFIGURATION.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ packaged or API providers, provider override files, the global configuration,
1717
the selected template, and Create World edits. The result is saved with the
1818
world. Restart after editing JSON by hand.
1919

20+
An existing generated world follows a stricter safety order. Its existing
21+
`serverconfig/orespawn-worldgen.json` always wins. If none exists, saved legacy
22+
Mineralogy mod metadata may select the matching 1.10, 1.12, or 5.x config
23+
contract before the world profile is first written. Installed-pack defaults,
24+
Create World choices, and unrelated stale legacy files cannot override that
25+
saved-world identity. See `MIGRATION.md` and the generated per-world upgrade
26+
report for the exact decision.
27+
2028
## Top-Level Fields
2129

2230
| Field | Values | Meaning |
@@ -94,6 +102,12 @@ Cyano settings use `cyano.geome_size` (4-32767),
94102
`cyano.rock_layer_noise` (1-32767), and `cyano.rock_layer_thickness` (1-255).
95103
They are ignored by Sky.
96104

105+
Profiles created from a legacy Mineralogy world also retain
106+
`cyano.enabled`, `cyano.realistic_coal_layers`, the three effective
107+
`*_rocks` arrays, the six original `*_whitelist`/`*_blacklist` arrays, and
108+
source/version fields. These are migration snapshots, not new settings that a
109+
fresh pack needs to author.
110+
97111
## Rocks And Geomes
98112

99113
A rock requires `enabled`, `family`, `depth_peak`, `depth_spread`, `min_y`,

‎docs/MIGRATION.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,37 @@ legacy-ID behaviour.
1313

1414
Migration is non-destructive. OreSpawn writes `config/orespawn-worldgen.json`
1515
only when that target does not already exist and retains every source file.
16+
When legacy OreSpawn rules are translated, a concise player-facing summary is
17+
also written atomically to `config/orespawn-upgrade-report.txt`; the existing
18+
detailed rule report remains at `config/orespawn-migration/migration-report.txt`.
19+
20+
## Existing Mineralogy Worlds
21+
22+
An already-generated world without an OreSpawn per-world profile is inspected
23+
before OreSpawn chooses any installed-pack or Create World default. OreSpawn
24+
uses saved mod metadata from `level.dat`, with a valid `level.dat_old` as a
25+
fallback, to distinguish these published contracts:
26+
27+
- Mineralogy 1.10.2 `3.3.8.26` and its `mineralogy.cfg`;
28+
- Mineralogy 1.12.2 `3.8.0.53` and its distinct `mineralogy.cfg`;
29+
- Mineralogy 5.0.1 through 5.4.0 and `mineralogy-common.toml`.
30+
31+
The resulting world profile preserves enablement, selected legacy/geome
32+
engine, geome size, layer noise and thickness, realistic-coal behavior where
33+
supported, exact effective rock order (including historical duplicates), and
34+
all six white/blacklists. Saved-world identity chooses the lineage even when a
35+
different stale config is present. Missing or malformed values use that
36+
lineage's published defaults and are reported rather than silently broadening
37+
the world configuration.
38+
39+
The human-readable result is written atomically to
40+
`<world>/serverconfig/orespawn-upgrade-report.txt`. It identifies the saved
41+
version and metadata source, config source, selected engine and lineage,
42+
effective settings and outputs, missing IDs, fallbacks, and warnings. Source
43+
configuration and existing chunks are not rewritten. Once
44+
`orespawn-worldgen.json` exists it is authoritative and the import is not run
45+
again. A fresh world containing stale legacy files remains on its explicit
46+
OreSpawn/Create World settings.
1647

1748
When `config/mineralogy-geomes.json` exists, OreSpawn imports the Mineralogy 6
1849
profile directly, updates its schema marker, and records `migrated_from`.

‎docs/PLAYER_GUIDE.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,20 @@ the same mods. Alternatively, place a prepared global profile at
9393

9494
The server console commands `/orespawn status`, `/orespawn reload`, and
9595
`/orespawn dump-biomes` help pack authors diagnose active providers and IDs.
96+
97+
### Upgrading a Mineralogy world
98+
99+
If the world was already generated with Mineralogy 1.10, 1.12, or 5.x and has
100+
no OreSpawn world profile yet, OreSpawn reads the Mineralogy version saved in
101+
the world and the matching old configuration. It preserves the selected
102+
engine, numeric settings, rock order, and lists rather than silently applying
103+
new-world defaults. Look for:
104+
105+
```text
106+
<world>/serverconfig/orespawn-upgrade-report.txt
107+
```
108+
109+
The report explains what was detected and retained, including any missing rock
110+
IDs or fallback values. OreSpawn leaves the old configuration and generated
111+
chunks untouched. A fresh world does not inherit this behavior merely because
112+
an old Mineralogy config is still present in the instance.

‎src/main/java/zone/moddev/mc/orespawn/worldgen/Geology.java‎

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package zone.moddev.mc.orespawn.worldgen;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.Random;
46

57
import zone.moddev.mc.orespawn.worldgen.math.PerlinNoise2D;
@@ -15,19 +17,46 @@
1517
import net.minecraft.core.Holder;
1618
import net.minecraft.resources.ResourceLocation;
1719
import net.minecraft.world.level.biome.Biome;
20+
import net.minecraft.core.registries.BuiltInRegistries;
21+
22+
import org.apache.logging.log4j.LogManager;
23+
import org.apache.logging.log4j.Logger;
1824

1925
public class Geology {
26+
private static final Logger LOGGER = LogManager.getLogger();
2027
private final PerlinNoise2D geomeNoiseLayer;
2128
private final PerlinNoise2D rockNoiseLayer;
2229
private final short[] whiteNoiseArray;
2330
private final BlockState[] igneousStones;
2431
private final BlockState[] metamorphicStones;
2532
private final BlockState[] sedimentaryStones;
2633
private final int layerThickness;
34+
private final boolean realisticCoalLayers;
2735

2836
public Geology(long seed, double geomeSize, double rockLayerSize, int layerThickness,
2937
BakedGeomeConfig config) {
38+
this(seed, geomeSize, rockLayerSize, layerThickness, false,
39+
config.statesForFamily(RockFamily.IGNEOUS_INTRUSIVE, RockFamily.IGNEOUS_VOLCANIC),
40+
config.statesForFamily(RockFamily.METAMORPHIC),
41+
config.statesForFamily(RockFamily.SEDIMENTARY));
42+
}
43+
44+
Geology(long seed, WorldGeologyProfile profile, BakedGeomeConfig config) {
45+
this(seed, profile.cyanoGeomeSize(), profile.cyanoRockLayerNoise(),
46+
profile.cyanoLayerThickness(), profile.cyanoRealisticCoalLayers(),
47+
resolveRockOrder(profile, "igneous_rocks",
48+
config.statesForFamily(RockFamily.IGNEOUS_INTRUSIVE, RockFamily.IGNEOUS_VOLCANIC)),
49+
resolveRockOrder(profile, "metamorphic_rocks",
50+
config.statesForFamily(RockFamily.METAMORPHIC)),
51+
resolveRockOrder(profile, "sedimentary_rocks",
52+
config.statesForFamily(RockFamily.SEDIMENTARY)));
53+
}
54+
55+
Geology(long seed, double geomeSize, double rockLayerSize, int layerThickness,
56+
boolean realisticCoalLayers, BlockState[] igneousStones,
57+
BlockState[] metamorphicStones, BlockState[] sedimentaryStones) {
3058
this.layerThickness = layerThickness;
59+
this.realisticCoalLayers = realisticCoalLayers;
3160
int rockLayerUndertones = 4;
3261
int undertoneMultiplier = 1 << (rockLayerUndertones - 1);
3362
geomeNoiseLayer = new PerlinNoise2D(~seed, 128, (float) geomeSize, 2);
@@ -40,9 +69,9 @@ public Geology(long seed, double geomeSize, double rockLayerSize, int layerThick
4069
whiteNoiseArray[i] = (short) random.nextInt(0x7FFF);
4170
}
4271

43-
igneousStones = config.statesForFamily(RockFamily.IGNEOUS_INTRUSIVE, RockFamily.IGNEOUS_VOLCANIC);
44-
metamorphicStones = config.statesForFamily(RockFamily.METAMORPHIC);
45-
sedimentaryStones = config.statesForFamily(RockFamily.SEDIMENTARY);
72+
this.igneousStones = igneousStones;
73+
this.metamorphicStones = metamorphicStones;
74+
this.sedimentaryStones = sedimentaryStones;
4675
}
4776

4877
public Block getStoneAt(int x, int y, int z) {
@@ -82,8 +111,12 @@ public void replaceStoneInChunk(LevelAccessor world, ChunkAccess chunk, BakedTer
82111

83112
for (; y >= chunk.getMinBuildHeight(); y--) {
84113
cursor.set(x, y, z);
85-
if (terrain.isReplaceable(chunk.getBlockState(cursor))) {
86-
chunk.setBlockState(cursor, pickReplacement(baseRockVal, geomeBase, y), false);
114+
BlockState current = chunk.getBlockState(cursor);
115+
if (terrain.isReplaceable(current)
116+
|| (realisticCoalLayers && current.getBlock() == Blocks.COAL_ORE)) {
117+
BlockState replacement = pickReplacement(baseRockVal, geomeBase, y);
118+
if (current.equals(replacement)) continue;
119+
chunk.setBlockState(cursor, replacement, false);
87120
changed = true;
88121
}
89122
}
@@ -131,4 +164,30 @@ private BlockState pickStateFromList(int value, BlockState[] list) {
131164
return list[whiteNoiseArray[(value / layerThickness) & 0xFF] % list.length];
132165
}
133166

167+
static BlockState[] resolveRockOrder(WorldGeologyProfile profile, String key,
168+
BlockState[] fallback) {
169+
if (!profile.hasCyanoRockOrder(key)) return fallback;
170+
List<BlockState> states = new ArrayList<>();
171+
for (String idText : profile.cyanoRockOrder(key)) {
172+
try {
173+
ResourceLocation id = ResourceLocation.parse(idText);
174+
Block block = BuiltInRegistries.BLOCK.containsKey(id)
175+
? BuiltInRegistries.BLOCK.get(id) : null;
176+
if (block != null && block != Blocks.AIR) {
177+
states.add(block.defaultBlockState());
178+
} else {
179+
LOGGER.warn("Legacy Mineralogy rock '{}' is not registered and will be omitted", id);
180+
}
181+
} catch (RuntimeException e) {
182+
LOGGER.warn("Legacy Mineralogy rock registry name '{}' is invalid and will be omitted", idText);
183+
}
184+
}
185+
if (states.isEmpty()) {
186+
LOGGER.warn("No snapshotted legacy Mineralogy rocks for '{}' are registered; "
187+
+ "using the matching provider family as a safe fallback", key);
188+
return fallback;
189+
}
190+
return states.toArray(new BlockState[states.size()]);
191+
}
192+
134193
}

‎src/main/java/zone/moddev/mc/orespawn/worldgen/LegacyConfigMigrator.java‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Path;
1111
import java.nio.file.StandardCopyOption;
1212
import java.util.ArrayList;
13+
import java.util.Arrays;
1314
import java.util.Comparator;
1415
import java.util.List;
1516
import java.util.Locale;
@@ -94,6 +95,7 @@ static JsonObject migrateIfNeeded(Path target, JsonObject defaults,
9495
report.add("Original files were retained unchanged. Review registry IDs and biome/dimension warnings before deleting them.");
9596
if (!write(target, migrated)) return null;
9697
writeReport(config, report);
98+
writeUpgradeReport(config, imported, report);
9799
LOGGER.info("Migrated {} legacy OreSpawn definitions into '{}'", imported, target);
98100
return migrated;
99101
}
@@ -354,6 +356,44 @@ private static void writeReport(Path config, List<String> lines) {
354356
}
355357
}
356358

359+
private static void writeUpgradeReport(Path config, int imported, List<String> detail) {
360+
List<String> lines = new ArrayList<>();
361+
lines.add("OreSpawn 4.0.6 Upgrade Report");
362+
lines.add("================================");
363+
lines.add("");
364+
lines.add("RESULT: Legacy OreSpawn settings were imported into the OS4 profile.");
365+
lines.add("- Spawn definitions imported: " + imported);
366+
lines.add("- Detailed translation report: "
367+
+ config.resolve("orespawn-migration/migration-report.txt").toAbsolutePath());
368+
for (String entry : detail) {
369+
if (entry.startsWith("Warning:") || entry.startsWith("Skipped")
370+
|| entry.startsWith("Clamped")) lines.add("- " + entry);
371+
}
372+
lines.add("");
373+
lines.add("Original legacy configuration files were retained unchanged.");
374+
writeTextAtomically(config.resolve("orespawn-upgrade-report.txt"), lines);
375+
}
376+
377+
private static void writeTextAtomically(Path path, List<String> lines) {
378+
Path temporary = path.resolveSibling(path.getFileName().toString() + ".tmp");
379+
try {
380+
Files.createDirectories(path.getParent());
381+
byte[] bytes = (String.join(System.lineSeparator(), lines) + System.lineSeparator())
382+
.getBytes(StandardCharsets.UTF_8);
383+
if (Files.isRegularFile(path) && Arrays.equals(Files.readAllBytes(path), bytes)) return;
384+
Files.write(temporary, bytes);
385+
try {
386+
Files.move(temporary, path, StandardCopyOption.ATOMIC_MOVE,
387+
StandardCopyOption.REPLACE_EXISTING);
388+
} catch (AtomicMoveNotSupportedException e) {
389+
Files.move(temporary, path, StandardCopyOption.REPLACE_EXISTING);
390+
}
391+
} catch (IOException e) {
392+
try { Files.deleteIfExists(temporary); } catch (IOException ignored) { }
393+
LOGGER.warn("Could not write OreSpawn upgrade report '{}'", path, e);
394+
}
395+
}
396+
357397
private static JsonObject object(JsonObject root, String key) {
358398
if (!root.has(key) || !root.get(key).isJsonObject()) root.add(key, new JsonObject());
359399
return root.getAsJsonObject(key);

0 commit comments

Comments
 (0)