1
1
package com.lambda.client.gui.hudgui.elements.player
2
2
3
3
import com.lambda.client.event.SafeClientEvent
4
- import com.lambda.client.event.events.ConnectionEvent
5
4
import com.lambda.client.event.events.PacketEvent
6
5
import 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
10
8
import com.lambda.client.util.graphics.GlStateUtils
11
9
import com.lambda.client.util.graphics.RenderUtils2D
12
10
import com.lambda.client.util.graphics.VertexHelper
13
11
import com.lambda.client.util.items.storageSlots
14
12
import com.lambda.client.util.math.Vec2d
15
13
import com.lambda.client.util.threads.runSafe
16
14
import com.lambda.client.util.threads.safeListener
17
- import net.minecraft.client.gui.inventory.GuiContainer
18
15
import net.minecraft.client.renderer.GlStateManager
19
16
import net.minecraft.client.renderer.Tessellator
20
17
import 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
26
18
import net.minecraft.network.play.server.SPacketOpenWindow
27
19
import net.minecraft.util.ResourceLocation
28
20
import net.minecraft.util.text.TextComponentTranslation
@@ -38,33 +30,32 @@ internal object InventoryViewer : HudElement(
38
30
private val showIcon by setting(" Show Icon" , false , { ! mcTexture })
39
31
private val iconScale by setting(" Icon Scale" , 0.5f , 0.1f .. 1.0f , 0.1f , { ! mcTexture && showIcon })
40
32
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 })
42
37
private val containerTexture = ResourceLocation (" textures/gui/container/inventory.png" )
43
38
private val lambdaIcon = ResourceLocation (" lambda/lambda_icon.png" )
44
- private var enderChestContents: MutableList <ItemStack > = MutableList (27 ) { ItemStack (Blocks .AIR ) }
45
39
46
40
override val hudWidth: Float = 162.0f
47
41
override val hudHeight: Float = 54.0f
48
42
49
- private var openedEnderChest: Int = - 1
50
-
51
43
override fun renderHud (vertexHelper : VertexHelper ) {
52
44
super .renderHud(vertexHelper)
53
45
runSafe {
54
46
drawFrame(vertexHelper)
55
47
drawFrameTexture()
56
- checkEnderChest()
57
48
drawItems()
58
49
}
59
50
}
60
51
61
52
private fun drawFrame (vertexHelper : VertexHelper ) {
62
53
if (! mcTexture) {
63
54
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 )
65
56
}
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 )
68
59
}
69
60
}
70
61
}
@@ -78,15 +69,15 @@ internal object InventoryViewer : HudElement(
78
69
mc.renderEngine.bindTexture(containerTexture)
79
70
buffer.begin(GL_TRIANGLE_STRIP , DefaultVertexFormats .POSITION_TEX )
80
71
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)
84
75
tessellator.draw()
85
76
} else if (showIcon) {
86
77
mc.renderEngine.bindTexture(lambdaIcon)
87
78
GlStateManager .glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR )
88
79
89
- val center = Vec2d (81 .0 , 27 .0 )
80
+ val center = Vec2d (hudWidth / 2 .0 , hudHeight / 2 .0 )
90
81
val halfWidth = iconScale * 50.0
91
82
val halfHeight = iconScale * 50.0
92
83
@@ -103,61 +94,33 @@ internal object InventoryViewer : HudElement(
103
94
104
95
105
96
init {
106
- safeListener<ConnectionEvent .Disconnect > {
107
- openedEnderChest = - 1
108
- }
109
-
110
97
safeListener<PacketEvent .Receive > {
111
98
if (it.packet !is SPacketOpenWindow ) return @safeListener
112
99
if (it.packet.guiId != " minecraft:container" ) return @safeListener
113
100
val title = it.packet.windowTitle
114
101
if (title !is TextComponentTranslation ) return @safeListener
115
102
if (title.key != " container.enderchest" ) return @safeListener
116
103
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
- }
140
104
}
141
105
}
142
106
143
107
private fun SafeClientEvent.drawItems () {
144
108
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())
151
114
}
152
115
} else {
153
116
for ((index, slot) in player.storageSlots.withIndex()) {
154
117
val itemStack = slot.stack
155
118
if (itemStack.isEmpty) continue
156
119
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
159
122
160
- RenderUtils2D .drawItem(itemStack, slotX, slotY)
123
+ RenderUtils2D .drawItem(itemStack, slotX.toInt() , slotY.toInt() )
161
124
}
162
125
}
163
126
}
0 commit comments