Skip to content

Commit 101fd12

Browse files
authored
Keep saved ore settings when providers rename rules
2 parents c45ea2a + e9ba2db commit 101fd12

15 files changed

Lines changed: 1435 additions & 13 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ jobs:
125125
if-no-files-found: error
126126
retention-days: 30
127127
path: |
128-
build/libs/OreSpawn-4.1.0.2601021.jar
129-
build/libs/OreSpawn-4.1.0.2601021-sources.jar
130-
build/libs/OreSpawn-4.1.0.2601021-javadoc.jar
128+
build/libs/OreSpawn-4.1.1.2601021.jar
129+
build/libs/OreSpawn-4.1.1.2601021-sources.jar
130+
build/libs/OreSpawn-4.1.1.2601021-javadoc.jar
131131
build/release/SHA256SUMS
132132
CHANGELOG.txt
133133

‎CHANGELOG.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 4.1.1.2601021
2+
3+
* Stop recognised ore-rule renames from adding a second generation pass to existing profiles.
4+
* Keep saved ore settings and show matching modern rules as disabled, editable alternatives.
5+
* Preserve explicit choices, deleted rules, and deliberately separate deposits.
6+
17
Version 4.1.0.2601021
28

39
* Leave imported vanilla ores inactive while Manage Vanilla Ores is off.

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ Its OS3 compatibility layer preserves ranged legacy block budgets, exclusive
1414
legacy height ceilings, and the historical "all dimensions except Nether and
1515
End" policy used by mods such as Base Metals.
1616

