mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -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
|
package de.bixilon.minosoft.data.player
|
||||||
|
|
||||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
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.CollectionUtil.synchronizedMapOf
|
||||||
import de.bixilon.kutil.collections.map.LockMap
|
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.clamp
|
||||||
import de.bixilon.kutil.math.MMath.floor
|
import de.bixilon.kutil.math.MMath.floor
|
||||||
import de.bixilon.kutil.primitive.BooleanUtil.decide
|
import de.bixilon.kutil.primitive.BooleanUtil.decide
|
||||||
@ -83,7 +85,7 @@ class LocalPlayerEntity(
|
|||||||
val baseAbilities = Abilities()
|
val baseAbilities = Abilities()
|
||||||
|
|
||||||
val inventory = PlayerInventory(connection)
|
val inventory = PlayerInventory(connection)
|
||||||
val containers: MutableMap<Int, Container> = synchronizedMapOf(
|
val containers: SynchronizedBiMap<Int, Container> = synchronizedBiMapOf(
|
||||||
ProtocolDefinition.PLAYER_CONTAINER_ID to inventory,
|
ProtocolDefinition.PLAYER_CONTAINER_ID to inventory,
|
||||||
)
|
)
|
||||||
var selectedHotbarSlot: Int = 0
|
var selectedHotbarSlot: Int = 0
|
||||||
|
@ -147,6 +147,11 @@ open class Container(
|
|||||||
revision++
|
revision++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun createAction(): Int {
|
||||||
|
return 0 // ToDo
|
||||||
|
}
|
||||||
|
|
||||||
override fun iterator(): Iterator<Map.Entry<Int, ItemStack>> {
|
override fun iterator(): Iterator<Map.Entry<Int, ItemStack>> {
|
||||||
return slots.toSynchronizedMap().iterator()
|
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.ColorElement
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ImageElement
|
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.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.GUIVertexConsumer
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.popper.text.TextPopper
|
import de.bixilon.minosoft.gui.rendering.gui.popper.text.TextPopper
|
||||||
@ -145,11 +146,21 @@ class ItemElement(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val container = container ?: return false
|
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
|
// ToDo
|
||||||
when (key) {
|
when (key) {
|
||||||
KeyCodes.KEY_Q -> {
|
KeyCodes.KEY_Q -> {
|
||||||
stack?.item?.decreaseCount()
|
val action: InventoryActions
|
||||||
renderWindow.connection.sendPacket(ContainerClickC2SP(0, container.serverRevision, slotId, InventoryActions.DROP_ITEM, 0, mapOf(), stack))
|
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
|
return true
|
||||||
|
@ -50,10 +50,12 @@ class PlayOutByteBuffer(val connection: PlayConnection) : OutByteBuffer() {
|
|||||||
writeNBT(itemStack.getNBT())
|
writeNBT(itemStack.getNBT())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeBoolean(itemStack != null)
|
val valid = itemStack?._valid == true
|
||||||
if (itemStack == null || !itemStack._valid) {
|
writeBoolean(valid)
|
||||||
|
if (!valid) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
itemStack!!
|
||||||
writeVarInt(connection.registries.itemRegistry.getId(itemStack.item.item))
|
writeVarInt(connection.registries.itemRegistry.getId(itemStack.item.item))
|
||||||
writeByte(itemStack.item.count)
|
writeByte(itemStack.item.count)
|
||||||
writeNBT(itemStack.getNBT())
|
writeNBT(itemStack.getNBT())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user