Skip to content

Commit 16ad9e2

Browse files
authored
Username & InventoryViewer Improvement (#354)
* Username Bugfix Fixes 1-space blank when prefix or suffix is defined with blank * Improved EnderChest Desync Problem(Desyncs when player close ender chest and moved item at same time), Now catches Ender chest in any language with using TextComponentTranslation.key instead of name(This method needed to use SPacketOpenWindow. * Refactored by Avanatiker * Small fix * Refactored by Avanatiker 2
1 parent 7b223c8 commit 16ad9e2

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/main/kotlin/com/lambda/client/gui/hudgui/elements/client/Username.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ internal object Username : LabelHud(
1313
private val suffix = setting("Suffix", "")
1414

1515
override fun SafeClientEvent.updateText() {
16-
displayText.add(prefix.value, primaryColor)
16+
if (prefix.value != "") displayText.add(prefix.value, primaryColor)
1717
displayText.add(mc.session.username, secondaryColor)
18-
displayText.add(suffix.value, primaryColor)
18+
if (suffix.value != "") displayText.add(suffix.value, primaryColor)
1919
}
2020

21-
}
21+
}

src/main/kotlin/com/lambda/client/gui/hudgui/elements/player/InventoryViewer.kt

+42-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.lambda.client.gui.hudgui.elements.player
22

33
import com.lambda.client.event.SafeClientEvent
4+
import com.lambda.client.event.events.ConnectionEvent
5+
import com.lambda.client.event.events.PacketEvent
46
import com.lambda.client.gui.hudgui.HudElement
7+
import com.lambda.client.mixin.extension.windowID
58
import com.lambda.client.module.modules.client.ClickGUI
69
import com.lambda.client.module.modules.client.GuiColors
710
import com.lambda.client.util.graphics.GlStateUtils
@@ -10,6 +13,7 @@ import com.lambda.client.util.graphics.VertexHelper
1013
import com.lambda.client.util.items.storageSlots
1114
import com.lambda.client.util.math.Vec2d
1215
import com.lambda.client.util.threads.runSafe
16+
import com.lambda.client.util.threads.safeListener
1317
import net.minecraft.client.gui.inventory.GuiContainer
1418
import net.minecraft.client.renderer.GlStateManager
1519
import net.minecraft.client.renderer.Tessellator
@@ -18,7 +22,10 @@ import net.minecraft.init.Blocks
1822
import net.minecraft.inventory.ContainerChest
1923
import net.minecraft.inventory.InventoryBasic
2024
import net.minecraft.item.ItemStack
25+
import net.minecraft.network.play.client.CPacketCloseWindow
26+
import net.minecraft.network.play.server.SPacketOpenWindow
2127
import net.minecraft.util.ResourceLocation
28+
import net.minecraft.util.text.TextComponentTranslation
2229
import org.lwjgl.opengl.GL11.*
2330

2431
internal object InventoryViewer : HudElement(
@@ -39,6 +46,8 @@ internal object InventoryViewer : HudElement(
3946
override val hudWidth: Float = 162.0f
4047
override val hudHeight: Float = 54.0f
4148

49+
private var openedEnderChest: Int = -1
50+
4251
override fun renderHud(vertexHelper: VertexHelper) {
4352
super.renderHud(vertexHelper)
4453
runSafe {
@@ -93,14 +102,40 @@ internal object InventoryViewer : HudElement(
93102
}
94103

95104

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+
96129
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]
104139
}
105140
}
106141
}

0 commit comments

Comments
 (0)