Skip to content

Commit 69e4fef

Browse files
committed
1.12 port
1 parent 726633c commit 69e4fef

File tree

13 files changed

+363
-96
lines changed

13 files changed

+363
-96
lines changed

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ plugins {
1717

1818
toolkitLoomHelper {
1919
useOneConfig {
20-
version = "1.0.0-alpha.106"
21-
loaderVersion = "1.1.0-alpha.46"
20+
version = "1.0.0-alpha.134"
21+
loaderVersion = "1.1.0-alpha.48"
2222

2323
usePolyMixin = true
24-
polyMixinVersion = "0.8.4+build.2"
24+
polyMixinVersion = "0.8.4+build.6"
2525

2626
applyLoaderTweaker = true
2727

28-
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "ui", "utils")) {
28+
for (module in arrayOf("commands", "config", "config-impl", "events", "internal", "hud", "ui", "utils")) {
2929
+module
3030
}
3131
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip

root.gradle.kts

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

13-
"1.8.9-forge"(10809, "srg") {
14-
"1.8.9-fabric"(10809, "yarn")
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")
17+
}
18+
}
1519
}
1620

1721
strictExtraMappings.set(true)

settings.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pluginManagement {
2424

2525
plugins {
2626
kotlin("jvm") version("2.0.0")
27-
id("dev.deftu.gradle.multiversion-root") version("2.34.0")
27+
id("dev.deftu.gradle.multiversion-root") version("2.49.0")
2828
}
2929
}
3030

