Skip to content

Commit 8bd73e1

Browse files
committed
Fix OreSpawn settings crash on Minecraft 1.14.4
1 parent 3b043ff commit 8bd73e1

10 files changed

Lines changed: 158 additions & 16 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ jobs:
126126
if-no-files-found: error
127127
retention-days: 30
128128
path: |
129-
build/libs/OreSpawn-4.1.0.114041.jar
130-
build/libs/OreSpawn-4.1.0.114041-sources.jar
131-
build/libs/OreSpawn-4.1.0.114041-javadoc.jar
129+
build/libs/OreSpawn-4.1.1.114041.jar
130+
build/libs/OreSpawn-4.1.1.114041-sources.jar
131+
build/libs/OreSpawn-4.1.1.114041-javadoc.jar
132132
build/release/SHA256SUMS
133133
CHANGELOG.txt
134134

‎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.114041
2+
3+
* Fixed a crash when opening or editing OreSpawn's settings in development runs.
4+
The fix has also been checked in a normal Forge installation.
5+
16
Version 4.1.0.114041
27

38
* Reject invalid Geome IDs instead of silently renaming them.

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ End" policy used by mods such as Base Metals.
1717
This is not the unrelated mod that adds mobs and dimensions under the same
1818
name.
1919

20-
This branch builds target-qualified version `4.1.0.114041` for Minecraft 1.14.4
20+
This branch builds target-qualified version `4.1.1.114041` for Minecraft 1.14.4
2121
and Forge. It adds material-group ore arbitration, exact biome replacements,
2222
and a directory for installed provider mods to the OreSpawn 4.0.16 base. See the
2323
[versioning policy](docs/VERSIONS.md) for the encoding and release convention.
2424

25+
I've fixed a crash when opening or editing OreSpawn's settings in development
26+
runs. The fix has also been checked in a normal Forge installation.
27+
2528
## What Happens When It Is Installed?
2629

2730
OreSpawn is deliberately passive on its own. It does not replace stone, remove

‎docs/VERSIONS.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Examples:
5252
| Minecraft | Loader | Target | Example full OreSpawn version |
5353
| --- | --- | ---: | --- |
5454
| 1.13.2 | Forge | `113021` | `4.0.16.113021` |
55-
| 1.14.4 | Forge | `114041` | `4.1.0.114041` |
55+
| 1.14.4 | Forge | `114041` | `4.1.1.114041` |
5656
| 1.20.6 | Forge | `120061` | `4.0.6.120061` |
5757
| 1.21.11 | Forge | `121111` | `4.0.6.121111` |
5858
| 26.1.2 | Forge | `2601021` | `4.0.6.2601021` |
@@ -162,6 +162,9 @@ the loaded-mod directory, and exact new-terrain biome replacements. It keeps
162162
the `114041` target suffix, API major 1, and the target's existing registry
163163
identities while provider/global/world schemas advance to 5/8/7.
164164

165+
Version 4.1.1 fixes a crash in the settings screens during development runs.
166+
The same fix is included in the Forge 1.14.4 and 1.15.2 releases.
167+
165168
This provides three useful guarantees:
166169

167170
1. A functional version is not used to describe two unrelated change sets.

‎gradle.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mcp_version=20190829.143755
1919
mod_id=orespawn
2020
mod_name=MMD OreSpawn
2121
mod_license=LGPL-2.1
22-
mod_version=4.1.0.114041
22+
mod_version=4.1.1.114041
2323
mod_group=zone.moddev.mc.orespawn
2424
mod_authors=SkyBlade1978, dshadowwolf, the MMD Team
2525
mod_description=Configurable, provider-driven terrain, ore, and deposit generation.

