diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-05-21 15:25:20 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-05-21 15:25:20 -0700 |
commit | 15a3b944d13e54f4241df78b199403d414b9bd69 (patch) | |
tree | 191330182be0d46374dfe50d6454d36b0f704f55 /src/main/java/com/anthonyhilyard/iceberg/mixin/MinecraftMixin.java | |
parent | 8b014a52c0059ef8e1d420dfc5674bd6e1c70b1a (diff) | |
download | Iceberg-15a3b944d13e54f4241df78b199403d414b9bd69.tar.gz Iceberg-15a3b944d13e54f4241df78b199403d414b9bd69.tar.bz2 Iceberg-15a3b944d13e54f4241df78b199403d414b9bd69.zip |
Added a workaround to fix update checker for my mods.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/mixin/MinecraftMixin.java')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/mixin/MinecraftMixin.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/MinecraftMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/MinecraftMixin.java new file mode 100644 index 0000000..67c63f5 --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/MinecraftMixin.java @@ -0,0 +1,75 @@ +package com.anthonyhilyard.iceberg.mixin; + +import java.lang.reflect.Field; +import java.net.URL; +import java.util.ArrayList; +import java.util.Optional; + +import com.anthonyhilyard.iceberg.Loader; +import com.mojang.blaze3d.pipeline.RenderTarget; + +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.loading.FMLLoader; +import net.minecraftforge.fml.loading.moddiscovery.ModInfo; +import net.minecraftforge.forgespi.language.IModInfo; + +@Mixin(Minecraft.class) +public class MinecraftMixin +{ + @SuppressWarnings("unchecked") + @Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/pipeline/RenderTarget;clear(Z)V", ordinal = 0), require = 0) + public void fixUpdateURLs(RenderTarget renderTarget, boolean onOSX) + { + for (IModInfo mod : FMLLoader.getLoadingModList().getMods()) + { + Optional<Object> authors = mod.getConfig().getConfigElement("authors"); + if (!authors.isPresent()) + { + continue; + } + + boolean madeByGrend = false; + if (authors.get() instanceof String author) + { + madeByGrend = author.contentEquals("Grend"); + } + else if (authors.get() instanceof ArrayList<?> authorList) + { + madeByGrend = authorList.contains("Grend"); + } + + if (madeByGrend) + { + // Found a mod I made, so patch the update URL. + // Yeah, it's a dirty hack but it lets me fix all my mods at once before I have the time to update them all properly. + ModInfo modInfo = (ModInfo)mod; + + try + { + Field updateJSONURLField = ModInfo.class.getDeclaredField("updateJSONURL"); + updateJSONURLField.setAccessible(true); + + Optional<URL> updateJSONURL = (Optional<URL>)updateJSONURLField.get(modInfo); + if (updateJSONURL.isPresent()) + { + String url = updateJSONURL.get().toString(); + url = url.replace("mc-curse-update-checker.herokuapp.com", "mc-update-check.anthonyhilyard.com"); + updateJSONURLField.set(modInfo, Optional.of(new URL(url))); + + } + } + catch (Exception e) + { + Loader.LOGGER.debug(ExceptionUtils.getStackTrace(e)); + } + } + + } + renderTarget.clear(onOSX); + } +} |