@@ -42,6 +42,8 @@ rootProject.buildFileName = "root.gradle.kts"
4242
listOf(
4343
"1.8.9-forge",
4444
"1.8.9-fabric",
45+
"1.12.2-forge",
46+
"1.12.2-fabric"
4547
).forEach { version ->
4648
include(":$version")
4749
project(":$version").apply {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.zip.ZipEntry;
99
import java.util.zip.ZipInputStream;
1010

11+
//TODO rewrite for fabric
1112
public class StacktraceDeobfuscator {
1213
public static final StacktraceDeobfuscator INSTANCE = new StacktraceDeobfuscator();
1314

@@ -21,7 +22,13 @@ private StacktraceDeobfuscator() {
2122
if (!mappings.exists()) {
2223
HttpURLConnection connection = null;
2324
try {
24-
URL mappingsURL = new URL("https://maven.minecraftforge.net/de/oceanlabs/mcp/mcp_stable_nodoc/22-1.8.9/mcp_stable_nodoc-22-1.8.9.zip");
25+
URL mappingsURL = new URL(
26+
//#if MC==1.8.9
27+
"https://maven.minecraftforge.net/de/oceanlabs/mcp/mcp_stable_nodoc/22-1.8.9/mcp_stable_nodoc-22-1.8.9.zip"
28+
//#else
29+
//$$ "http://export.mcpbot.bspk.rs/mcp_stable_nodoc/39-1.12/mcp_stable_nodoc-39-1.12.zip"
30+
//#endif
31+
);
2532
connection = (HttpURLConnection) mappingsURL.openConnection();
2633
connection.setDoInput(true);
2734
connection.connect();

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

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

33
//#if FORGE
4+
import dev.deftu.omnicore.client.OmniClient;
45
import dev.deftu.omnicore.client.OmniDesktop;
6+
import dev.deftu.textile.minecraft.MCTextFormat;
57
import org.polyfrost.crashpatch.CrashPatch;
6-
import net.minecraft.client.Minecraft;
78
import net.minecraft.client.gui.GuiButton;
89
import net.minecraft.client.gui.GuiErrorScreen;
9-
import net.minecraft.util.EnumChatFormatting;
1010
import net.minecraftforge.fml.client.GuiDupesFound;
1111
import net.minecraftforge.fml.common.DuplicateModsFoundException;
1212
import net.minecraftforge.fml.common.FMLCommonHandler;
@@ -32,8 +32,14 @@ public MixinGuiDupesFound() {
3232
super(null, null);
3333
}
3434

35+
//#if MC < 1.12
3536
@Inject(method = "initGui", at = @At("RETURN"))
3637
private void onInit(CallbackInfo ci) {
38+
//#else
39+
//$$ @Override
40+
//$$ public void initGui() {
41+
//$$ super.initGui();
42+
//#endif
3743
this.buttonList.add(new GuiButton(0, width / 2 - 100, height - 50, "Open Folder"));
3844
this.buttonList.add(new GuiButton(1, width / 2 - 100, height - 30, "Quit Game"));
3945
}
@@ -64,10 +70,14 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn
6470

6571
offset += 10;
6672

67-
crashpatch$drawSplitString(EnumChatFormatting.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 " + CrashPatch.getMcDir().getAbsolutePath() + " and deleting the duplicate mods.", width / 2, offset, width, Color.BLUE.getRGB());
6874

6975
for (GuiButton guiButton : this.buttonList) {
70-
guiButton.drawButton(this.mc, mouseX, mouseY);
76+
guiButton.drawButton(this.mc, mouseX, mouseY
77+
//#if MC >= 1.12
78+
//$$ , partialTicks
79+
//#endif
80+
);
7181
}
7282
for (net.minecraft.client.gui.GuiLabel guiLabel : this.labelList) {
7383
guiLabel.drawLabel(this.mc, mouseX, mouseY);
@@ -78,9 +88,9 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn
7888
private static int crashpatch$drawSplitString(String str, int x, int y, int wrapWidth, int textColor) {
7989
str = crashpatch$trimStringNewline(str);
8090
int y2 = y;
81-
for (String s : Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth(str, wrapWidth)) {
82-
Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(s, (float) (x - Minecraft.getMinecraft().fontRendererObj.getStringWidth(s) / 2), (float) y2, textColor);
83-
y2 += Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT;
91+
for (String s : OmniClient.getFontRenderer().listFormattedStringToWidth(str, wrapWidth)) {
92+
OmniClient.getFontRenderer().drawStringWithShadow(s, (float) (x - OmniClient.getFontRenderer().getStringWidth(s) / 2), (float) y2, textColor);
93+
y2 += OmniClient.getFontRenderer().FONT_HEIGHT;
8494
}
8595
return y2 - y;
8696
}

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

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import net.minecraft.client.network.NetHandlerPlayClient;
1616
import net.minecraft.client.renderer.EntityRenderer;
1717
import net.minecraft.client.renderer.GlStateManager;
18-
import net.minecraft.client.renderer.OpenGlHelper;
1918
import net.minecraft.client.renderer.texture.TextureManager;
2019
import net.minecraft.client.resources.IReloadableResourceManager;
2120
import net.minecraft.client.resources.LanguageManager;
@@ -32,19 +31,14 @@
3231
import org.lwjgl.LWJGLException;
3332
import org.lwjgl.input.Mouse;
3433
import org.lwjgl.opengl.Display;
35-
import org.lwjgl.opengl.GL11;
36-
import org.lwjgl.opengl.GL12;
37-
import org.lwjgl.opengl.GL14;
3834
import org.polyfrost.crashpatch.CrashPatch;
3935
import org.polyfrost.crashpatch.CrashPatchConfig;
4036
import org.polyfrost.crashpatch.crashes.StateManager;
4137
import org.polyfrost.crashpatch.gui.CrashUI;
4238
import org.polyfrost.crashpatch.hooks.MinecraftHook;
39+
import org.polyfrost.crashpatch.utils.GlUtil;
4340
import org.polyfrost.crashpatch.utils.GuiDisconnectedHook;
44-
import org.spongepowered.asm.mixin.Final;
45-
import org.spongepowered.asm.mixin.Mixin;
46-
import org.spongepowered.asm.mixin.Shadow;
47-
import org.spongepowered.asm.mixin.Unique;
41+
import org.spongepowered.asm.mixin.*;
4842
import org.spongepowered.asm.mixin.injection.At;
4943
import org.spongepowered.asm.mixin.injection.Inject;
5044
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -111,9 +105,6 @@ public abstract class MixinMinecraft implements MinecraftHook {
111105
@Shadow
112106
protected abstract void runGameLoop();
113107

114-
@Shadow
115-
public abstract void freeMemory();
116-
117108
@Shadow
118109
public abstract void shutdownMinecraftApplet();
119110

@@ -248,10 +239,14 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
248239
crashReport.getCategory().addCrashSectionCallable("Integrated Server Crashes Since Restart", () -> String.valueOf(crashpatch$serverCrashCount));
249240
}
250241

242+
public void crashpatch$resetGameState() {
243+
crashpatch$resetGameState(false);
244+
}
245+
251246
/**
252247
* @author Runemoro
253248
*/
254-
public void crashpatch$resetGameState() {
249+
public void crashpatch$resetGameState(boolean freeingMemory) {
255250
try {
256251
// Free up memory such that this works properly in case of an OutOfMemoryError
257252
int originalMemoryReserveSize = -1;
@@ -265,9 +260,18 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
265260

266261
StateManager.INSTANCE.resetStates();
267262

268-
if (crashpatch$clientCrashCount >= CrashPatchConfig.INSTANCE.getLeaveLimit() || crashpatch$serverCrashCount >= CrashPatchConfig.INSTANCE.getLeaveLimit()) {
263+
boolean shouldCrash = crashpatch$clientCrashCount >= CrashPatchConfig.INSTANCE.getLeaveLimit() || crashpatch$serverCrashCount >= CrashPatchConfig.INSTANCE.getLeaveLimit();
264+
265+
if (shouldCrash && !freeingMemory) {
269266
this.logger.error("Crash limit reached, exiting world");
270267
CrashUI.Companion.setLeaveWorldCrash(true);
268+
}
269+
270+
if (shouldCrash || freeingMemory
271+
//#if MC > 1.12
272+
//$$ || true
273+
//#endif
274+
) {
271275
if (getNetHandler() != null) {
272276
getNetHandler().getNetworkManager().closeChannel(new ChatComponentText("[CrashPatch] Client crashed"));
273277
}
@@ -280,7 +284,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
280284
this.scheduledTasks.clear(); // TODO: Figure out why this isn't necessary for vanilla disconnect
281285
}
282286

283-
crashpatch$resetState();
287+
GlUtil.INSTANCE.resetState();
284288

285289
if (originalMemoryReserveSize != -1) {
286290
try {
@@ -293,11 +297,25 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
293297
this.logger.error("Failed to reset state after a crash", t);
294298
try {
295299
StateManager.INSTANCE.resetStates();
296-
crashpatch$resetState();
300+
GlUtil.INSTANCE.resetState();
297301
} catch (Throwable ignored) {}
298302
}
299303
}
300304

305+
/**
306+
* @reason Disconnect from the current world and free memory, using a memory reserve
307+
* to make sure that an OutOfMemory doesn't happen while doing this.
308+
* <p>
309+
* Bugs Fixed:
310+
* - https://bugs.mojang.com/browse/MC-128953
311+
* - Memory reserve not recreated after out-of memory
312+
* @author Runemoro
313+
*/
314+
@Overwrite
315+
public void freeMemory() {
316+
crashpatch$resetGameState(true);
317+
}
318+
301319
/**
302320
* @author Runemoro
303321
*/
@@ -417,59 +435,6 @@ public void redirect(FMLCommonHandler instance, int code) {
417435
}
418436
//#endif
419437

420-
@Unique
421-
private void crashpatch$resetState() {
422-
GlStateManager.bindTexture(0);
423-
GlStateManager.disableTexture2D();
424-
425-
// Reset depth
426-
GlStateManager.disableDepth();
427-
GlStateManager.depthFunc(513);
428-
GlStateManager.depthMask(true);
429-
430-
// Reset blend mode
431-
GlStateManager.disableBlend();
432-
GlStateManager.blendFunc(1, 0);
433-
GlStateManager.tryBlendFuncSeparate(1, 0, 1, 0);
434-
GL14.glBlendEquation(GL14.GL_FUNC_ADD);
435-
436-
// Reset polygon offset
437-
GlStateManager.doPolygonOffset(0.0F, 0.0F);
438-
GlStateManager.disablePolygonOffset();
439-
440-
// Reset color logic
441-
GlStateManager.disableColorLogic();
442-
GlStateManager.colorLogicOp(5379);
443-
444-
// Disable lightmap
445-
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
446-
GlStateManager.disableTexture2D();
447-
448-
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
449-
450-
// Reset texture parameters
451-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
452-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
453-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
454-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
455-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LEVEL, 1000);
456-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, 1000);
457-
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MIN_LOD, -1000);
458-
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0.0F);
459-
460-
GlStateManager.colorMask(true, true, true, true);
461-
GlStateManager.clearDepth(1.0D);
462-
GL11.glLineWidth(1.0F);
463-
GL11.glNormal3f(0.0F, 0.0F, 1.0F);
464-
GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
465-
GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_FILL);
466-
GlStateManager.enableTexture2D();
467-
GlStateManager.clearDepth(1.0D);
468-
GlStateManager.enableDepth();
469-
GlStateManager.depthFunc(515);
470-
GlStateManager.enableCull();
471-
GL11.glDisable(GL11.GL_SCISSOR_TEST);
472-
}
473438

474439
}
475440

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
@Mixin(TileEntityRendererDispatcher.class)
1818
public abstract class MixinTileEntityRendererDispatcher implements StateManager.IResettable {
1919

20+
//#if MC < 1.12
2021
@Unique
2122
private boolean crashpatch$drawingBatch = false;
23+
//#else
24+
//$$ @org.spongepowered.asm.mixin.Shadow
25+
//$$ private boolean drawingBatch;
26+
//#endif
2227

2328
@Inject(method = "<init>", at = @At(value = "RETURN"))
2429
public void onInit(CallbackInfo ci) {
@@ -27,9 +32,15 @@ public void onInit(CallbackInfo ci) {
2732

2833
@Override
2934
public void resetState() {
35+
//#if MC < 1.12
3036
if (crashpatch$drawingBatch) crashpatch$drawingBatch = false;
37+
//#else
38+
//$$ if (drawingBatch) drawingBatch = false;
39+
//#endif
3140
}
3241

42+
//#if MC < 1.12
43+
3344
@Redirect(method = "renderTileEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/TileEntity;hasFastRenderer()Z"))
3445
private boolean isNotFastRenderOrDrawing(TileEntity instance) {
3546
if (!crashpatch$drawingBatch) {
@@ -54,5 +65,6 @@ private void setDrawingBatchFalse(int pass, CallbackInfo ci) {
5465
crashpatch$drawingBatch = false;
5566
}
5667

68+
//#endif
5769
}
5870
//#endif

src/main/kotlin/org/polyfrost/crashpatch/CrashPatchConfig.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ object CrashPatchConfig : Config("crashpatch.json", "/assets/crashpatch/crashpat
2929
)
3030
var disconnectCrashPatch = true
3131

32-
// Limits
33-
//@Info( // todo
34-
// text = "It's recommended to leave the world after a few crashes, and outright quit the game if there are more; this is to avoid severe instability",
35-
// type = InfoType.WARNING,
36-
// size = 2,
37-
// subcategory = "Limits"
38-
//)
39-
//var ignored: Boolean = false
32+
@Info(
33+
title = "polyui.warning",
34+
description = "It's recommended to leave the world after a few crashes, and outright quit the game if there are more; this is to avoid severe instability",
35+
icon = "polyui/warning.svg",
36+
subcategory = "Limits"
37+
)
38+
var ignored: Boolean = false
4039

4140
@Slider(
4241
title = "World Leave Limit",

src/main/kotlin/org/polyfrost/crashpatch/crashes/CrashScanStorage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object CrashScanStorage {
2727
@JvmStatic
2828
fun downloadJson(): Boolean {
2929
return try {
30-
skyclientData = JsonUtils.parseFromUrl("https://raw.githubusercontent.com/SkyblockClient/CrashData/main/crashes.json")
30+
skyclientData = JsonUtils.parseFromUrl("https://raw.githubusercontent.com/Polyfrost/CrashData/main/crashes.json")
3131
?.asJsonObject ?: return false
3232
cacheFile.writeText(skyclientData.toString())
3333
true

0 commit comments

Comments
 (0)