‎gradle/release/artifacts.gradle‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def preparedReleaseDir = providers.gradleProperty('preparedReleaseDir')
9191
tasks.register('verifyReleaseConfiguration') {
9292
group = 'verification'
9393
doLast {
94-
if (project.mod_version != '4.1.0.114041'
94+
if (project.mod_version != '4.1.1.114041'
9595
|| project.mod_group != expectedMavenGroup
9696
|| project.minecraft_version != '1.14.4'
9797
|| project.forge_version != '28.2.26'
@@ -105,9 +105,9 @@ tasks.register('verifyReleaseConfiguration') {
105105
throw new GradleException('Unexpected dispatcher or Java target metadata')
106106
}
107107
List<String> expectedPublicArtifacts = [
108-
'OreSpawn-4.1.0.114041.jar',
109-
'OreSpawn-4.1.0.114041-sources.jar',
110-
'OreSpawn-4.1.0.114041-javadoc.jar'
108+
'OreSpawn-4.1.1.114041.jar',
109+
'OreSpawn-4.1.1.114041-sources.jar',
110+
'OreSpawn-4.1.1.114041-javadoc.jar'
111111
]
112112
if (base.archivesName.get() != expectedMavenArtifact
113113
|| expectedReleaseFiles.get().collect { it.toString() } != expectedPublicArtifacts) {
@@ -124,7 +124,7 @@ tasks.register('verifyReleaseConfiguration') {
124124
'src/main/java/zone/moddev/mc/orespawn/worldgen/LegacyMineralogyProfileMigration.java',
125125
'README.md', 'CHANGELOG.txt'
126126
].each { path ->
127-
if (!file(path).getText('UTF-8').contains('4.1.0.114041')) {
127+
if (!file(path).getText('UTF-8').contains('4.1.1.114041')) {
128128
throw new GradleException("Release identity missing from ${path}")
129129
}
130130
}

‎src/main/java/zone/moddev/mc/orespawn/client/TextFieldWidget.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ class TextFieldWidget extends net.minecraft.client.gui.widget.TextFieldWidget {
1414
}
1515

1616
void setValue(String value) {
17-
setText(value);
17+
// Official remapping gives the native method our alias name. Keep this
18+
// a superclass call so imported jars cannot dispatch back into this bridge.
19+
super.setText(value);
1820
}
1921

2022
String getValue() {
21-
return getText();
23+
return super.getText();
2224
}
2325

2426
void setMaxLength(int length) {
25-
setMaxStringLength(length);
27+
super.setMaxStringLength(length);
2628
}
2729

2830
void setBounds(int x, int y, int width, int height) {

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

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private static void writeUpgradeReport(Path worldRoot, Path configPath,
197197
Path report = worldRoot.resolve("serverconfig/orespawn-upgrade-report.txt");
198198
List<String> missing = missingBlocks(igneous, metamorphic, sedimentary);
199199
List<String> lines = new ArrayList<>();
200-
lines.add("OreSpawn 4.1.0.114041 Upgrade Report");
200+
lines.add("OreSpawn 4.1.1.114041 Upgrade Report");
201201
lines.add("================================");
202202
lines.add("");
203203
lines.add("RESULT: Existing Mineralogy " + identity.version + " world detected.");
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package zone.moddev.mc.orespawn.client;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.io.InputStream;
6+
import java.lang.reflect.Constructor;
7+
import java.lang.reflect.Method;
8+
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.params.ParameterizedTest;
11+
import org.junit.jupiter.params.provider.ValueSource;
12+
import org.objectweb.asm.ClassReader;
13+
import org.objectweb.asm.ClassVisitor;
14+
import org.objectweb.asm.ClassWriter;
15+
import org.objectweb.asm.MethodVisitor;
16+
import org.objectweb.asm.Opcodes;
17+
18+
import net.minecraft.client.gui.FontRenderer;
19+
20+
/** Exercises the name collision introduced when another mod uses official mappings. */
21+
public class TextFieldRemappingTest {
22+
private static final String WRAPPER = TextFieldWidget.class.getName().replace('.', '/');
23+
private static final String NATIVE = "net/minecraft/client/gui/widget/TextFieldWidget";
24+
private static final String REMAPPED_NATIVE = OfficialTextField.class.getName().replace('.', '/');
25+
26+
@ParameterizedTest
27+
@ValueSource(strings = { "setValue", "getValue", "setMaxLength" })
28+
void eachOfficialNameStillDelegatesToTheNativeWidget(String method) throws Exception {
29+
Object field = remappedField();
30+
if (method.equals("setValue")) {
31+
invoke(field.getClass(), field, method, String.class, "minecraft:stone");
32+
assertEquals("minecraft:stone", ((OfficialTextField) field).value);
33+
} else if (method.equals("setMaxLength")) {
34+
invoke(field.getClass(), field, method, int.class, 1024);
35+
assertEquals(1024, ((OfficialTextField) field).maximum);
36+
} else {
37+
assertEquals("", readValue(field.getClass(), field));
38+
}
39+
}
40+
41+
@Test
42+
void remappedWidgetPreservesLongValuesAndNativeLimits() throws Exception {
43+
Object field = remappedField();
44+
Class<?> remapped = field.getClass();
45+
String value = "minecraft:stone,minecraft:granite,minecraft:diorite,minecraft:andesite";
46+
47+
invoke(remapped, field, "setMaxLength", int.class, 1024);
48+
invoke(remapped, field, "setValue", String.class, value);
49+
assertEquals(value, readValue(remapped, field));
50+
invoke(remapped, field, "setMaxLength", int.class, 12);
51+
assertEquals(value.substring(0, 12), readValue(remapped, field));
52+
invoke(remapped, field, "setValue", String.class, "minecraft:granite");
53+
assertEquals("minecraft:gr", readValue(remapped, field));
54+
}
55+
56+
private Object remappedField() throws Exception {
57+
// Use the real compiled wrapper, remapping the three native MCP names as
58+
// ForgeGradle does when importing an SRG jar into an official-mapped project.
59+
ClassWriter writer = new ClassWriter(0);
60+
try (InputStream input = TextFieldWidget.class.getResourceAsStream("TextFieldWidget.class")) {
61+
new ClassReader(input).accept(new ClassVisitor(Opcodes.ASM6, writer) {
62+
@Override
63+
public void visit(int version, int access, String name, String signature,
64+
String superName, String[] interfaces) {
65+
super.visit(version, access, name, signature, REMAPPED_NATIVE, interfaces);
66+
}
67+
68+
@Override
69+
public MethodVisitor visitMethod(int access, String name, String descriptor,
70+
String signature, String[] exceptions) {
71+
return new MethodVisitor(Opcodes.ASM6,
72+
super.visitMethod(access, name, descriptor, signature, exceptions)) {
73+
@Override
74+
public void visitMethodInsn(int opcode, String owner, String name,
75+
String descriptor, boolean isInterface) {
76+
if (owner.equals(WRAPPER) || owner.equals(NATIVE)) {
77+
if (name.equals("setText")) name = "setValue";
78+
if (name.equals("getText")) name = "getValue";
79+
if (name.equals("setMaxStringLength")) name = "setMaxLength";
80+
}
81+
super.visitMethodInsn(opcode, owner.equals(NATIVE) ? REMAPPED_NATIVE : owner,
82+
name, descriptor, isInterface);
83+
}
84+
};
85+
}
86+
}, 0);
87+
}
88+
Class<?> remapped = new ClassLoader(getClass().getClassLoader()) {
89+
Class<?> defineWrapper() {
90+
byte[] bytes = writer.toByteArray();
91+
return defineClass(TextFieldWidget.class.getName(), bytes, 0, bytes.length);
92+
}
93+
}.defineWrapper();
94+
Constructor<?> constructor = remapped.getDeclaredConstructor(FontRenderer.class,
95+
int.class, int.class, int.class, int.class, String.class);
96+
constructor.setAccessible(true);
97+
return constructor.newInstance(null, 0, 0, 200, 20, "host_blocks");
98+
}
99+
100+
private static void invoke(Class<?> type, Object field, String name, Class<?> parameter,
101+
Object value) throws Exception {
102+
Method method = type.getDeclaredMethod(name, parameter);
103+
method.setAccessible(true);
104+
method.invoke(field, value);
105+
}
106+
107+
private static Object readValue(Class<?> type, Object field) throws Exception {
108+
Method method = type.getDeclaredMethod("getValue");
109+
method.setAccessible(true);
110+
return method.invoke(field);
111+
}
112+
113+
/** Small native-widget stand-in: only naming and virtual dispatch matter here. */
114+
public static class OfficialTextField {
115+
public int x, y, width, height;
116+
private int maximum = 32;
117+
private String value = "";
118+
119+
public OfficialTextField(FontRenderer font, int x, int y, int width, int height, String label) { }
120+
public void setValue(String value) {
121+
this.value = value.substring(0, Math.min(maximum, value.length()));
122+
}
123+
public String getValue() { return value; }
124+
public void setMaxLength(int maximum) {
125+
this.maximum = maximum;
126+
value = value.substring(0, Math.min(maximum, value.length()));
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)