@@ -50,17 +50,14 @@ object ContainerPreview : Module(
5050
5151 private val background = Identifier .ofVanilla(" textures/gui/container/shulker_box.png" )
5252
53- // Locked tooltip state - store the stack instead of component for persistence
5453 private var lockedStack: ItemStack ? = null
5554 private var lockedX: Int = 0
5655 private var lockedY: Int = 0
5756
58- // Flag to prevent recursive tooltip rendering
5957 @JvmStatic
6058 var isRenderingSubTooltip: Boolean = false
6159 private set
6260
63- // Tooltip dimensions (3 rows x 9 columns like shulker box)
6461 private const val ROWS = 3
6562 private const val COLS = 9
6663 private const val SLOT_SIZE = 18
@@ -79,8 +76,8 @@ object ContainerPreview : Module(
7976 return GLFW .glfwGetKey(handle, lockKey.key) == GLFW .GLFW_PRESS
8077 }
8178
82- private fun getTooltipWidth (): Int = PADDING + COLS * SLOT_SIZE + PADDING
83- private fun getTooltipHeight (): Int = TITLE_HEIGHT + ROWS * SLOT_SIZE + PADDING
79+ private fun getTooltipWidth () = PADDING + COLS * SLOT_SIZE + PADDING
80+ private fun getTooltipHeight () = TITLE_HEIGHT + ROWS * SLOT_SIZE + PADDING
8481
8582 /* *
8683 * Check if mouse is over the locked tooltip area (for click blocking)
@@ -102,40 +99,36 @@ object ContainerPreview : Module(
10299 val r = ((tintColor shr 16 ) and 0xFF ) / 255f
103100 val g = ((tintColor shr 8 ) and 0xFF ) / 255f
104101 val b = (tintColor and 0xFF ) / 255f
105-
106- // Calculate relative luminance using standard formula
107102 val luminance = 0.299f * r + 0.587f * g + 0.114f * b
108-
109- // Use dark text on light backgrounds, white text on dark backgrounds
110103 return if (luminance > 0.5f ) 0x404040 else 0xFFFFFF
111104 }
112105
113106 @JvmStatic
114- fun renderShulkerTooltip (context : DrawContext , textRenderer : TextRenderer , component : ContainerComponent , mouseX : Int , mouseY : Int ) {
115- // Calculate tooltip position
107+ fun renderShulkerTooltip (
108+ context : DrawContext ,
109+ textRenderer : TextRenderer ,
110+ component : ContainerComponent ,
111+ mouseX : Int ,
112+ mouseY : Int
113+ ) {
116114 val width = getTooltipWidth()
117115 val height = getTooltipHeight()
118116
119- // Handle locking - lock when key is pressed while hovering a shulker
120117 val lockKeyPressed = isLockKeyPressed()
121118
122119 if (lockKeyPressed && lockedStack == null ) {
123- // Lock when key is pressed while hovering
124- lockedStack = component.stack.copy() // Copy the stack to preserve it
120+ lockedStack = component.stack.copy()
125121 lockedX = calculateTooltipX(mouseX, width)
126122 lockedY = calculateTooltipY(mouseY, height)
127123 } else if (! lockKeyPressed && lockedStack != null ) {
128- // Unlock when key is released
129124 lockedStack = null
130125 }
131126
132- // If locked, delegate to renderLockedTooltip
133127 if (isLocked) {
134128 renderLockedTooltipInternal(context, textRenderer)
135129 return
136130 }
137131
138- // Not locked - render normal tooltip following mouse
139132 renderTooltipForStack(context, textRenderer, component.stack, calculateTooltipX(mouseX, width), calculateTooltipY(mouseY, height), false )
140133 }
141134
@@ -144,7 +137,6 @@ object ContainerPreview : Module(
144137 */
145138 @JvmStatic
146139 fun renderLockedTooltip (context : DrawContext , textRenderer : TextRenderer ) {
147- // Update lock state - unlock if key released
148140 if (! isLockKeyPressed()) {
149141 lockedStack = null
150142 return
@@ -166,22 +158,16 @@ object ContainerPreview : Module(
166158 matrices.push()
167159 matrices.translate(0f , 0f , 400f )
168160
169- // Get container color (shulker box color or purple for ender chest)
170161 val tintColor = getContainerTintColor(stack)
171162
172- // Draw background with color tint
173163 drawBackground(context, x, y, width, height, tintColor)
174-
175- // Draw title (container name) with appropriate text color
176164 val name = stack.name
177165 val textColor = getTextColor(tintColor)
178166 context.drawText(textRenderer, name, x + PADDING , y + 4 , textColor, false )
179167
180- // Slots start at padding offset, items are centered in 18px slots (1px padding on each side)
181168 val slotsStartX = x + PADDING
182169 val slotsStartY = y + TITLE_HEIGHT
183170
184- // Get actual mouse position for hover detection
185171 val actualMouseX = (mc.mouse.x * mc.window.scaledWidth / mc.window.width).toInt()
186172 val actualMouseY = (mc.mouse.y * mc.window.scaledHeight / mc.window.height).toInt()
187173
@@ -195,22 +181,16 @@ object ContainerPreview : Module(
195181 val slotCol = index % COLS
196182 val slotRow = index / COLS
197183
198- // Slot bounds (full 18x18 area for hover detection)
199184 val slotX = slotsStartX + slotCol * SLOT_SIZE
200185 val slotY = slotsStartY + slotRow * SLOT_SIZE
201-
202- // Item position (centered in slot with 1px offset)
203186 val itemX = slotX + 1
204187 val itemY = slotY + 1
205188
206- // Check if this slot is hovered (only when locked/allowHover)
207- // Use full slot size (18x18) for hover detection to avoid dead zones
208189 if (allowHover) {
209190 val isHovered = actualMouseX >= slotX && actualMouseX < slotX + SLOT_SIZE &&
210191 actualMouseY >= slotY && actualMouseY < slotY + SLOT_SIZE
211192
212193 if (isHovered && ! item.isEmpty) {
213- // Draw highlight on the item area (16x16)
214194 context.fill(itemX, itemY, itemX + 16 , itemY + 16 , 0x80FFFFFF .toInt())
215195 hoveredStack = item
216196 hoveredSlotX = actualMouseX
@@ -226,24 +206,20 @@ object ContainerPreview : Module(
226206
227207 matrices.pop()
228208
229- // Draw sub-tooltip for hovered item at higher Z level
230- if (hoveredStack != null && allowHover) {
209+ hoveredStack?.let { stack ->
231210 matrices.push()
232- matrices.translate(0f , 0f , 500f ) // Higher Z than the main tooltip
211+ matrices.translate(0f , 0f , 500f )
233212
234- // Check if hovered item is also a previewable container (shulker in echest)
235- if (isPreviewableContainer(hoveredStack)) {
236- // Render nested container preview recursively
213+ if (isPreviewableContainer(stack)) {
237214 val nestedWidth = getTooltipWidth()
238215 val nestedHeight = getTooltipHeight()
239216 val nestedX = calculateTooltipX(hoveredSlotX, nestedWidth)
240217 val nestedY = calculateTooltipY(hoveredSlotY, nestedHeight)
241- renderTooltipForStack(context, textRenderer, hoveredStack , nestedX, nestedY, false )
218+ renderTooltipForStack(context, textRenderer, stack , nestedX, nestedY, false )
242219 } else {
243- // Regular item tooltip - use mixin bypass flag
244220 isRenderingSubTooltip = true
245221 try {
246- context.drawItemTooltip(textRenderer, hoveredStack , hoveredSlotX, hoveredSlotY)
222+ context.drawItemTooltip(textRenderer, stack , hoveredSlotX, hoveredSlotY)
247223 } finally {
248224 isRenderingSubTooltip = false
249225 }
@@ -268,10 +244,7 @@ object ContainerPreview : Module(
268244 val color = getShulkerColor(stack)
269245 color?.entityColor ? : 0xFFFFFFFF .toInt()
270246 }
271- isEnderChest(stack) -> {
272- // Ender chest purple/dark tint
273- 0xFF1E1E2E .toInt()
274- }
247+ isEnderChest(stack) -> 0xFF1E1E2E .toInt()
275248 else -> 0xFFFFFFFF .toInt()
276249 }
277250 }
@@ -297,11 +270,6 @@ object ContainerPreview : Module(
297270 }
298271
299272 private fun drawBackground (context : DrawContext , x : Int , y : Int , width : Int , height : Int , tintColor : Int ) {
300- // Extract RGB components for tinting
301- val r = ((tintColor shr 16 ) and 0xFF ) / 255f
302- val g = ((tintColor shr 8 ) and 0xFF ) / 255f
303- val b = (tintColor and 0xFF ) / 255f
304-
305273 // Draw the shulker box texture background with tint
306274 // The shulker_box.png texture is 176x166
307275 // Top part (title area): y=0 to y=17
@@ -319,17 +287,17 @@ object ContainerPreview : Module(
319287 )
320288
321289 // Middle rows
322- for (row in 0 until ROWS ) {
323- context.drawTexture(
324- RenderLayer ::getGuiTextured,
325- background,
326- x, y + TITLE_HEIGHT + row * SLOT_SIZE ,
327- 0f , 17f ,
328- width, SLOT_SIZE ,
329- 256 , 256 ,
330- tintColor
331- )
332- }
290+ ( 0 until ROWS ).forEach { row ->
291+ context.drawTexture(
292+ RenderLayer ::getGuiTextured,
293+ background,
294+ x, y + TITLE_HEIGHT + row * SLOT_SIZE ,
295+ 0f , 17f ,
296+ width, SLOT_SIZE ,
297+ 256 , 256 ,
298+ tintColor
299+ )
300+ }
333301
334302 // Bottom
335303 context.drawTexture(
@@ -355,35 +323,17 @@ object ContainerPreview : Module(
355323 }
356324
357325 @JvmStatic
358- fun isShulkerBox (stack : ItemStack ): Boolean {
359- return stack.item in shulkerBoxes
360- }
326+ fun isShulkerBox (stack : ItemStack ) = stack.item in shulkerBoxes
361327
362328 @JvmStatic
363- fun isEnderChest (stack : ItemStack ): Boolean {
364- return stack.item == Items .ENDER_CHEST && EnderChestContainer .stacks.isNotEmpty()
365- }
329+ fun isEnderChest (stack : ItemStack ) = stack.item == Items .ENDER_CHEST && EnderChestContainer .stacks.isNotEmpty()
366330
367331 @JvmStatic
368- fun isPreviewableContainer (stack : ItemStack ): Boolean {
369- return isShulkerBox(stack) || isEnderChest(stack)
370- }
332+ fun isPreviewableContainer (stack : ItemStack ) = isShulkerBox(stack) || isEnderChest(stack)
371333
372334 open class ContainerComponent (val stack : ItemStack ) : TooltipData, TooltipComponent {
373- val contents: List <ItemStack >
374- get() = when {
375- isShulkerBox(stack) -> stack.shulkerBoxContents
376- isEnderChest(stack) -> EnderChestContainer .stacks
377- else -> emptyList()
378- }
379-
380- // These methods are not used since we render the tooltip ourselves
381335 override fun drawItems (textRenderer : TextRenderer , x : Int , y : Int , width : Int , height : Int , context : DrawContext ) {}
382336 override fun getHeight (textRenderer : TextRenderer ): Int = 0
383337 override fun getWidth (textRenderer : TextRenderer ): Int = 0
384338 }
385-
386- // Keep for backwards compatibility
387- @Deprecated(" Use ContainerComponent instead" , ReplaceWith (" ContainerComponent" ))
388- class ShulkerComponent (stack : ItemStack ) : ContainerComponent(stack)
389339}
0 commit comments