mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
network: fix item writing, gui: stack dropping
This commit is contained in:
parent
bc191c50a7
commit
04c0108257
@ -13,8 +13,10 @@
|
||||
package de.bixilon.minosoft.data.player
|
||||
|
||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedBiMapOf
|
||||
import de.bixilon.kutil.collections.CollectionUtil.synchronizedMapOf
|
||||
import de.bixilon.kutil.collections.map.LockMap
|
||||
import de.bixilon.kutil.collections.map.bi.SynchronizedBiMap
|
||||
import de.bixilon.kutil.math.MMath.clamp
|
||||
import de.bixilon.kutil.math.MMath.floor
|
||||
import de.bixilon.kutil.primitive.BooleanUtil.decide
|
||||
@ -83,7 +85,7 @@ class LocalPlayerEntity(
|
||||
val baseAbilities = Abilities()
|
||||
|
||||
val inventory = PlayerInventory(connection)
|
||||
val containers: MutableMap<Int, Container> = synchronizedMapOf(
|
||||
val containers: SynchronizedBiMap<Int, Container> = synchronizedBiMapOf(
|
||||
ProtocolDefinition.PLAYER_CONTAINER_ID to inventory,
|
||||
)
|
||||
var selectedHotbarSlot: Int = 0
|
||||
|
@ -147,6 +147,11 @@ open class Container(
|
||||
revision++
|
||||
}
|
||||
|
||||
|
||||
fun createAction(): Int {
|
||||
return 0 // ToDo
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<Map.Entry<Int, ItemStack>> {
|
||||
return slots.toSynchronizedMap().iterator()
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.VerticalAlignments.Compani
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ColorElement
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ImageElement
|
||||
import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
|
||||
import de.bixilon.minosoft.gui.rendering.gui.input.ModifierKeys
|
||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
||||
import de.bixilon.minosoft.gui.rendering.gui.popper.text.TextPopper
|
||||
@ -145,11 +146,21 @@ class ItemElement(
|
||||
return true
|
||||
}
|
||||
val container = container ?: return false
|
||||
val containerId = renderWindow.connection.player.containers.getKey(container) ?: return false
|
||||
val controlDown = guiRenderer.isKeyDown(ModifierKeys.CONTROL)
|
||||
val shiftDown = guiRenderer.isKeyDown(ModifierKeys.SHIFT)
|
||||
// ToDo
|
||||
when (key) {
|
||||
KeyCodes.KEY_Q -> {
|
||||
stack?.item?.decreaseCount()
|
||||
renderWindow.connection.sendPacket(ContainerClickC2SP(0, container.serverRevision, slotId, InventoryActions.DROP_ITEM, 0, mapOf(), stack))
|
||||
val action: InventoryActions
|
||||
if (controlDown) {
|
||||
stack?.item?.count = 0
|
||||
action = InventoryActions.DROP_STACK
|
||||
} else {
|
||||
stack?.item?.decreaseCount()
|
||||
action = InventoryActions.DROP_ITEM
|
||||
}
|
||||
renderWindow.connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, slotId, action, container.createAction(), mapOf(slotId to stack), stack))
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
@ -50,10 +50,12 @@ class PlayOutByteBuffer(val connection: PlayConnection) : OutByteBuffer() {
|
||||
writeNBT(itemStack.getNBT())
|
||||
return
|
||||
}
|
||||
writeBoolean(itemStack != null)
|
||||
if (itemStack == null || !itemStack._valid) {
|
||||
val valid = itemStack?._valid == true
|
||||
writeBoolean(valid)
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
itemStack!!
|
||||
writeVarInt(connection.registries.itemRegistry.getId(itemStack.item.item))
|
||||
writeByte(itemStack.item.count)
|
||||
writeNBT(itemStack.getNBT())
|
||||
|
Loading…
x
Reference in New Issue
Block a user