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

Add Ender Chest to InventoryViewer (#68) #234

Merged
merged 3 commits into from
Feb 11, 2022
Merged
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 @@ -10,9 +10,15 @@ 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 net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.init.Blocks
import net.minecraft.inventory.Container
import net.minecraft.inventory.ContainerChest
import net.minecraft.inventory.InventoryBasic
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
import org.lwjgl.opengl.GL11.*

Expand All @@ -21,14 +27,15 @@ internal object InventoryViewer : HudElement(
category = Category.PLAYER,
description = "Items in Inventory"
) {
private val enderChest by setting("Inventory", SlotType.PLAYER)
private val mcTexture by setting("Minecraft Texture", false)
private val showIcon by setting("Show Icon", false, { !mcTexture })
private val iconScale by setting("Icon Scale", 0.5f, 0.1f..1.0f, 0.1f, { !mcTexture && showIcon })
private val background by setting("Background", true, { !mcTexture })
private val alpha by setting("Alpha", 150, 0..255, 1, { !mcTexture })

private val containerTexture = ResourceLocation("textures/gui/container/inventory.png")
private val lambdaIcon = ResourceLocation("lambda/lambda_icon.png")
private var enderChestContents: MutableList<ItemStack> = MutableList(27) { ItemStack(Blocks.AIR) }

override val hudWidth: Float = 162.0f
override val hudHeight: Float = 54.0f
Expand All @@ -38,6 +45,7 @@ internal object InventoryViewer : HudElement(
runSafe {
drawFrame(vertexHelper)
drawFrameTexture()
checkEnderChest()
drawItems()
}
}
Expand Down Expand Up @@ -85,16 +93,42 @@ internal object InventoryViewer : HudElement(
}
}


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]
}
}
}
}

private fun SafeClientEvent.drawItems() {
for ((index, slot) in player.storageSlots.withIndex()) {
val itemStack = slot.stack
if (itemStack.isEmpty) continue
if (enderChest == SlotType.ENDER_CHEST) {
for ((index, stack) in enderChestContents.withIndex()) {
if (stack.isEmpty) continue

val slotX = index % 9 * 18 + 1
val slotY = index / 9 * 18 + 1
RenderUtils2D.drawItem(stack, slotX, slotY)
}
} else {
for ((index, slot) in player.storageSlots.withIndex()) {
val itemStack = slot.stack
if (itemStack.isEmpty) continue

val slotX = index % 9 * 18 + 1
val slotY = index / 9 * 18 + 1
val slotX = index % 9 * 18 + 1
val slotY = index / 9 * 18 + 1

RenderUtils2D.drawItem(itemStack, slotX, slotY)
RenderUtils2D.drawItem(itemStack, slotX, slotY)
}
}
}

private enum class SlotType {
PLAYER, ENDER_CHEST
}
}