|
6 | 6 | import com.coflnet.gui.RenderUtils; |
7 | 7 | import com.coflnet.models.TextElement; |
8 | 8 | import com.google.gson.Gson; |
9 | | -import com.google.gson.reflect.TypeToken; |
10 | 9 | import net.minecraft.client.MinecraftClient; |
11 | 10 | import net.minecraft.client.gui.DrawContext; |
12 | 11 | import net.minecraft.client.gui.screen.ingame.HandledScreen; |
|
25 | 24 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
26 | 25 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
27 | 26 |
|
28 | | -import java.lang.reflect.Type; |
29 | 27 | import java.net.URI; |
30 | 28 | import java.util.List; |
31 | 29 |
|
@@ -126,12 +124,20 @@ protected void updateTextWithJson(DescriptionHandler.DescModification[] lines) { |
126 | 124 | } |
127 | 125 |
|
128 | 126 | try { |
129 | | - Type listType = new TypeToken<List<TextElement>>(){}.getType(); |
130 | | - List<TextElement> textElements = gson.fromJson(jsonText, listType); |
131 | | - |
| 127 | + TextElement[] textElements = gson.fromJson(jsonText, TextElement[].class); |
| 128 | + if (textElements == null || textElements.length == 0) { |
| 129 | + MutableText fallbackText = Text.literal(descModification.value); |
| 130 | + interactiveTextLines.add(fallbackText); |
| 131 | + int width = MinecraftClient.getInstance().textRenderer.getWidth(fallbackText); |
| 132 | + if (width > maxWidth) { |
| 133 | + maxWidth = width; |
| 134 | + } |
| 135 | + continue; |
| 136 | + } |
| 137 | + |
132 | 138 | MutableText lineText = Text.empty(); |
133 | | - for (int i = 0; i < textElements.size(); i++) { |
134 | | - TextElement element = textElements.get(i); |
| 139 | + for (int i = 0; i < textElements.length; i++) { |
| 140 | + TextElement element = textElements[i]; |
135 | 141 | MutableText elementText = Text.literal(element.text); |
136 | 142 |
|
137 | 143 | // Add click event |
|
0 commit comments