#[Kotlin] [ScreenHandler] Inventory GUI is unusable! How do i fix it? I followed documentation.

14 messages · Page 1 of 1 (latest)

tulip dune
#

The GUI is screwed! i mostly followed the fabricmc.net/wiki/tutorial:screenhandler page, im on 1.20 and it just wont work! some times in my code might have changed but i have to translate from java to kotlin anyways.

Here's my screen handler's code: https://pastebin.com/Bqs3L1DZ

Issues im having overall:

There's no dragging items from a slot to another! it's just click on one, then click on the target slot which is awful.

The container's slot (which are generated on the fly) Don't work, and infact act like the player's armor slot? despite showing the items that the inventory of the container holds.

It seems like the rows of the player inventory are offset??

How do i fix this?

tulip dune
#

decided to do a sanity checked, created a java file, pasted in the example from the tutorial AND EVEN THAT DOESN'T WORK what am i doing wrong?

verbal shuttle
#

how are you opening the screen handler

tulip dune
#

the screen is opened with

client?.setScreen(BarterInputScreen(BarterInputScreenHandler(0, client?.player?.inventory!!, SimpleInventory(9)), client?.player?.inventory, this))

and this is the screen's source


class BarterInputScreen(handler: BarterInputScreenHandler?,
                        inventory: PlayerInventory?,
                        parent: Screen
) : HandledScreen<BarterInputScreenHandler>(handler, inventory, Text.translatable("gui.autoquest.barter.inputscreentitle")) {
    private val parent = parent
    private val texture = Identifier("minecraft", "textures/gui/container/dispenser.png")
    override fun drawBackground(context: DrawContext, delta: Float , mouseX: Int, mouseY: Int) {
        RenderSystem.setShader(GameRenderer::getPositionTexProgram)
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F)
        RenderSystem.setShaderTexture(0, texture)
        var x = (width - backgroundWidth) / 2
        var y = (height - backgroundHeight) / 2
        context.drawTexture(texture, x, y, 0, 0, backgroundWidth, backgroundHeight)
    }

    override fun close() {
        super.close()
        client?.setScreen(parent)
    }
}
verbal shuttle
#

yeah I don't think you can do that

#

screen handlers are both sides

#

so you'd only be setting it on the client

tulip dune
#

so what should i do?

verbal shuttle
#

use PlayerEntity#openHandledScreen but you have to call it from the server

#

and make sure you register your screen handler types and handled screens

tulip dune
#

alright ill give that a try

jovial musk
#

HA

tulip dune
#

works now @verbal shuttle thanks alot!

#

pinged the wrong one 😭