Skip to content

Commit a397353

Browse files
authored
Keep saved provider ore settings on Forge 26.2
Preserve saved ore choices and add recognised renamed rules as disabled alternatives. Release 4.1.1.2602001 for Forge 26.2.
2 parents c64d189 + dcaaa93 commit a397353

15 files changed

Lines changed: 1467 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.2602001.jar
129-
build/libs/OreSpawn-4.1.0.2602001-sources.jar
130-
build/libs/OreSpawn-4.1.0.2602001-javadoc.jar
128+
build/libs/OreSpawn-4.1.1.2602001.jar
129+
build/libs/OreSpawn-4.1.1.2602001-sources.jar
130+
build/libs/OreSpawn-4.1.1.2602001-javadoc.jar
131131
build/release/SHA256SUMS
132132
CHANGELOG.txt
133133

‎CHANGELOG.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 4.1.1.2602001 (local candidate)
2+
3+
* Keep saved ore settings when a provider renames a recognised rule. Add the
4+
matching modern rule as a disabled alternative rather than another ore pass.
5+
16
Version 4.1.0.2602001
27

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

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ 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+
Recognised provider rule renames keep the saved ore settings and add the modern
18+
rule as a disabled, editable alternative, avoiding an extra generation pass.
19+
See [retained provider rules](docs/MIGRATION.md#retained-provider-rules).
20+
1721
This is not the unrelated mod that adds mobs and dimensions under the same
1822
name.
1923

20-
This branch builds target-qualified version `4.1.0.2602001`: the OreSpawn 4.1
24+
This branch builds target-qualified version `4.1.1.2602001`: the OreSpawn 4.1
2125
feature set for Minecraft 26.2 and Forge. See the
2226
[versioning policy](docs/VERSIONS.md) for the encoding and release convention.
2327

‎docs/MIGRATION.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
# Migration
22

3+
## Retained Provider Rules
4+
5+
An older profile can keep an ore rule after its provider renames that rule.
6+
OreSpawn must not add a second generation pass just because the ID changed.
7+
The merge recognises OreSpawn's imported `orespawn:legacy/<provider>/...`
8+
rules and the following exact Base Metals replacements:
9+
10+
- `basemetals:legacy/<material>_ore` to `basemetals:ore/<material>` for
11+
coldiron, adamantine, starsteel, tin, lead, zinc, silver, mercury, nickel
12+
and platinum.
13+
14+
A match needs one saved rule and one provider candidate with the same single
15+
output, default metadata, and dimension/selector and effective placement-channel
16+
footprint. Conflicting provider ownership, mixed outputs, different deep outputs
17+
and ambiguous matches are not treated as replacements. A generic mod's
18+
`legacy/` name is not enough evidence.
19+
20+
For a recognised match, the missing modern rule is added as a complete,
21+
disabled alternative. The saved rule keeps its rates, hosts, heights, pattern,
22+
enablement and source choices, including disabled and zero-rate settings.
23+
Fresh worlds still use the provider's normal defaults.
24+
25+
You can enable the alternative in the ore settings. Later merges retain that
26+
choice, existing modern rules and recorded deletions. A recorded deletion of
27+
one of the historical Base Metals IDs also leaves its mapped replacement
28+
disabled. Deleted imports without an exact mapping are not guessed from their
29+
names.
30+
31+
This repair does not automatically remove an already-saved historical
32+
Base Metals/modern pair: both may have been selected deliberately. Review
33+
ambiguous or previously affected profiles before changing their choices.
34+
It does not alter generated chunks, public APIs or saved formats.
35+
336
## Provider-Aware OS3 Imports
437

538
When an OreSpawn 2/3 file is named for an installed provider, the migrator now

‎docs/VERSIONS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Examples:
6363
| 1.21.1 | Forge | `121011` | `4.0.16.121011` |
6464
| 1.21.11 | Forge | `121111` | `4.0.16.121111` |
6565
| 26.1.2 | Forge | `2601021` | `4.0.16.2601021` |
66-
| 26.2 | Forge | `2602001` | `4.1.0.2602001` |
66+
| 26.2 | Forge | `2602001` | `4.1.1.2602001` |
6767
| 26.2 | NeoForge | `2602002` | `4.0.6.2602002` |
6868

6969
Historical MMD releases may also have four numeric components but may have used

‎gradle.properties‎

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

‎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 saved 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.2602001 Upgrade Report");
361+
lines.add("OreSpawn 4.1.1.2602001 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)