@@ -22,6 +22,8 @@ import com.lambda.config.settings.complex.Bind
2222import com.lambda.interaction.material.container.containers.EnderChestContainer
2323import com.lambda.module.Module
2424import com.lambda.module.tag.ModuleTag
25+ import com.lambda.threading.runSafe
26+ import com.lambda.util.InputUtils.isSatisfied
2527import com.lambda.util.KeyCode
2628import com.lambda.util.item.ItemStackUtils.shulkerBoxContents
2729import com.lambda.util.item.ItemUtils.shulkerBoxes
@@ -30,13 +32,14 @@ import net.minecraft.client.font.TextRenderer
3032import net.minecraft.client.gui.DrawContext
3133import net.minecraft.client.gui.tooltip.TooltipComponent
3234import net.minecraft.client.gl.RenderPipelines
35+ import net.minecraft.client.gui.screen.ingame.HandledScreen
3336import net.minecraft.item.BlockItem
3437import net.minecraft.item.ItemStack
3538import net.minecraft.item.Items
3639import net.minecraft.item.tooltip.TooltipData
40+ import net.minecraft.screen.slot.Slot
3741import net.minecraft.util.DyeColor
3842import net.minecraft.util.Identifier
39- import org.lwjgl.glfw.GLFW
4043
4144object ContainerPreview : Module(
4245 name = " ContainerPreview" ,
@@ -48,7 +51,12 @@ object ContainerPreview : Module(
4851
4952 private val background = Identifier .ofVanilla(" textures/gui/container/shulker_box.png" )
5053
54+ private var lockedSlot: Slot ? = null
5155 private var lockedStack: ItemStack ? = null
56+ set(value) {
57+ if (value != = field) lockedSlot = null
58+ field = value
59+ }
5260 private var lockedX: Int = 0
5361 private var lockedY: Int = 0
5462
@@ -64,14 +72,7 @@ object ContainerPreview : Module(
6472
6573 @JvmStatic
6674 val isLocked: Boolean
67- get() = lockedStack != null
68-
69- @JvmStatic
70- fun isLockKeyPressed (): Boolean {
71- if (! isEnabled) return false
72- val handle = mc.window.handle
73- return GLFW .glfwGetKey(handle, lockKey.key) == GLFW .GLFW_PRESS
74- }
75+ get() = lockedSlot != null
7576
7677 private fun getTooltipWidth () = PADDING + COLS * SLOT_SIZE + PADDING
7778 private fun getTooltipHeight () = TITLE_HEIGHT + ROWS * SLOT_SIZE + PADDING
@@ -104,38 +105,41 @@ object ContainerPreview : Module(
104105 fun renderShulkerTooltip (
105106 context : DrawContext ,
106107 textRenderer : TextRenderer ,
107- component : ContainerComponent ,
108108 mouseX : Int ,
109109 mouseY : Int
110- ) {
110+ ) = runSafe {
111+ val handledScreen = mc.currentScreen as ? HandledScreen <* > ? : return @runSafe
112+ val slot = handledScreen.focusedSlot ? : return @runSafe
113+
111114 val width = getTooltipWidth()
112115 val height = getTooltipHeight()
113116
114- val lockKeyPressed = isLockKeyPressed ()
117+ val lockKeyPressed = lockKey.isSatisfied ()
115118
116- if (lockKeyPressed && lockedStack == null ) {
117- lockedStack = component.stack.copy()
119+ if (lockKeyPressed && lockedSlot == null ) {
120+ lockedSlot = slot
118121 lockedX = calculateTooltipX(mouseX, width)
119122 lockedY = calculateTooltipY(mouseY, height)
120- } else if (! lockKeyPressed && lockedStack != null ) {
121- lockedStack = null
123+ } else if (! lockKeyPressed && lockedSlot != null ) {
124+ lockedSlot = null
122125 }
123126
124127 if (isLocked) {
125128 renderLockedTooltipInternal(context, textRenderer)
126- return
129+ return @runSafe
127130 }
128131
129- renderTooltipForStack(context, textRenderer, component .stack, calculateTooltipX(mouseX, width), calculateTooltipY(mouseY, height), false )
132+ renderTooltipForStack(context, textRenderer, slot .stack, calculateTooltipX(mouseX, width), calculateTooltipY(mouseY, height), false )
130133 }
131134
132135 /* *
133136 * Render the locked tooltip - called from mixin when we're locked
134137 */
135138 @JvmStatic
136139 fun renderLockedTooltip (context : DrawContext , textRenderer : TextRenderer ) {
137- if (! isLockKeyPressed()) {
138- lockedStack = null
140+ lockedStack = lockedSlot?.stack
141+ if (! lockKey.isSatisfied() || lockedSlot?.stack?.isEmpty == true ) {
142+ lockedSlot = null
139143 return
140144 }
141145 renderLockedTooltipInternal(context, textRenderer)
0 commit comments