Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Username & InventoryViewer Improvement #354

Merged
merged 8 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ internal object Username : LabelHud(
private val suffix = setting("Suffix", "")

override fun SafeClientEvent.updateText() {
displayText.add(prefix.value, primaryColor)
if (prefix.value != "") displayText.add(prefix.value, primaryColor)
displayText.add(mc.session.username, secondaryColor)
displayText.add(suffix.value, primaryColor)
if (suffix.value != "") displayText.add(suffix.value, primaryColor)
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.lambda.client.gui.hudgui.elements.player

import com.lambda.client.event.SafeClientEvent
import com.lambda.client.event.events.ConnectionEvent
import com.lambda.client.event.events.PacketEvent
import com.lambda.client.gui.hudgui.HudElement
import com.lambda.client.mixin.extension.windowID
import com.lambda.client.module.modules.client.ClickGUI
import com.lambda.client.module.modules.client.GuiColors
import com.lambda.client.util.graphics.GlStateUtils
Expand All @@ -10,6 +13,7 @@ import com.lambda.client.util.graphics.VertexHelper
import com.lambda.client.util.items.storageSlots
import com.lambda.client.util.math.Vec2d
import com.lambda.client.util.threads.runSafe
import com.lambda.client.util.threads.safeListener
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
Expand All @@ -18,7 +22,10 @@ import net.minecraft.init.Blocks
import net.minecraft.inventory.ContainerChest
import net.minecraft.inventory.InventoryBasic
import net.minecraft.item.ItemStack
import net.minecraft.network.play.client.CPacketCloseWindow
import net.minecraft.network.play.server.SPacketOpenWindow
import net.minecraft.util.ResourceLocation
import net.minecraft.util.text.TextComponentTranslation
import org.lwjgl.opengl.GL11.*

internal object InventoryViewer : HudElement(
Expand All @@ -39,6 +46,8 @@ internal object InventoryViewer : HudElement(
override val hudWidth: Float = 162.0f
override val hudHeight: Float = 54.0f

private var openedEnderChest: Int = -1

override fun renderHud(vertexHelper: VertexHelper) {
super.renderHud(vertexHelper)
runSafe {
Expand Down Expand Up @@ -93,14 +102,40 @@ internal object InventoryViewer : HudElement(
}


init {
safeListener<ConnectionEvent.Disconnect> {
openedEnderChest = -1
}

safeListener<PacketEvent.Receive> {
if (it.packet !is SPacketOpenWindow) return@safeListener
if (it.packet.guiId != "minecraft:container") return@safeListener
val title = it.packet.windowTitle
if (title !is TextComponentTranslation) return@safeListener
if (title.key != "container.enderchest") return@safeListener

openedEnderChest = it.packet.windowId
}

safeListener<PacketEvent.PostSend> {
if (it.packet !is CPacketCloseWindow) return@safeListener
if (it.packet.windowID != openedEnderChest) return@safeListener

checkEnderChest()
openedEnderChest = -1
}
}

private fun checkEnderChest() {
if (mc.currentScreen is GuiContainer) {
val container = (mc.currentScreen as GuiContainer).inventorySlots
if (container is ContainerChest && container.lowerChestInventory is InventoryBasic) {
val inv = (container.lowerChestInventory as InventoryBasic)
if (inv.name.equals("Ender Chest", true)) {
for (i in 0..26) enderChestContents[i] = container.inventory[i]
}
val guiScreen = mc.currentScreen

if (guiScreen !is GuiContainer) return

val container = guiScreen.inventorySlots

if (container is ContainerChest && container.lowerChestInventory is InventoryBasic) {
if (container.windowId == openedEnderChest) {
for (i in 0..26) enderChestContents[i] = container.inventory[i]
}
}
}
Expand Down