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
+ import com.lambda.client.event.events.PacketEvent
4
6
import com.lambda.client.gui.hudgui.HudElement
7
+ import com.lambda.client.mixin.extension.windowID
5
8
import com.lambda.client.module.modules.client.ClickGUI
6
9
import com.lambda.client.module.modules.client.GuiColors
7
10
import com.lambda.client.util.graphics.GlStateUtils
@@ -10,6 +13,7 @@ import com.lambda.client.util.graphics.VertexHelper
10
13
import com.lambda.client.util.items.storageSlots
11
14
import com.lambda.client.util.math.Vec2d
12
15
import com.lambda.client.util.threads.runSafe
16
+ import com.lambda.client.util.threads.safeListener
13
17
import net.minecraft.client.gui.inventory.GuiContainer
14
18
import net.minecraft.client.renderer.GlStateManager
15
19
import net.minecraft.client.renderer.Tessellator
@@ -18,7 +22,10 @@ import net.minecraft.init.Blocks
18
22
import net.minecraft.inventory.ContainerChest
19
23
import net.minecraft.inventory.InventoryBasic
20
24
import net.minecraft.item.ItemStack
25
+ import net.minecraft.network.play.client.CPacketCloseWindow
26
+ import net.minecraft.network.play.server.SPacketOpenWindow
21
27
import net.minecraft.util.ResourceLocation
28
+ import net.minecraft.util.text.TextComponentTranslation
22
29
import org.lwjgl.opengl.GL11.*
23
30
24
31
internal object InventoryViewer : HudElement(
@@ -39,6 +46,8 @@ internal object InventoryViewer : HudElement(
39
46
override val hudWidth: Float = 162.0f
40
47
override val hudHeight: Float = 54.0f
41
48
49
+ private var openedEnderChest: Int = - 1
50
+
42
51
override fun renderHud (vertexHelper : VertexHelper ) {
43
52
super .renderHud(vertexHelper)
44
53
runSafe {
@@ -93,14 +102,40 @@ internal object InventoryViewer : HudElement(
93
102
}
94
103
95
104
105
+ init {
106
+ safeListener<ConnectionEvent .Disconnect > {
107
+ openedEnderChest = - 1
108
+ }
109
+
110
+ safeListener<PacketEvent .Receive > {
111
+ if (it.packet !is SPacketOpenWindow ) return @safeListener
112
+ if (it.packet.guiId != " minecraft:container" ) return @safeListener
113
+ val title = it.packet.windowTitle
114
+ if (title !is TextComponentTranslation ) return @safeListener
115
+ if (title.key != " container.enderchest" ) return @safeListener
116
+
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
+
96
129
private fun checkEnderChest () {
97
- if (mc.currentScreen is GuiContainer ) {
98
- val container = (mc.currentScreen as GuiContainer ).inventorySlots
99
- if (container is ContainerChest && container.lowerChestInventory is InventoryBasic ) {
100
- val inv = (container.lowerChestInventory as InventoryBasic )
101
- if (inv .name.equals(" Ender Chest" , true )) {
102
- for (i in 0 .. 26 ) enderChestContents[i] = container.inventory[i]
103
- }
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]
104
139
}
105
140
}
106
141
}
0 commit comments