Implement auto-updater screen for 1.12.2

This commit is contained in:
Vojtěch Šokala
2026-06-07 23:01:08 +02:00
parent 1d7cb1e6fc
commit 00b47fc776
7 changed files with 77 additions and 25 deletions
+2 -1
View File
@@ -578,7 +578,8 @@ if (isNotCommonProject) {
new JsonSlurper()
.parse(input)
.each { key, value ->
writer.writeLine("${key}=${value.toString().replace("%", "%%").replace("\n", "\\n")}")
def text = value.toString().replaceAll(/%(?!((\d+)\$)?s|%)/, "%%").replace("\n", "\\n")
writer.writeLine("${key}=${text}")
}
}
}
@@ -0,0 +1,24 @@
package com.seibel.distanthorizons.cleanroom.mixins.client;
import com.seibel.distanthorizons.common.commonMixins.DhUpdateScreenBase;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.coreapi.ModInfo;
import net.minecraft.client.Minecraft;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Minecraft.class)
public class MixinMinecraft
{
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo ci)
{
if(Config.Client.Advanced.AutoUpdater.enableAutoUpdater.get() && !ModInfo.IS_DEV_BUILD) // weird lib class not found error can occur if we don't check if we are in dev
{
DhUpdateScreenBase.tryShowUpdateScreenAndRunAutoUpdateStartup(null);
}
}
}
@@ -1,19 +1,20 @@
{
"required": true,
"package": "com.seibel.distanthorizons.cleanroom.mixins",
"compatibilityLevel": "JAVA_8",
"target": "@env(DEFAULT)",
"mixins": [
"common.MixinThreadedFileIOBase"
],
"minVersion": "0.8.7",
"server": [
"server.MixinEntityPlayerMP"
],
"client": [
"client.MixinEntityRenderer",
"client.MixinNetHandlerPlayClient",
"client.MixinOptionsScreen",
"client.MixinRenderGlobal"
]
"required": true,
"package": "com.seibel.distanthorizons.cleanroom.mixins",
"compatibilityLevel": "JAVA_8",
"target": "@env(DEFAULT)",
"mixins": [
"common.MixinThreadedFileIOBase"
],
"minVersion": "0.8.7",
"server": [
"server.MixinEntityPlayerMP"
],
"client": [
"client.MixinEntityRenderer",
"client.MixinMinecraft",
"client.MixinNetHandlerPlayClient",
"client.MixinOptionsScreen",
"client.MixinRenderGlobal"
]
}
@@ -155,16 +155,21 @@ public class TexturedButtonWidget extends Button
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
if (this.visible) {
//Render vanilla background
mc.getTextureManager().bindTexture(BUTTON_TEXTURES);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
int i = this.getHoverState(this.hovered);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if (this.renderBackground)
{
//Render vanilla background
mc.getTextureManager().bindTexture(BUTTON_TEXTURES);
this.drawTexturedModalRect(this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height);
}
//Render DH texture
mc.getTextureManager().bindTexture(textureResourceLocation);
@@ -1030,7 +1030,7 @@ class DhConfigScreen extends DhScreen
ChangelogScreen changelogScreen = new ChangelogScreen(this);
if (changelogScreen.usable)
{
Minecraft.getMinecraft().displayGuiScreen(changelogScreen);
DhScreenUtil.setScreen(changelogScreen);
}
else
{
@@ -186,7 +186,7 @@ public class ChangelogScreen extends DhScreen
this.addBtn( // Close
MakeBtn(Translatable(ModInfo.ID + ".general.back"), 5, this.height - 25, 100, 20, (btn) -> {
#if MC_VER <= MC_1_12_2
Objects.requireNonNull(this.mc).displayGuiScreen(this.parent);
DhScreenUtil.setScreen(this.parent);
#else
this.onClose();
#endif
@@ -11,6 +11,7 @@ import com.seibel.distanthorizons.core.jar.installer.ModrinthGetter;
import com.seibel.distanthorizons.core.jar.updater.SelfUpdater;
import com.seibel.distanthorizons.core.logging.DhLogger;
#if MC_VER <= MC_1_12_2
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
#else
import net.minecraft.client.gui.screens.Screen;
@@ -298,4 +299,24 @@ public class UpdateModScreen extends DhScreen
#endif
}
#if MC_VER <= MC_1_12_2
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
if(button.id == changelogButton_id)
{
ChangelogScreen changelogScreen = new ChangelogScreen(this);
if (changelogScreen.usable)
{
DhScreenUtil.setScreen(changelogScreen);
}
else
{
LOGGER.warn("Changelog was not able to open");
}
}
}
#endif
}