11package com.lambda.client.gui.hudgui.elements.player
22
33import com.lambda.client.event.SafeClientEvent
4- import com.lambda.client.event.events.ConnectionEvent
54import com.lambda.client.event.events.PacketEvent
65import com.lambda.client.gui.hudgui.HudElement
7- import com.lambda.client.mixin.extension.windowID
8- import com.lambda.client.module.modules.client.ClickGUI
9- import com.lambda.client.module.modules.client.GuiColors
6+ import com.lambda.client.manager.managers.CachedContainerManager
7+ import com.lambda.client.util.color.ColorHolder
108import com.lambda.client.util.graphics.GlStateUtils
119import com.lambda.client.util.graphics.RenderUtils2D
1210import com.lambda.client.util.graphics.VertexHelper
1311import com.lambda.client.util.items.storageSlots
1412import com.lambda.client.util.math.Vec2d
1513import com.lambda.client.util.threads.runSafe
1614import com.lambda.client.util.threads.safeListener
17- import net.minecraft.client.gui.inventory.GuiContainer
1815import net.minecraft.client.renderer.GlStateManager
1916import net.minecraft.client.renderer.Tessellator
2017import net.minecraft.client.renderer.vertex.DefaultVertexFormats
21- import net.minecraft.init.Blocks
22- import net.minecraft.inventory.ContainerChest
23- import net.minecraft.inventory.InventoryBasic
24- import net.minecraft.item.ItemStack
25- import net.minecraft.network.play.client.CPacketCloseWindow
2618import net.minecraft.network.play.server.SPacketOpenWindow
2719import net.minecraft.util.ResourceLocation
2820import net.minecraft.util.text.TextComponentTranslation
@@ -38,33 +30,32 @@ internal object InventoryViewer : HudElement(
3830 private val showIcon by setting(" Show Icon" , false , { ! mcTexture })
3931 private val iconScale by setting(" Icon Scale" , 0.5f , 0.1f .. 1.0f , 0.1f , { ! mcTexture && showIcon })
4032 private val background by setting(" Background" , true , { ! mcTexture })
41- private val alpha by setting(" Alpha" , 150 , 0 .. 255 , 1 , { ! mcTexture })
33+ private val backgroundColor by setting(" Background Color" , ColorHolder (0 , 0 , 0 , 150 ), visibility = { ! mcTexture && background })
34+ private val outline by setting(" Outline" , true , visibility = { ! mcTexture })
35+ private val outlineColor by setting(" Outline Color" , ColorHolder (255 , 255 , 255 , 150 ), visibility = { ! mcTexture && outline })
36+ private val outlineThickness by setting(" Outline Thickness" , 1.0f , 0.5f .. 5.0f , 0.5f , { ! mcTexture && outline })
4237 private val containerTexture = ResourceLocation (" textures/gui/container/inventory.png" )
4338 private val lambdaIcon = ResourceLocation (" lambda/lambda_icon.png" )
44- private var enderChestContents: MutableList <ItemStack > = MutableList (27 ) { ItemStack (Blocks .AIR ) }
4539
4640 override val hudWidth: Float = 162.0f
4741 override val hudHeight: Float = 54.0f
4842
49- private var openedEnderChest: Int = - 1
50-
5143 override fun renderHud (vertexHelper : VertexHelper ) {
5244 super .renderHud(vertexHelper)
5345 runSafe {
5446 drawFrame(vertexHelper)
5547 drawFrameTexture()
56- checkEnderChest()
5748 drawItems()
5849 }
5950 }
6051
6152 private fun drawFrame (vertexHelper : VertexHelper ) {
6253 if (! mcTexture) {
6354 if (background) {
64- RenderUtils2D .drawRectFilled(vertexHelper, posEnd = Vec2d (162.0 , 54.0 ) , color = GuiColors .backGround. apply { a = alpha } )
55+ RenderUtils2D .drawRectFilled(vertexHelper, posEnd = Vec2d (hudWidth.toDouble(), hudHeight.toDouble()) , color = backgroundColor )
6556 }
66- if (ClickGUI .windowOutline ) {
67- RenderUtils2D .drawRectOutline(vertexHelper, posEnd = Vec2d (162.0 , 54.0 ) , lineWidth = ClickGUI .outlineWidth , color = GuiColors .outline. apply { a = alpha } )
57+ if (outline ) {
58+ RenderUtils2D .drawRectOutline(vertexHelper, posEnd = Vec2d (hudWidth.toDouble(), hudHeight.toDouble()) , lineWidth = outlineThickness , color = outlineColor )
6859 }
6960 }
7061 }
@@ -78,15 +69,15 @@ internal object InventoryViewer : HudElement(
7869 mc.renderEngine.bindTexture(containerTexture)
7970 buffer.begin(GL_TRIANGLE_STRIP , DefaultVertexFormats .POSITION_TEX )
8071 buffer.pos(0.0 , 0.0 , 0.0 ).tex(0.02734375 , 0.32421875 ).endVertex() // (7 / 256), (83 / 256)
81- buffer.pos(0.0 , 54.0 , 0.0 ).tex(0.02734375 , 0.53125 ).endVertex() // (7 / 256), (136 / 256)
82- buffer.pos(162.0 , 0.0 , 0.0 ).tex(0.65625 , 0.32421875 ).endVertex() // (168 / 256), (83 / 256)
83- buffer.pos(162.0 , 54.0 , 0.0 ).tex(0.65625 , 0.53125 ).endVertex() // (168 / 256), (136 / 256)
72+ buffer.pos(0.0 , hudHeight.toDouble() , 0.0 ).tex(0.02734375 , 0.53125 ).endVertex() // (7 / 256), (136 / 256)
73+ buffer.pos(hudWidth.toDouble() , 0.0 , 0.0 ).tex(0.65625 , 0.32421875 ).endVertex() // (168 / 256), (83 / 256)
74+ buffer.pos(hudWidth.toDouble(), hudHeight.toDouble() , 0.0 ).tex(0.65625 , 0.53125 ).endVertex() // (168 / 256), (136 / 256)
8475 tessellator.draw()
8576 } else if (showIcon) {
8677 mc.renderEngine.bindTexture(lambdaIcon)
8778 GlStateManager .glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR )
8879
89- val center = Vec2d (81 .0 , 27 .0 )
80+ val center = Vec2d (hudWidth / 2 .0 , hudHeight / 2 .0 )
9081 val halfWidth = iconScale * 50.0
9182 val halfHeight = iconScale * 50.0
9283
@@ -103,61 +94,33 @@ internal object InventoryViewer : HudElement(
10394
10495
10596 init {
106- safeListener<ConnectionEvent .Disconnect > {
107- openedEnderChest = - 1
108- }
109-
11097 safeListener<PacketEvent .Receive > {
11198 if (it.packet !is SPacketOpenWindow ) return @safeListener
11299 if (it.packet.guiId != " minecraft:container" ) return @safeListener
113100 val title = it.packet.windowTitle
114101 if (title !is TextComponentTranslation ) return @safeListener
115102 if (title.key != " container.enderchest" ) return @safeListener
116103
117- openedEnderChest = it.packet.windowId
118- }
119-
120- safeListener<PacketEvent .PostSend > {
121- if (it.packet !is CPacketCloseWindow ) return @safeListener
122- if (it.packet.windowID != openedEnderChest) return @safeListener
123-
124- checkEnderChest()
125- openedEnderChest = - 1
126- }
127- }
128-
129- private fun checkEnderChest () {
130- val guiScreen = mc.currentScreen
131-
132- if (guiScreen !is GuiContainer ) return
133-
134- val container = guiScreen.inventorySlots
135-
136- if (container is ContainerChest && container.lowerChestInventory is InventoryBasic ) {
137- if (container.windowId == openedEnderChest) {
138- for (i in 0 .. 26 ) enderChestContents[i] = container.inventory[i]
139- }
140104 }
141105 }
142106
143107 private fun SafeClientEvent.drawItems () {
144108 if (enderChest == SlotType .ENDER_CHEST ) {
145- for ((index, stack) in enderChestContents.withIndex()) {
146- if (stack.isEmpty) continue
147-
148- val slotX = index % 9 * 18 + 1
149- val slotY = index / 9 * 18 + 1
150- RenderUtils2D .drawItem(stack, slotX, slotY)
109+ CachedContainerManager .getEnderChestInventory().forEachIndexed { index, stack ->
110+ if (stack.isEmpty) return @forEachIndexed
111+ val slotX = index % 9 * (hudWidth / 9.0 ) + 1
112+ val slotY = index / 9 * (hudWidth / 9.0 ) + 1
113+ RenderUtils2D .drawItem(stack, slotX.toInt(), slotY.toInt())
151114 }
152115 } else {
153116 for ((index, slot) in player.storageSlots.withIndex()) {
154117 val itemStack = slot.stack
155118 if (itemStack.isEmpty) continue
156119
157- val slotX = index % 9 * 18 + 1
158- val slotY = index / 9 * 18 + 1
120+ val slotX = index % 9 * (hudWidth / 9.0 ) + 1
121+ val slotY = index / 9 * (hudWidth / 9.0 ) + 1
159122
160- RenderUtils2D .drawItem(itemStack, slotX, slotY)
123+ RenderUtils2D .drawItem(itemStack, slotX.toInt() , slotY.toInt() )
161124 }
162125 }
163126 }
0 commit comments