Skip to content

Commit

Permalink
Show hint for people who dont know that they need to turn on optifine (
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o authored Oct 30, 2023
1 parent ce153f0 commit e1c24ec
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,29 @@
package io.github.moulberry.notenoughupdates.miscgui

import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import net.minecraftforge.fml.common.registry.GameRegistry
import org.lwjgl.opengl.GL11
import java.awt.Color
import java.io.File
import kotlin.math.ceil

class DynamicLightItemsEditor() : GuiScreen() {

val isOfLightsEnabled = run {
val ofDynamicLights = File("optionsof.txt").takeIf { it.exists() }?.readLines()
?.find { it.startsWith("ofDynamicLights:") }
ofDynamicLights != null && !ofDynamicLights.endsWith(":3")
}

val background = ResourceLocation("notenoughupdates:dynamic_light_items_editor.png")
val enabledButton = ResourceLocation("notenoughupdates:enabled_button.png")
val disabledButton = ResourceLocation("notenoughupdates:disabled_button.png")
Expand Down Expand Up @@ -98,6 +108,12 @@ class DynamicLightItemsEditor() : GuiScreen() {
fontRendererObj.drawString("the discord for help", guiLeft + 52, guiTop + 42, Color.RED.rgb)
return
}
if (!isOfLightsEnabled) {
fontRendererObj.drawString("Dynamic lights have", guiLeft + 50, guiTop + 22, Color.RED.rgb)
fontRendererObj.drawString("been disabled in OptiFine.", guiLeft + 50, guiTop + 32, Color.RED.rgb)
fontRendererObj.drawString("Enable in Video Settings.", guiLeft + 52, guiTop + 42, Color.RED.rgb)
return
}

// Buttons
GlStateManager.color(1f, 1f, 1f, 1f)
Expand Down Expand Up @@ -204,7 +220,26 @@ class DynamicLightItemsEditor() : GuiScreen() {
super.mouseClicked(mouseX, mouseY, mouseButton)
}

@NEUAutoSubscribe
companion object {
var hasAttemptedToLoadOptifine = false

@SubscribeEvent
fun autoloadOptifine(event: TickEvent) {
if (Minecraft.getMinecraft().thePlayer == null || hasAttemptedToLoadOptifine) return
try {
Class.forName("net.optifine.DynamicLights")
println("Loaded dynamic lights successfully.")
} catch (e: Exception) {
e.printStackTrace()
}
hasAttemptedToLoadOptifine = true
if (!didApplyMixin) {
println("Loaded optifine dynamic lights class without applying mixin!")
}
}


@JvmStatic
var didApplyMixin = false

Expand All @@ -228,7 +263,8 @@ class DynamicLightItemsEditor() : GuiScreen() {
@JvmStatic
fun resolveInternalName(itemStack: ItemStack): String? {
var internalName =
NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(itemStack).resolveInternalName()
NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(itemStack)
.resolveInternalName()
if (internalName == null) {
// If resolving internal name failed, the item may be a minecraft item
internalName = itemStack.item.registryName
Expand Down

0 comments on commit e1c24ec

Please sign in to comment.