Skip to content

Commit 887a40d

Browse files
committed
Make compile on 1.16
Still need to make it override NEC
1 parent 69e4fef commit 887a40d

32 files changed

+348
-179
lines changed

build.gradle.kts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import dev.deftu.gradle.utils.GameSide
44
import dev.deftu.gradle.utils.includeOrShade
5+
import dev.deftu.gradle.utils.version.MinecraftVersion
6+
import dev.deftu.gradle.utils.version.MinecraftVersions
57

68
plugins {
79
java
@@ -44,8 +46,46 @@ toolkitLoomHelper {
4446
}
4547
}
4648

49+
repositories {
50+
maven("https://api.modrinth.com/maven") {
51+
content { includeGroup("maven.modrinth") }
52+
}
53+
}
54+
4755
dependencies {
4856
implementation(includeOrShade("gs.mclo:api:3.0.1")!!)
57+
if (mcData.version >= MinecraftVersions.VERSION_1_16) {
58+
data class CompatDependency(
59+
val forge: String,
60+
val fabric: String,
61+
val neoforge: String
62+
)
63+
64+
fun DependencyHandlerScope.modImplementationCompat(notation: CompatDependency?) {
65+
notation?.let {
66+
when {
67+
mcData.isNeoForge -> modImplementation(it.neoforge)
68+
mcData.isForge -> modImplementation(it.forge)
69+
mcData.isFabric -> modImplementation(it.fabric)
70+
else -> error("Unsupported loader type: ${mcData.loader}")
71+
}
72+
}
73+
}
74+
75+
fun nec(mcVersion: String, modVersion: String) =
76+
mcVersion to CompatDependency(
77+
fabric = "maven.modrinth:notenoughcrashes:$modVersion+$mcVersion-fabric",
78+
forge = "maven.modrinth:notenoughcrashes:$modVersion+$mcVersion-forge",
79+
neoforge = "maven.modrinth:notenoughcrashes:$modVersion+$mcVersion-neoforge"
80+
)
81+
82+
val nec = mapOf(
83+
nec("1.16.5", "4.1.4"),
84+
nec("1.17.1", "4.1.4")
85+
)
86+
87+
modImplementationCompat(nec[mcData.version.toString()])
88+
}
4989
}
5090

