inventory: fix wrong setting new item on click

This commit is contained in:
Bixilon 2022-02-25 00:15:01 +01:00
parent e2a91512be
commit c6e9d69044
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 11 additions and 15 deletions

View File

@ -45,12 +45,12 @@ class SimpleContainerAction(
floatingItem.lock()
val target = container.slots[slot]
try {
if (count == ContainerCounts.ALL) {
floatingItem.item._count = 0
} else {
floatingItem.item._count-- // don't use decrease, item + container is already locked
}
if (slot == null) {
if (count == ContainerCounts.ALL) {
floatingItem.item._count = 0
} else {
floatingItem.item._count-- // don't use decrease, item + container is already locked
}
return connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, null, 0, count.ordinal, container.createAction(this), mapOf(), null))
}
@ -65,7 +65,7 @@ class SimpleContainerAction(
}
// swap
container.floatingItem = target
container.slots[slot] = floatingItem
container._set(slot, floatingItem)
connection.sendPacket(ContainerClickC2SP(containerId, container.serverRevision, slot, 0, count.ordinal, container.createAction(this), mapOf(slot to target), target))
} finally {
floatingItem.commit()

View File

@ -113,7 +113,7 @@ open class Container(
revision++
}
private fun _set(slotId: Int, itemStack: ItemStack?): Boolean {
fun _set(slotId: Int, itemStack: ItemStack?): Boolean {
val previous = slots[slotId]
if (itemStack == null) {
if (previous == null) {

View File

@ -67,8 +67,8 @@ class ItemElement(
}
override fun onMouseEnter(position: Vec2i, absolute: Vec2i): Boolean {
renderWindow.window.cursorShape = CursorShapes.HAND
val stack = stack ?: return true
renderWindow.window.cursorShape = CursorShapes.HAND
popper = ItemInfoPopper(guiRenderer, absolute, stack).apply { show() }
hovered = true
cacheUpToDate = false
@ -132,14 +132,10 @@ class ItemElement(
return true
}
val container = itemsElement.container
val controlDown = guiRenderer.isKeyDown(ModifierKeys.CONTROL)
val shiftDown = guiRenderer.isKeyDown(ModifierKeys.SHIFT)
// ToDo
when (key) {
KeyCodes.KEY_Q -> {
container.invokeAction(DropContainerAction(slotId, controlDown))
}
if (key != KeyCodes.KEY_Q) { // ToDo: Make it configurable
return true
}
container.invokeAction(DropContainerAction(slotId, guiRenderer.isKeyDown(ModifierKeys.CONTROL)))
return true
}