diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-28 21:59:37 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-28 21:59:37 +0200 |
commit | 03f30aa94951bef366985c1eddb72922c255b2b3 (patch) | |
tree | b5c31870d5da08161f079cd3ba5440fe79d5175b /src/main/java/at/hannibal2 | |
parent | 613a8603d081589684c9f54133cae9b7a398c759 (diff) | |
download | skyhanni-03f30aa94951bef366985c1eddb72922c255b2b3.tar.gz skyhanni-03f30aa94951bef366985c1eddb72922c255b2b3.tar.bz2 skyhanni-03f30aa94951bef366985c1eddb72922c255b2b3.zip |
fixed stats tuning display
Diffstat (limited to 'src/main/java/at/hannibal2')
8 files changed, 121 insertions, 33 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt index baa9fa75e..384b0546d 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt @@ -1,9 +1,15 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.events.DrawScreenAfterEvent import at.hannibal2.skyhanni.events.GuiRenderItemEvent +import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent import at.hannibal2.skyhanni.events.RenderItemTipEvent +import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.renderer.GlStateManager +import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ItemTipHelper { @@ -22,12 +28,48 @@ class ItemTipHelper { GlStateManager.disableDepth() GlStateManager.disableBlend() - val x = event.x + 17 + itemTipEvent.offsetX - if (itemTipEvent.alignLeft) { - event.fontRenderer.getStringWidth(stackTip) - } else 0 - val y = event.y + 9 + itemTipEvent.offsetY + val fontRenderer = event.fontRenderer + val x = event.x + 17 - fontRenderer.getStringWidth(stackTip) + val y = event.y + 9 - event.fontRenderer.drawStringWithShadow(stackTip, x.toFloat(), y.toFloat(), 16777215) + fontRenderer.drawStringWithShadow(stackTip, x.toFloat(), y.toFloat(), 16777215) + GlStateManager.enableLighting() + GlStateManager.enableDepth() + } + + @SubscribeEvent(priority = EventPriority.HIGHEST) + fun onRenderInventoryItemOverlayPost(event: DrawScreenAfterEvent) { + if (!LorenzUtils.inSkyblock) return + + val gui = Minecraft.getMinecraft().currentScreen + if (gui !is GuiChest) return + + val guiLeft = (gui as AccessorGuiContainer).guiLeft + val guiTop = (gui as AccessorGuiContainer).guiTop + val fontRenderer = Minecraft.getMinecraft().fontRendererObj + + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.disableBlend() + for (slot in gui.inventorySlots.inventorySlots) { + val stack = slot.stack ?: continue + if (stack.stackSize != 1) continue + + val itemTipEvent = RenderInventoryItemTipEvent(stack) + itemTipEvent.postAndCatch() + val stackTip = itemTipEvent.stackTip + if (stackTip.isEmpty()) continue + + val xDisplayPosition = slot.xDisplayPosition + val yDisplayPosition = slot.yDisplayPosition + + val x = guiLeft + xDisplayPosition + 17 + itemTipEvent.offsetX - if (itemTipEvent.alignLeft) { + fontRenderer.getStringWidth(stackTip) + } else 0 + val y = guiTop + yDisplayPosition + 9 + itemTipEvent.offsetY + + fontRenderer.drawStringWithShadow(stackTip, x.toFloat(), y.toFloat(), 16777215) + } GlStateManager.enableLighting() GlStateManager.enableDepth() } diff --git a/src/main/java/at/hannibal2/skyhanni/events/DrawScreenAfterEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/DrawScreenAfterEvent.kt new file mode 100644 index 000000000..ba278df24 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/DrawScreenAfterEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events + +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo + +class DrawScreenAfterEvent(val mouseX: Int, val mouseY: Int, val ci: CallbackInfo) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/RenderInventoryItemTipEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/RenderInventoryItemTipEvent.kt new file mode 100644 index 000000000..4576576bd --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/RenderInventoryItemTipEvent.kt @@ -0,0 +1,11 @@ +package at.hannibal2.skyhanni.events + +import net.minecraft.item.ItemStack + +class RenderInventoryItemTipEvent( + val stack: ItemStack, + var stackTip: String = "", + var offsetX: Int = 0, + var offsetY: Int = 0, + var alignLeft: Boolean = true, +) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/RenderItemTipEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/RenderItemTipEvent.kt index 4da9f6e37..aa4831225 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/RenderItemTipEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/RenderItemTipEvent.kt @@ -5,7 +5,4 @@ import net.minecraft.item.ItemStack class RenderItemTipEvent( val stack: ItemStack, var stackTip: String = "", - var offsetX: Int = 0, - var offsetY: Int = 0, - var alignLeft: Boolean = true, ) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt index d25c2a0eb..bc1a5c9fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.RenderItemTipEvent +import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name @@ -21,7 +21,7 @@ class StatsTuning { private val patternStatPoints = Pattern.compile("§7Stat has: §e(\\d+) point(s)?") @SubscribeEvent - fun onRenderItemTip(event: RenderItemTipEvent) { + fun onRenderItemTip(event: RenderInventoryItemTipEvent) { val screen = Minecraft.getMinecraft().currentScreen if (screen !is GuiChest) return val chest = screen.inventorySlots as ContainerChest 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 d4287f074..f8e0e225a 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiContainerHook.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.mixins.hooks +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 @@ -20,13 +21,7 @@ class GuiContainerHook(guiAny: Any) { } fun backgroundDrawn(mouseX: Int, mouseY: Int, partialTicks: Float, ci: CallbackInfo) { - GuiContainerEvent.BackgroundDrawnEvent( - gui, - gui.inventorySlots, - mouseX, - mouseY, - partialTicks - ).postAndCatch() + GuiContainerEvent.BackgroundDrawnEvent(gui, gui.inventorySlots, mouseX, mouseY, partialTicks).postAndCatch() } fun foregroundDrawn(mouseX: Int, mouseY: Int, partialTicks: Float, ci: CallbackInfo) { @@ -34,12 +29,7 @@ class GuiContainerHook(guiAny: Any) { } fun onDrawSlot(slot: Slot, ci: CallbackInfo) { - if (GuiContainerEvent.DrawSlotEvent.Pre( - gui, - gui.inventorySlots, - slot - ).postAndCatch() - ) ci.cancel() + if (GuiContainerEvent.DrawSlotEvent.Pre(gui, gui.inventorySlots, slot).postAndCatch()) ci.cancel() } fun onDrawSlotPost(slot: Slot, ci: CallbackInfo) { @@ -47,15 +37,14 @@ class GuiContainerHook(guiAny: Any) { } fun onMouseClick(slot: Slot?, slotId: Int, clickedButton: Int, clickType: Int, ci: CallbackInfo) { - if ( - SlotClickEvent( - gui, - gui.inventorySlots, - slot, - slotId, - clickedButton, - clickType - ).postAndCatch() - ) ci.cancel() + if (SlotClickEvent(gui, gui.inventorySlots, slot, slotId, clickedButton, clickType).postAndCatch()) ci.cancel() + } + + fun onDrawScreenAfter( + mouseX: Int, + mouseY: Int, + ci: CallbackInfo, + ) { + if (DrawScreenAfterEvent(mouseX, mouseY, ci).postAndCatch()) ci.cancel() } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java new file mode 100644 index 000000000..e1e2c7c75 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/gui/AccessorGuiContainer.java @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.mixins.transformers.gui; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(GuiContainer.class) +public interface AccessorGuiContainer { + + @Invoker("getSlotAtPosition") + Slot doGetSlotAtPosition(int x, int y); + + @Invoker("drawSlot") + void doDrawSlot(Slot slot); + + @Invoker("isMouseOverSlot") + boolean doIsMouseOverSlot(Slot slot, int x, int y); + + @Accessor("guiLeft") + int getGuiLeft(); + + @Accessor("guiTop") + int getGuiTop(); + + @Accessor("xSize") + int getXSize(); + + @Accessor("ySize") + int getYSize(); + +} 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 3331c393f..a7fc852e5 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 @@ -45,4 +45,15 @@ public abstract class MixinGuiContainer extends GuiScreen { private void onMouseClick(Slot slot, int slotId, int clickedButton, int clickType, CallbackInfo ci) { hook.onMouseClick(slot, slotId, clickedButton, clickType, ci); } + + @Inject(method = "drawScreen", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V", + shift = At.Shift.AFTER + ) + ) + public void drawScreen_after(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { + hook.onDrawScreenAfter(mouseX, mouseY, ci); + } } |