aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GuiData.kt72
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/NEURenderEvent.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNEUOverlay.java20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt41
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt3
9 files changed, 180 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index dcb610423..a68ae1cce 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -25,6 +25,7 @@ import at.hannibal2.skyhanni.data.GardenComposterUpgradesData
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestonesCommunityFix
import at.hannibal2.skyhanni.data.GardenCropUpgrades
+import at.hannibal2.skyhanni.data.GuiData
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.GuildAPI
import at.hannibal2.skyhanni.data.HighlightOnHoverSlot
@@ -539,6 +540,7 @@ class SkyHanniMod {
loadModule(TrackerManager)
loadModule(ScoreboardPattern)
loadModule(UtilsPatterns)
+ loadModule(GuiData)
loadModule(BossbarData)
loadModule(EntityUtils)
loadModule(ChatUtils)
@@ -959,6 +961,7 @@ class SkyHanniMod {
screenTicks++
if (screenTicks == 5) {
Minecraft.getMinecraft().thePlayer.closeScreen()
+ OtherInventoryData.close()
Minecraft.getMinecraft().displayGuiScreen(screenToOpen)
screenTicks = 0
screenToOpen = null
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
new file mode 100644
index 000000000..c0cd46365
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
@@ -0,0 +1,72 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.NEURenderEvent
+import at.hannibal2.skyhanni.utils.DelayedRun
+import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
+import io.github.moulberry.notenoughupdates.NEUApi
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.inventory.GuiChest
+import net.minecraftforge.client.event.GuiOpenEvent
+import net.minecraftforge.client.event.GuiScreenEvent
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.network.FMLNetworkEvent
+import org.lwjgl.input.Keyboard
+
+object GuiData {
+
+ var preDrawEventCanceled = false
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onNeuRenderEvent(event: NEURenderEvent) {
+ if (preDrawEventCanceled) event.cancel()
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onClick(event: GuiContainerEvent.SlotClickEvent) {
+ if (preDrawEventCanceled) event.cancel()
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onGuiClick(event: GuiScreenEvent.MouseInputEvent.Pre) {
+ if (preDrawEventCanceled) event.isCanceled = true
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onGuiKeyPress(event: GuiScreenEvent.KeyboardInputEvent.Pre) {
+ val (escKey, invKey) = Minecraft.getMinecraft().gameSettings.let {
+ Keyboard.KEY_ESCAPE to it.keyBindInventory.keyCode
+ }
+ if (escKey.isKeyHeld() || invKey.isKeyHeld()) return
+ if (preDrawEventCanceled) event.isCanceled = true
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ DelayedRun.runNextTick {
+ if (Minecraft.getMinecraft().currentScreen !is GuiChest) {
+ preDrawEventCanceled = false
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ preDrawEventCanceled = false
+ }
+
+ @SubscribeEvent
+ fun onDisconnect(event: FMLNetworkEvent.ClientDisconnectionFromServerEvent) {
+ preDrawEventCanceled = false
+ }
+
+ @SubscribeEvent(priority = EventPriority.LOW)
+ fun onGuiOpen(event: GuiOpenEvent) {
+ if (preDrawEventCanceled) {
+ NEUApi.setInventoryButtonsToDisabled()
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt
index 9b4d534fc..9837e1529 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/GuiContainerEvent.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.events
+import at.hannibal2.skyhanni.utils.GuiRenderUtils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Container
@@ -18,6 +19,18 @@ abstract class GuiContainerEvent(open val gui: GuiContainer, open val container:
) : GuiContainerEvent(gui, container)
@Cancelable
+ data class BeforeDraw(
+ override val gui: GuiContainer,
+ override val container: Container,
+ val mouseX: Int,
+ val mouseY: Int,
+ val partialTicks: Float,
+ ) : GuiContainerEvent(gui, container) {
+ fun drawDefaultBackground() =
+ GuiRenderUtils.drawGradientRect(0, 0, gui.width, gui.height, -1072689136, -804253680, 0.0)
+ }
+
+ @Cancelable
data class CloseWindowEvent(override val gui: GuiContainer, override val container: Container) :
GuiContainerEvent(gui, container)
diff --git a/src/main/java/at/hannibal2/skyhanni/events/NEURenderEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/NEURenderEvent.kt
new file mode 100644
index 000000000..c2bcc9b49
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/NEURenderEvent.kt
@@ -0,0 +1,6 @@
+package at.hannibal2.skyhanni.events
+
+import net.minecraftforge.fml.common.eventhandler.Cancelable
+
+@Cancelable
+class NEURenderEvent : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt
index 3304534a3..72f4a2e90 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt
@@ -1,10 +1,12 @@
package at.hannibal2.skyhanni.mixins.hooks
+import at.hannibal2.skyhanni.data.GuiData
import at.hannibal2.skyhanni.events.DrawScreenAfterEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent.CloseWindowEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent.SlotClickEvent
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
+import io.github.moulberry.notenoughupdates.NEUApi
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Slot
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo
@@ -26,6 +28,22 @@ class GuiContainerHook(guiAny: Any) {
GuiContainerEvent.BackgroundDrawnEvent(gui, gui.inventorySlots, mouseX, mouseY, partialTicks).postAndCatch()
}
+ fun preDraw(
+ mouseX: Int,
+ mouseY: Int,
+ partialTicks: Float,
+ ci: CallbackInfo,
+ ) {
+ if (!SkyHanniDebugsAndTests.globalRender) return
+ if (GuiContainerEvent.BeforeDraw(gui, gui.inventorySlots, mouseX, mouseY, partialTicks).postAndCatch()) {
+ NEUApi.setInventoryButtonsToDisabled()
+ GuiData.preDrawEventCanceled = true
+ ci.cancel()
+ } else {
+ GuiData.preDrawEventCanceled = false
+ }
+ }
+
fun foregroundDrawn(mouseX: Int, mouseY: Int, partialTicks: Float) {
GuiContainerEvent.ForegroundDrawnEvent(gui, gui.inventorySlots, mouseX, mouseY, partialTicks).postAndCatch()
}
@@ -52,4 +70,5 @@ class GuiContainerHook(guiAny: Any) {
) {
if (DrawScreenAfterEvent(mouseX, mouseY, ci).postAndCatch()) ci.cancel()
}
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNEUOverlay.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNEUOverlay.java
new file mode 100644
index 000000000..9ac228f29
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinNEUOverlay.java
@@ -0,0 +1,20 @@
+package at.hannibal2.skyhanni.mixins.transformers;
+
+import at.hannibal2.skyhanni.events.NEURenderEvent;
+import io.github.moulberry.notenoughupdates.NEUOverlay;
+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(NEUOverlay.class)
+public class MixinNEUOverlay {
+
+ @Inject(method = "render", at = @At("HEAD"), cancellable = true, remap = false)
+ private void render(boolean hoverInv, CallbackInfo ci) {
+ if (new NEURenderEvent().postAndCatch()) {
+ ci.cancel();
+ }
+ }
+
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java
index f5f637e14..c92f2ab7c 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/MixinGuiContainer.java
@@ -31,6 +31,11 @@ public abstract class MixinGuiContainer extends GuiScreen {
skyHanni$hook.backgroundDrawn(mouseX, mouseY, partialTicks);
}
+ @Inject(method = "drawScreen", at = @At("HEAD"), cancellable = true)
+ private void preDraw(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
+ skyHanni$hook.preDraw(mouseX, mouseY, partialTicks, ci);
+ }
+
@Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;drawGuiContainerForegroundLayer(II)V", shift = At.Shift.AFTER))
private void onForegroundDraw(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
skyHanni$hook.foregroundDrawn(mouseX, mouseY, partialTicks);
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
index aab61ab10..8962e402e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt
@@ -9,6 +9,8 @@ import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.RenderHelper
+import net.minecraft.client.renderer.Tessellator
+import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.item.ItemStack
import org.lwjgl.opengl.GL11
import java.awt.Color
@@ -310,7 +312,7 @@ object GuiRenderUtils {
color: Color,
useChroma: Boolean,
texture: SkillProgressBarConfig.TexturedBar.UsedTexture,
- height: Float
+ height: Float,
) {
GlStateManager.pushMatrix()
GlStateManager.translate(x, y, 0f)
@@ -377,4 +379,41 @@ object GuiRenderUtils {
}
GlStateManager.popMatrix()
}
+
+ /**@Mojang */
+ fun drawGradientRect(
+ left: Int,
+ top: Int,
+ right: Int,
+ bottom: Int,
+ startColor: Int,
+ endColor: Int,
+ zLevel: Double,
+ ) {
+ val f = (startColor shr 24 and 255).toFloat() / 255.0f
+ val g = (startColor shr 16 and 255).toFloat() / 255.0f
+ val h = (startColor shr 8 and 255).toFloat() / 255.0f
+ val i = (startColor and 255).toFloat() / 255.0f
+ val j = (endColor shr 24 and 255).toFloat() / 255.0f
+ val k = (endColor shr 16 and 255).toFloat() / 255.0f
+ val l = (endColor shr 8 and 255).toFloat() / 255.0f
+ val m = (endColor and 255).toFloat() / 255.0f
+ GlStateManager.disableTexture2D()
+ GlStateManager.enableBlend()
+ GlStateManager.disableAlpha()
+ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
+ GlStateManager.shadeModel(7425)
+ val tessellator = Tessellator.getInstance()
+ val worldRenderer = tessellator.worldRenderer
+ worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR)
+ worldRenderer.pos(right.toDouble(), top.toDouble(), zLevel).color(g, h, i, f).endVertex()
+ worldRenderer.pos(left.toDouble(), top.toDouble(), zLevel).color(g, h, i, f).endVertex()
+ worldRenderer.pos(left.toDouble(), bottom.toDouble(), zLevel).color(k, l, m, j).endVertex()
+ worldRenderer.pos(right.toDouble(), bottom.toDouble(), zLevel).color(k, l, m, j).endVertex()
+ tessellator.draw()
+ GlStateManager.shadeModel(7424)
+ GlStateManager.disableBlend()
+ GlStateManager.enableAlpha()
+ GlStateManager.enableTexture2D()
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
index fc1b0f45f..6c1e0bd2e 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils.renderables
import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor
import at.hannibal2.skyhanni.config.features.skillprogress.SkillProgressBarConfig
+import at.hannibal2.skyhanni.data.GuiData
import at.hannibal2.skyhanni.data.HighlightOnHoverSlot
import at.hannibal2.skyhanni.data.ToolTipData
import at.hannibal2.skyhanni.features.chroma.ChromaShaderManager
@@ -231,7 +232,7 @@ interface Renderable {
}
val isGuiPositionEditor = Minecraft.getMinecraft().currentScreen !is GuiPositionEditor
val isNotInSignAndOnSlot = if (Minecraft.getMinecraft().currentScreen !is GuiEditSign) {
- ToolTipData.lastSlot == null
+ ToolTipData.lastSlot == null || GuiData.preDrawEventCanceled
} else true
val isConfigScreen = Minecraft.getMinecraft().currentScreen !is GuiScreenElementWrapper