5191
tasks {

root.gradle.kts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ preprocess {
1010
// "1.8.9-forge"(10809, "srg")
1111
// }
1212

13-
"1.12.2-forge"(11202, "srg") {
14-
"1.12.2-fabric"(11202, "yarn") {
15-
"1.8.9-fabric"(10809, "yarn") {
16-
"1.8.9-forge"(10809, "srg")
13+
"1.16.5-fabric"(11605, "yarn") {
14+
"1.16.5-forge"(11605, "srg") {
15+
"1.12.2-forge"(11202, "srg", rootProject.file("versions/1.16.5-1.8.9.txt")) {
16+
"1.12.2-fabric"(11202, "yarn") {
17+
"1.8.9-fabric"(10809, "yarn") {
18+
"1.8.9-forge"(10809, "srg")
19+
}
20+
}
1721
}
1822
}
1923
}

settings.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ listOf(
4343
"1.8.9-forge",
4444
"1.8.9-fabric",
4545
"1.12.2-forge",
46-
"1.12.2-fabric"
46+
"1.12.2-fabric",
47+
"1.16.5-forge",
48+
"1.16.5-fabric",
4749
).forEach { version ->
4850
include(":$version")
4951
project(":$version").apply {

src/main/java/org/polyfrost/crashpatch/hooks/StacktraceDeobfuscator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.polyfrost.crashpatch.hooks;
22

3+
//#if MC<1.13
4+
35
import java.io.File;
46
import java.io.FileOutputStream;
57
import java.net.HttpURLConnection;
@@ -110,3 +112,4 @@ public String deobfuscateMethodName(String srgName) {
110112
return mcpName != null ? mcpName : srgName;
111113
}
112114
}
115+
//#endif
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package org.polyfrost.crashpatch.mixin;
22

33
import net.minecraft.client.gui.GuiDisconnected;
4-
import net.minecraft.util.IChatComponent;
54
import org.spongepowered.asm.mixin.Mixin;
65
import org.spongepowered.asm.mixin.gen.Accessor;
76

87
@Mixin(GuiDisconnected.class)
98
public interface AccessorGuiDisconnected {
10-
@Accessor("message")
11-
IChatComponent getMessage();
12-
139
@Accessor("reason")
14-
String getReason();
10+
//#if MC<=1.12.2
11+
String
12+
//#else
13+
//$$ net.minecraft.network.chat.Component
14+
//#endif
15+
getReason();
1516
}

src/main/java/org/polyfrost/crashpatch/mixin/MixinCrashReport.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import org.polyfrost.crashpatch.identifier.ModIdentifier;
1010
import org.polyfrost.crashpatch.hooks.CrashReportHook;
11-
import org.polyfrost.crashpatch.hooks.StacktraceDeobfuscator;
1211
import net.minecraft.crash.CrashReport;
1312
import org.polyfrost.crashpatch.identifier.ModMetadata;
1413
import org.spongepowered.asm.mixin.Final;
@@ -32,12 +31,14 @@ public String getSuspectedCrashPatchMods() {
3231

3332
@Inject(method = "populateEnvironment", at = @At("TAIL"))
3433
private void afterPopulateEnvironment(CallbackInfo ci) {
35-
ModMetadata susMod = ModIdentifier.INSTANCE.identifyFromStacktrace(cause);
34+
ModMetadata susMod = ModIdentifier.INSTANCE.identifyFromStacktrace((CrashReport) (Object) this, this.cause);
3635
crashpatch$suspectedMod = (susMod == null ? "Unknown" : susMod.getName());
3736
}
3837

38+
//#if MC<1.13
3939
@Inject(method = "populateEnvironment", at = @At("HEAD"))
4040
private void beforePopulateEnvironment(CallbackInfo ci) {
41-
StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(cause);
41+
org.polyfrost.crashpatch.hooks.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(this.cause);
4242
}
43+
//#endif
4344
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.polyfrost.crashpatch.mixin;
22

3-
import org.polyfrost.crashpatch.hooks.StacktraceDeobfuscator;
43
import net.minecraft.crash.CrashReportCategory;
54
import org.spongepowered.asm.mixin.Mixin;
65
import org.spongepowered.asm.mixin.injection.At;
@@ -10,8 +9,10 @@
109

1110
@Mixin(CrashReportCategory.class)
1211
public class MixinCrashReportCategory {
12+
//#if MC<1.13
1313
@Inject(method = "getPrunedStackTrace", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;getStackTrace()[Ljava/lang/StackTraceElement;", shift = At.Shift.BY, by = 2, ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD)
1414
private void afterGetStacktrace(int size, CallbackInfoReturnable<Integer> cir, StackTraceElement[] stackTrace) {
15-
StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(stackTrace);
15+
org.polyfrost.crashpatch.hooks.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(stackTrace);
1616
}
17+
//#endif
1718
}

src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiConnecting.java

Lines changed: 6 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import dev.deftu.omnicore.client.OmniDesktop;
44
import dev.deftu.textile.minecraft.MCTextFormat;
5-
import org.polyfrost.crashpatch.CrashPatch;
5+
import org.polyfrost.crashpatch.client.CrashPatchClient;
66
import org.polyfrost.crashpatch.hooks.MinecraftHook;
77
import net.minecraft.client.Minecraft;
8-
import net.minecraft.client.gui.FontRenderer;
98
import net.minecraft.client.gui.GuiScreen;
109
import net.minecraft.client.multiplayer.GuiConnecting;
1110
import org.spongepowered.asm.mixin.Mixin;
@@ -17,6 +16,7 @@
1716
import java.awt.*;
1817
import java.io.IOException;
1918
import java.net.URI;
19+
import java.util.List;
2020

2121
@Mixin(GuiConnecting.class)
2222
public class MixinGuiConnecting extends GuiScreen {
@@ -30,7 +30,7 @@ private void drawWarningText(int mouseX, int mouseY, float partialTicks, Callbac
3030

3131
@Unique
3232
private String crashpatch$getText() {
33-
return MCTextFormat.RED + "If Minecraft is stuck on this screen, please force close the game" + (CrashPatch.INSTANCE.isSkyclient() ? " and go to https://discord.gg/eh7tNFezct for support" : "") + ".";
33+
return MCTextFormat.RED + "If Minecraft is stuck on this screen, please force close the game" + (CrashPatchClient.INSTANCE.isSkyclient() ? " and go to https://discord.gg/eh7tNFezct for support" : "") + ".";
3434
}
3535

3636
@Override
@@ -42,14 +42,14 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
4242
super.mouseClicked(mouseX, mouseY, mouseButton);
4343
if (((MinecraftHook) Minecraft.getMinecraft()).hasRecoveredFromCrash()) {
4444
if (mouseButton == 0) {
45-
String[] list = crashpatch$wrapFormattedStringToWidth(crashpatch$getText(), width).split("\n");
45+
List<String> list = this.fontRendererObj.listFormattedStringToWidth(crashpatch$getText(), width);
4646
int width = -1;
4747
for (String text : list) {
4848
width = Math.max(width, this.fontRendererObj.getStringWidth(text));
4949
}
5050

5151
int left = (this.width / 2) - width / 2;
52-
if ((width == -1 || (left < mouseX && left + width > mouseX)) && (mouseY > 5 && mouseY < 15 + ((list.length - 1) * (this.fontRendererObj.FONT_HEIGHT + 2)))) {
52+
if ((width == -1 || (left < mouseX && left + width > mouseX)) && (mouseY > 5 && mouseY < 15 + ((list.size() - 1) * (this.fontRendererObj.FONT_HEIGHT + 2)))) {
5353
OmniDesktop.browse(URI.create("https://discord.gg/eh7tNFezct"));
5454
}
5555
}
@@ -58,83 +58,9 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
5858

5959
@Unique
6060
public void crashpatch$drawSplitCenteredString(String text, int x, int y, int color) {
61-
for (String line : crashpatch$wrapFormattedStringToWidth(text, width).split("\n")) {
61+
for (String line : this.fontRendererObj.listFormattedStringToWidth(text, width)) {
6262
drawCenteredString(this.fontRendererObj, line, x, y, color);
6363
y += this.fontRendererObj.FONT_HEIGHT + 2;
6464
}
6565
}
66-
67-
@Unique
68-
public String crashpatch$wrapFormattedStringToWidth(String str, int wrapWidth) {
69-
int i = this.crashpatch$sizeStringToWidth(str, wrapWidth);
70-
71-
if (str.length() <= i) {
72-
return str;
73-
} else {
74-
String s = str.substring(0, i);
75-
char c0 = str.charAt(i);
76-
boolean flag = c0 == 32 || c0 == 10;
77-
String s1 = FontRenderer.getFormatFromString(s) + str.substring(i + (flag ? 1 : 0));
78-
return s + "\n" + this.crashpatch$wrapFormattedStringToWidth(s1, wrapWidth);
79-
}
80-
}
81-
82-
@Unique
83-
private int crashpatch$sizeStringToWidth(String str, int wrapWidth) {
84-
int i = str.length();
85-
int j = 0;
86-
int k = 0;
87-
int l = -1;
88-
89-
for (boolean flag = false; k < i; ++k) {
90-
char c0 = str.charAt(k);
91-
92-
switch (c0) {
93-
case '\n':
94-
--k;
95-
break;
96-
case ' ':
97-
l = k;
98-
default:
99-
j += this.fontRendererObj.getCharWidth(c0);
100-
101-
if (flag) {
102-
++j;
103-
}
104-
105-
break;
106-
case '\u00a7':
107-
108-
if (k < i - 1) {
109-
++k;
110-
char c1 = str.charAt(k);
111-
112-
if (c1 != 108 && c1 != 76) {
113-
if (c1 == 114 || c1 == 82 || crashpatch$isFormatColor(c1)) {
114-
flag = false;
115-
}
116-
} else {
117-
flag = true;
118-
}
119-
}
120-
}
121-
122-
if (c0 == 10) {
123-
++k;
124-
l = k;
125-
break;
126-
}
127-
128-
if (j > wrapWidth) {
129-
break;
130-
}
131-
}
132-
133-
return k != i && l != -1 && l < k ? l : k;
134-
}
135-
136-
@Unique
137-
private static boolean crashpatch$isFormatColor(char colorChar) {
138-
return colorChar >= 48 && colorChar <= 57 || colorChar >= 97 && colorChar <= 102 || colorChar >= 65 && colorChar <= 70;
139-
}
14066
}

src/main/java/org/polyfrost/crashpatch/mixin/MixinGuiDupesFound.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.polyfrost.crashpatch.mixin;
22

3-
//#if FORGE
3+
//#if FORGE && MC<1.13
44
import dev.deftu.omnicore.client.OmniClient;
55
import dev.deftu.omnicore.client.OmniDesktop;
66
import dev.deftu.textile.minecraft.MCTextFormat;
7-
import org.polyfrost.crashpatch.CrashPatch;
7+
import org.polyfrost.crashpatch.client.CrashPatchClient;
88
import net.minecraft.client.gui.GuiButton;
99
import net.minecraft.client.gui.GuiErrorScreen;
1010
import net.minecraftforge.fml.client.GuiDupesFound;
@@ -48,7 +48,7 @@ private void onInit(CallbackInfo ci) {
4848
protected void actionPerformed(GuiButton button) {
4949
switch (button.id) {
5050
case 0:
51-
OmniDesktop.open(new File(CrashPatch.getMcDir(), "mods"));
51+
OmniDesktop.open(new File(CrashPatchClient.getMcDir(), "mods"));
5252
break;
5353
case 1:
5454
FMLCommonHandler.instance().exitJava(0, false);
@@ -70,7 +70,7 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn
7070

7171
offset += 10;
7272

73-
crashpatch$drawSplitString(MCTextFormat.BOLD + "To fix this, go into your mods folder by clicking the button below or going to " + CrashPatch.getMcDir().getAbsolutePath() + " and deleting the duplicate mods.", width / 2, offset, width, Color.BLUE.getRGB());
73+
crashpatch$drawSplitString(MCTextFormat.BOLD + "To fix this, go into your mods folder by clicking the button below or going to " + CrashPatchClient.getMcDir().getAbsolutePath() + " and deleting the duplicate mods.", width / 2, offset, width, Color.BLUE.getRGB());
7474

7575
for (GuiButton guiButton : this.buttonList) {
7676
guiButton.drawButton(this.mc, mouseX, mouseY

src/main/java/org/polyfrost/crashpatch/mixin/MixinMinecraft.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package org.polyfrost.crashpatch.mixin;
2-
2+
//#if MC<1.13
33
//#if FORGE
44
import net.minecraftforge.fml.client.SplashProgress;
55
import net.minecraftforge.fml.common.FMLCommonHandler;
@@ -31,7 +31,7 @@
3131
import org.lwjgl.LWJGLException;
3232
import org.lwjgl.input.Mouse;
3333
import org.lwjgl.opengl.Display;
34-
import org.polyfrost.crashpatch.CrashPatch;
34+
import org.polyfrost.crashpatch.client.CrashPatchClient;
3535
import org.polyfrost.crashpatch.CrashPatchConfig;
3636
import org.polyfrost.crashpatch.crashes.StateManager;
3737
import org.polyfrost.crashpatch.gui.CrashUI;
@@ -158,8 +158,8 @@ public void run(CallbackInfo ci) {
158158
while (running) {
159159
if (!this.hasCrashed || this.crashReporter == null) {
160160
try {
161-
if (CrashPatch.INSTANCE.getRequestedCrash()) {
162-
CrashPatch.INSTANCE.setRequestedCrash(false);
161+
if (CrashPatchClient.INSTANCE.getRequestedCrash()) {
162+
CrashPatchClient.INSTANCE.setRequestedCrash(false);
163163
throw new RuntimeException("Crash requested by CrashPatch");
164164
}
165165

@@ -438,5 +438,4 @@ public void redirect(FMLCommonHandler instance, int code) {
438438

439439
}
440440

441-
442-
441+
//#endif

0 commit comments

Comments
 (0)