diff options
| author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-05-03 12:15:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-03 12:15:45 +0200 |
| commit | 4a2ac4ca162d846dcc9a2a3227f963321fa4e22a (patch) | |
| tree | 3bd7a448f61e58e02f1e81778a40aa3b964fd8b7 /src/main/java/at/hannibal2/skyhanni/mixins | |
| parent | 8d338540f3293b03acdd74f40a6c84a3cbedbded (diff) | |
| download | skyhanni-4a2ac4ca162d846dcc9a2a3227f963321fa4e22a.tar.gz skyhanni-4a2ac4ca162d846dcc9a2a3227f963321fa4e22a.tar.bz2 skyhanni-4a2ac4ca162d846dcc9a2a3227f963321fa4e22a.zip | |
Backend: GuiContainerEvent.BeforeDraw (#1510)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/mixins')
3 files changed, 44 insertions, 0 deletions
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); |
