Hey! I apologize for the quality of the language - English is not my main language and I use a translator. I will be glad if you will correct me and speak simply.
For my purposes, to make a system like Applied Energystics, and at the moment I am solving the problem of the terminal GUI.
In similar mods, the storage grid GUI is made of slots, which seems to me not very attractive and crutch.
I just render GUI and stacks directly and capture mouse clicks.
When I click on an item, I send a packet to the server indicating the item and button. Further, the network puts the item for storage, and everything that it has not stored (or an empty stack) points to the player’s server representation and sends it to the client, where the client representation is similarly affixed.
Tell me, how bad is this method and what could I ignore?
PckGridTransfer (from client to server)
override fun onMessage(message: PckGridTransfer, ctx: MessageContext): IMessage? {
val player = ctx.serverHandler.player
val world = player.world as WorldServer
world.addScheduledTask {
// todo! check player has this item as holded
val host = ((player.openContainer as? AFactoryContainerNew<*>)?.tileEntity as? AFactoryTileGrid)?.host ?: return@addScheduledTask
// todo! message.push
val resultStack = host.storageProxy.putItemStackToStorage(message.stack, message.mouseButton)
player.inventory.itemStack = resultStack
TheMyMod.packetToPlayer(PckGridTransferResult(resultStack), player)
}
return null
}
PckGridTransferResult (from server to client)
override fun onMessage(message: PckGridTransferResult, ctx: MessageContext): IMessage? {
Minecraft.getMinecraft().addScheduledTask {
Minecraft.getMinecraft().player.inventory.itemStack = message.stack
}
return null
}