17+
The [provider-merge repair](docs/MIGRATION.md#retained-provider-rules) keeps
18+
recognised legacy ore settings when modern provider IDs are first added.
19+
Matching alternatives remain visible but disabled, so upgrading does not add
20+
a second generation pass for the same deposit.
21+
1722
This is not the unrelated mod that adds mobs and dimensions under the same
1823
name.
1924

20-
This branch builds target-qualified version `4.1.0.2601021`: the OreSpawn 4.1
25+
This branch builds target-qualified version `4.1.1.2601021`: the OreSpawn 4.1
2126
feature set for Minecraft 26.1.2 and Forge. See the
2227
[versioning policy](docs/VERSIONS.md) for the encoding and release convention.
2328

‎docs/MIGRATION.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,49 @@ When legacy OreSpawn rules are translated, a concise player-facing summary is
1717
also written atomically to `config/orespawn-upgrade-report.txt`; the existing
1818
detailed rule report remains at `config/orespawn-migration/migration-report.txt`.
1919

20+
## Retained Provider Rules
21+
22+
Some existing OreSpawn 4 profiles still use rule IDs declared by older
23+
providers. A changed rule ID must not silently add another generation pass
24+
for the same deposit. The provider-merge repair recognises two positive
25+
lineages:
26+
27+
- OreSpawn's own imported `orespawn:legacy/<provider>/...` rules.
28+
- Base Metals' historical `basemetals:legacy/<material>_ore` to
29+
`basemetals:ore/<material>` replacements for coldiron, adamantine, starsteel,
30+
tin, lead, zinc, silver, mercury, nickel and platinum. Base Metals itself
31+
declared the old IDs in its maintained 1.10/1.12 providers; this is an exact
32+
compatibility list, not a guess based on the word `legacy`.
33+
34+
The merge requires one saved rule and one current candidate with the same
35+
single output, default metadata, and exact dimension/selector and effective
36+
placement-channel footprint. It does not infer equivalence from overlapping
37+
dimensions, a shared material name, or an `orphaned_provider` flag. Mixed
38+
outputs, different deep outputs, and ambiguous matches retain the existing
39+
merge behaviour rather than being guessed away.
40+
Explicit conflicting `source_provider` or fallback `source_mod` ownership is
41+
not treated as a replacement. The importer's neutral `legacy` owner marker is
42+
accepted only with OreSpawn's own imported IDs.
43+
44+
When that relationship is unambiguous, OreSpawn adds the missing modern rule
45+
as a complete **disabled** alternative. The saved rule's rates, hosts, heights,
46+
pattern, enablement and policy choices remain authoritative. Disabled and
47+
zero-frequency settings count as saved choices too. Fresh installations keep
48+
the provider's ordinary defaults.
49+
50+
Players can enable the alternative in the normal ore settings. Later merges
51+
preserve that explicit choice; they also preserve existing modern rules and
52+
intentional deletions recorded in `known_ores`. Already-present old/new rule
53+
combinations are not automatically cleaned up, since the player may have
54+
chosen both. A deleted historical Base Metals rule recorded in `known_ores`
55+
also keeps its mapped modern replacement disabled; that exact ID relationship
56+
is known even though the old placement payload has been removed. Other custom
57+
deposits do not cancel that recorded deletion and are not changed. Deleted
58+
imports without an explicit historical mapping are not matched by guessing an
59+
output from their filename.
60+
Review ambiguous profiles explicitly. This repair does not change API
61+
versions, schemas, or already-generated chunks.
62+
2063
## Existing Mineralogy Worlds
2164

2265
An already-generated world without an OreSpawn per-world profile is inspected

‎docs/VERSIONS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Examples:
6262
| 1.20.6 | Forge | `120061` | `4.0.16.120061` |
6363
| 1.21.1 | Forge | `121011` | `4.0.16.121011` |
6464
| 1.21.11 | Forge | `121111` | `4.0.16.121111` |
65-
| 26.1.2 | Forge | `2601021` | `4.1.0.2601021` |
65+
| 26.1.2 | Forge | `2601021` | `4.1.1.2601021` |
6666
| 26.2 | Forge | `2602001` | `4.0.6.2602001` |
6767
| 26.2 | NeoForge | `2602002` | `4.0.6.2602002` |
6868

‎gradle.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ mapping_version=26.1.2
4343
mod_id=orespawn
4444
mod_name=MMD OreSpawn
4545
mod_license=LGPL-2.1
46-
mod_version=4.1.0.2601021
46+
mod_version=4.1.1.2601021
4747
mod_group=zone.moddev.mc.orespawn
4848
mod_authors=SkyBlade1978, dshadowwolf, the MMD Team
4949
mod_vendor=Minecraft Mod Development

‎gradle/release/artifacts.gradle‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def preparedReleaseDir = providers.gradleProperty('preparedReleaseDir')
7979
tasks.register('verifyReleaseConfiguration') {
8080
group = 'verification'
8181
doLast {
82-
if (project.mod_version != '4.1.0.2601021'
82+
if (project.mod_version != '4.1.1.2601021'
8383
|| project.mod_group != expectedMavenGroup
8484
|| project.minecraft_version != '26.1.2'
8585
|| project.forge_version != '64.0.9'
@@ -93,9 +93,9 @@ tasks.register('verifyReleaseConfiguration') {
9393
throw new GradleException('Unexpected dispatcher or Java target metadata')
9494
}
9595
List<String> expectedPublicArtifacts = [
96-
'OreSpawn-4.1.0.2601021.jar',
97-
'OreSpawn-4.1.0.2601021-sources.jar',
98-
'OreSpawn-4.1.0.2601021-javadoc.jar'
96+
'OreSpawn-4.1.1.2601021.jar',
97+
'OreSpawn-4.1.1.2601021-sources.jar',
98+
'OreSpawn-4.1.1.2601021-javadoc.jar'
9999
]
100100
if (base.archivesName.get() != expectedMavenArtifact
101101
|| expectedReleaseFiles.get().collect { it.toString() } != expectedPublicArtifacts) {
@@ -112,7 +112,7 @@ tasks.register('verifyReleaseConfiguration') {
112112
'src/main/java/zone/moddev/mc/orespawn/worldgen/LegacyMineralogyProfileMigration.java',
113113
'README.md', 'CHANGELOG.txt'
114114
].each { path ->
115-
if (!file(path).getText('UTF-8').contains('4.1.0.2601021')) {
115+
if (!file(path).getText('UTF-8').contains('4.1.1.2601021')) {
116116
throw new GradleException("Release identity missing from ${path}")
117117
}
118118
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package zone.moddev.mc.orespawn.integration;
2+
3+
import java.util.HashSet;
4+
import java.util.List;
5+
import java.util.Set;
6+
7+
import com.google.gson.JsonElement;
8+
import com.google.gson.JsonObject;
9+
import net.minecraft.resources.Identifier;
10+
11+
/** Conservative matching at provider merge time, never in chunk generation. */
12+
final class RetainedProviderOreDefaults {
13+
14+
private static final Set<String> BASE_METALS_LEGACY_MATERIALS = Set.of(
15+
"coldiron", "adamantine", "starsteel", "tin", "lead", "zinc",
16+
"silver", "mercury", "nickel", "platinum");
17+
18+
private record Placement(String kind, String dimension, String channel) {}
19+
20+
private RetainedProviderOreDefaults() {}
21+
22+
static String predecessor(String owner, String currentId, JsonObject current,
23+
JsonObject defaults, JsonObject saved, Set<String> known) {
24+
String output = singletonOutput(currentId, current);
25+
Set<Placement> scope = placements(current);
26+
if (output == null || scope == null || scope.isEmpty()) return null;
27+
String historical = historicalPredecessor(owner, currentId, output);
28+
if (historical != null && known.contains(historical) && !saved.has(historical)) return historical;
29+
30+
int replacements = 0;
31+
for (var entry : defaults.entrySet()) {
32+
if (equivalentOutputAndScope(entry.getKey(), entry.getValue(), output, scope)) replacements++;
33+
}
34+
if (replacements != 1) return null;
35+
36+
String retained = null;
37+
for (var entry : saved.entrySet()) {
38+
if (!equivalentOutputAndScope(entry.getKey(), entry.getValue(), output, scope)) continue;
39+
if (retained != null) return null;
40+
retained = entry.getKey();
41+
}
42+
return retained != null && declaredPredecessor(owner, currentId, output, retained, saved.getAsJsonObject(retained))
43+
? retained : null;
44+
}
45+
46+
private static boolean declaredPredecessor(String owner, String currentId, String output, String savedId, JsonObject saved) {
47+
String importedPrefix = "orespawn:legacy/" + owner + "/";
48+
boolean imported = savedId.startsWith(importedPrefix) && savedId.length() > importedPrefix.length();
49+
if (saved.has("source_provider")) {
50+
if (!owner.equals(text(saved.get("source_provider")))) return false;
51+
} else if (saved.has("source_mod")) {
52+
String fallbackOwner = text(saved.get("source_mod"));
53+
if (!owner.equals(fallbackOwner) && !(imported && "legacy".equals(fallbackOwner))) return false;
54+
}
55+
if (imported) return true;
56+
return savedId.equals(historicalPredecessor(owner, currentId, output));
57+
}
58+
59+
private static String historicalPredecessor(String owner, String currentId, String output) {
60+
// Base Metals' maintained 1.10/1.12 providers declared these IDs themselves.
61+
// A generic provider's "legacy/" prefix is not evidence of a replacement.
62+
if (!owner.equals("basemetals")) return null;
63+
for (String material : BASE_METALS_LEGACY_MATERIALS) {
64+
if (currentId.equals("basemetals:ore/" + material)
65+
&& output.equals("basemetals:" + material + "_ore")) return "basemetals:legacy/" + material + "_ore";
66+
}
67+
return null;
68+
}
69+
70+
private static boolean equivalentOutputAndScope(String id, JsonElement rule, String output, Set<Placement> scope) {
71+
return rule.isJsonObject() && output.equals(singletonOutput(id, rule.getAsJsonObject()))
72+
&& scope.equals(placements(rule.getAsJsonObject()));
73+
}
74+
75+
private static String singletonOutput(String id, JsonObject rule) {
76+
String output = rule.has("block") ? text(rule.get("block")) : id;
77+
Identifier parsed = output == null ? null : Identifier.tryParse(output);
78+
if (parsed == null || !defaultMetadata(rule)) return null;
79+
output = parsed.toString();
80+
if (rule.has("deep_output") && !output.equals(text(rule.get("deep_output")))) return null;
81+
if (rule.has("outputs")) {
82+
JsonElement values = rule.get("outputs");
83+
if (!values.isJsonArray() || values.getAsJsonArray().size() != 1
84+
|| !values.getAsJsonArray().get(0).isJsonObject()) return null;
85+
JsonObject only = values.getAsJsonArray().get(0).getAsJsonObject();
86+
if (!output.equals(text(only.get("block"))) || !defaultMetadata(only)) return null;
87+
}
88+
return output;
89+
}
90+
91+
private static boolean defaultMetadata(JsonObject rule) {
92+
JsonElement metadata = rule.get("metadata");
93+
return metadata == null || metadata.isJsonPrimitive() && metadata.getAsJsonPrimitive().isNumber()
94+
&& metadata.getAsBigDecimal().signum() == 0;
95+
}
96+
97+
private static Set<Placement> placements(JsonObject rule) {
98+
Set<Placement> result = new HashSet<>();
99+
for (String kind : List.of("dimensions", "dimension_selectors")) {
100+
JsonElement table = rule.get(kind);
101+
if (table == null) continue;
102+
if (!table.isJsonObject()) return null;
103+
for (var entry : table.getAsJsonObject().entrySet()) {
104+
if (Identifier.tryParse(entry.getKey()) == null || !entry.getValue().isJsonObject()) return null;
105+
// Disabled and zero-rate placements are saved choices too.
106+
result.add(new Placement(kind, entry.getKey(), channel(entry.getValue().getAsJsonObject())));
107+
}
108+
}
109+
return result;
110+
}
111+
112+
private static String channel(JsonObject placement) {
113+
Identifier explicit = identifier(placement.get("placement_channel"));
114+
if (explicit != null) return explicit.toString();
115+
JsonElement pattern = placement.get("pattern");
116+
Identifier type = pattern != null && pattern.isJsonObject()
117+
? identifier(pattern.getAsJsonObject().get("type")) : null;
118+
String legacy = text(pattern);
119+
if (type == null && legacy != null && legacy.indexOf(':') >= 0) type = Identifier.tryParse(legacy);
120+
return type == null ? "orespawn:standard" : type.toString();
121+
}
122+
123+
private static Identifier identifier(JsonElement value) {
124+
String name = text(value);
125+
return name == null ? null : Identifier.tryParse(name);
126+
}
127+
128+
private static String text(JsonElement value) {
129+
return value != null && value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()
130+
? value.getAsString() : null;
131+
}
132+
}

‎src/main/java/zone/moddev/mc/orespawn/integration/WorldgenIntegrationManager.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ public static synchronized boolean mergeProviderDefinitions(JsonObject target) {
248248
String id = entry.getKey();
249249
if (!targetSection.has(id) && !known.contains(id)) {
250250
JsonObject value = entry.getValue().getAsJsonObject().deepCopy();
251+
if ("ores".equals(sectionName)) {
252+
String retained = RetainedProviderOreDefaults.predecessor(
253+
provider.modId, id, value, providerSection, targetSection, known);
254+
if (retained != null) {
255+
value.addProperty("enabled", false);
256+
LOGGER.info("Preserved legacy ore choice '{}'; added provider alternative '{}' disabled", retained, id);
257+
}
258+
}
251259
if (!"biome_rules".equals(sectionName)) {
252260
value.addProperty("source_provider", provider.modId);
253261
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ private static void writeReport(Path config, List<String> lines) {
358358

359359
private static void writeUpgradeReport(Path config, int imported, List<String> detail) {
360360
List<String> lines = new ArrayList<>();
361-
lines.add("OreSpawn 4.1.0.2601021 Upgrade Report");
361+
lines.add("OreSpawn 4.1.1.2601021 Upgrade Report");
362362
lines.add("================================");
363363
lines.add("");
364364
lines.add("RESULT: Legacy OreSpawn settings were imported into the OS4 profile.");

0 commit comments

Comments
 (0)