Skip to content

Commit

Permalink
fix rendering of items client side by using menu instead of container
Browse files Browse the repository at this point in the history
  • Loading branch information
ATPStorages committed Aug 30, 2024
1 parent d5db20f commit bf5cf82
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package breadmod.client.screen.sound_block
import breadmod.menu.block.SoundBlockMenu
import breadmod.network.serverbound.SoundBlockPacket
import breadmod.util.gui.SerializedScreen
import breadmod.util.gui.widget.ContainerWidget
import breadmod.util.gui.widget.InventoryWidget
import breadmod.util.gui.widget.ItemContainerWidget
import breadmod.util.gui.widget.SlotWidget
import breadmod.util.gui.widget.TextWidget
import breadmod.util.gui.widget.*
import breadmod.util.render.rgMinecraft
import com.mojang.blaze3d.platform.InputConstants
import net.minecraft.client.gui.GuiGraphics
Expand Down Expand Up @@ -60,9 +56,7 @@ internal class SoundBlockSerializedScreen(
InventoryWidget(8, 88, pInventory, pMenu),
0.0
).addWidget(
ItemContainerWidget(0, 0, 16, 16, pMenu.slots[36].container, menu).also {
it.x = 10
it.y = 10
ItemContainerWidget(10, 10, 16, 16, pMenu.slots[36].container, pMenu).also {
it.addWidget(SlotWidget(0, 0, it, 36), 0.0)
}, 0.0
).addWidget(
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/breadmod/util/gui/widget/ContainerWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.joml.Matrix4f
import kotlin.reflect.KClass
import kotlin.reflect.full.isSubclassOf

typealias ContainedWidgets = MutableMap<AbstractWidget, Pair<Double, String?>>

/**
* A widget that can contain other widgets.
* @param pWidth The width of the widget.
Expand All @@ -39,7 +41,7 @@ open class ContainerWidget(
pWidth: Int, pHeight: Int,
private val pTilt: Float,
pComponent: Component,
private val childrenWidgets: MutableMap<AbstractWidget, Pair<Double, String?>>
private val childrenWidgets: ContainedWidgets
) : AbstractWidget(pX, pY, pWidth, pHeight, pComponent) {
private val associationMap: MutableMap<String, AbstractWidget> = mutableMapOf()

Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/breadmod/util/gui/widget/ListContainerWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ import net.minecraft.network.chat.Component
* @param pY The Y position this widget will render at.
* @param pWidth The width of this widget.
* @param pHeight The height of this widget.
*
* @author Miko Elbrecht
* @since 1.0.0
*/
class ListContainerWidget(
pX: Int, pY: Int,
pWidth: Int, pHeight: Int,

pScrollBarWidth: Int,
pBackgroundComponents: MutableMap<AbstractWidget, Pair<Double, String?>>
) : ContainerWidget(pX, pY, pWidth, pHeight, 0f, Component.empty(), pBackgroundComponents) {
pBackgroundComponents: ContainedWidgets,
pScrollComponents: ContainedWidgets
) : ContainerWidget(pX, pY, pWidth, pHeight, 0f, Component.empty(), mutableMapOf()) {
val scrollContentsContainer = ContainerWidget(
0, 0,
pWidth - pScrollBarWidth, pHeight, 0f,
Component.empty(), mutableMapOf()
)

override fun addWidget(pWidget: AbstractWidget, pZIndex: Double, pTag: String?): ContainerWidget {
if (pWidget !is RowContainerWidget)
throw UnsupportedOperationException("ListContainerWidget only supports RowContainerWidgets")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/breadmod/util/gui/widget/SlotWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SlotWidget(
private val hoverColor = Color(1f, 1f, 1f, 0.5f).rgb

override fun renderWidget(pGuiGraphics: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTick: Float) {
val stack = pParent.pContainer.getItem(slot)
val stack = pParent.pContainerMenu.getSlot(slot).item
val notEmpty = !stack.isEmpty

if (notEmpty) {
Expand Down

0 comments on commit bf5cf82

Please sign in to comment.