|
7 | 7 | import org.spongepowered.asm.mixin.Mixin; |
8 | 8 | import org.spongepowered.asm.mixin.Pseudo; |
9 | 9 | import org.spongepowered.asm.mixin.Shadow; |
| 10 | +import org.spongepowered.asm.mixin.Unique; |
| 11 | + |
| 12 | +import java.lang.reflect.Field; |
| 13 | +import java.lang.reflect.Method; |
| 14 | +import java.util.List; |
10 | 15 |
|
11 | 16 | @Pseudo |
12 | 17 | @MoulConfig |
|
15 | 20 | //#endif |
16 | 21 | @Mixin(value = GuiOptionEditorDropdown.class, remap = false) |
17 | 22 | public class Mixin_GuiOptionEditorDropdown implements MoulConfigGuiOptionEditorDropdownAccessor { |
18 | | - |
19 | | - @Shadow |
20 | | - private String[] values; |
21 | 23 | @Shadow |
22 | 24 | private boolean useOrdinal; |
23 | 25 | @Shadow |
24 | 26 | private Enum<?>[] constants; |
25 | 27 |
|
| 28 | + @Unique |
| 29 | + private String[] oneconfig$resolvedValues; |
| 30 | + |
| 31 | + // MoulConfig 3.x uses String[] for this field, 4.x uses List<StructuredText>. |
| 32 | + // Reflection avoids the @Shadow descriptor mismatch that breaks mixin application. |
26 | 33 | public String[] oneconfig$values() { |
27 | | - return this.values; |
| 34 | + if (oneconfig$resolvedValues != null) return oneconfig$resolvedValues; |
| 35 | + try { |
| 36 | + Field f = this.getClass().getDeclaredField("values"); |
| 37 | + f.setAccessible(true); |
| 38 | + Object val = f.get(this); |
| 39 | + if (val instanceof String[]) { |
| 40 | + oneconfig$resolvedValues = (String[]) val; |
| 41 | + } else if (val instanceof List<?>) { |
| 42 | + List<?> list = (List<?>) val; |
| 43 | + String[] result = new String[list.size()]; |
| 44 | + for (int i = 0; i < list.size(); i++) { |
| 45 | + Object item = list.get(i); |
| 46 | + if (item instanceof String) { |
| 47 | + result[i] = (String) item; |
| 48 | + } else { |
| 49 | + try { |
| 50 | + Method getText = item.getClass().getMethod("getText"); |
| 51 | + result[i] = (String) getText.invoke(item); |
| 52 | + } catch (Exception e) { |
| 53 | + result[i] = item.toString(); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + oneconfig$resolvedValues = result; |
| 58 | + } else { |
| 59 | + oneconfig$resolvedValues = new String[0]; |
| 60 | + } |
| 61 | + } catch (Exception e) { |
| 62 | + oneconfig$resolvedValues = new String[0]; |
| 63 | + } |
| 64 | + return oneconfig$resolvedValues; |
28 | 65 | } |
29 | 66 |
|
30 | 67 | public boolean oneconfig$useOrdinal() { |
|
0 commit comments