Skip to content

Commit

Permalink
remove connected textures fix x2
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed May 2, 2022
1 parent 7b9332c commit 4d42917
Showing 1 changed file with 0 additions and 58 deletions.
58 changes: 0 additions & 58 deletions src/main/kotlin/cc/woverflow/crashpatch/CrashPatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@ import cc.woverflow.crashpatch.crashes.DeobfuscatingRewritePolicy
import cc.woverflow.crashpatch.hooks.ModsCheckerPlugin
import cc.woverflow.onecore.utils.Updater
import cc.woverflow.onecore.utils.command
import cc.woverflow.onecore.utils.sendBrandedNotification
import gg.essential.api.EssentialAPI
import gg.essential.api.utils.Multithreading
import gg.essential.universal.ChatColor
import gg.essential.universal.UDesktop
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiMainMenu
import net.minecraft.client.settings.GameSettings
import net.minecraft.launchwrapper.Launch
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.apache.logging.log4j.LogManager
import java.io.File
import java.lang.reflect.Field


@Mod(modid = CrashPatch.MODID, version = CrashPatch.VERSION, name = CrashPatch.NAME, modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter")
Expand All @@ -40,7 +32,6 @@ object CrashPatch {
Launch.minecraftHome
}
}
var stopChecking = false

@Mod.EventHandler
fun onPreInit(e: FMLPreInitializationEvent) {
Expand All @@ -65,55 +56,6 @@ object CrashPatch {
}
}
}
MinecraftForge.EVENT_BUS.register(this)
}

@SubscribeEvent
fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent.Post) {
if (!stopChecking && event.gui !is GuiMainMenu) {
stopChecking = true
try {
val settingsClass: Class<GameSettings> = Minecraft.getMinecraft().gameSettings.javaClass
val field = settingsClass.getFieldAndSetAccessible("ofConnectedTextures")
field?.let { property ->
try {
property.getInt(Minecraft.getMinecraft().gameSettings).let {
if (it == 0 || it == 3) {
sendBrandedNotification("CrashPatch", "CrashPatch fixes the Connected Textures crash on Forge.\n\nClick here to enable Connected Textures!", duration = 10f, action = {
var reload = true
try {
property.setInt(Minecraft.getMinecraft().gameSettings, 2)
} catch (e: Exception) {
e.printStackTrace()
reload = false
}
if (reload) {
Minecraft.getMinecraft().gameSettings.saveOptions()
Minecraft.getMinecraft().gameSettings.loadOptions()
Minecraft.getMinecraft().refreshResources()
}
})
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}

private fun Class<*>.getFieldAndSetAccessible(name: String): Field? {
return try {
val field = this.getDeclaredField(name)
field.isAccessible = true
field
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
val logger = LogManager.getLogger(CrashPatch)

0 comments on commit 4d42917

Please sign in to comment.