Skip to content

Commit

Permalink
place single item in inv
Browse files Browse the repository at this point in the history
  • Loading branch information
j0code committed Mar 23, 2024
1 parent 8c320ce commit ec7e02c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/util/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class Container {
if (!mouseSlot) return false

if (button == 0) {
if (input.keyPressed("ShiftLeft")) {
if (input.keyPressed("ShiftLeft")) { // move stack to hotbar
const stack = inventory.get(mouseSlot.slotIndex)

if (stack.item.id == "tiny:air") return false
Expand All @@ -139,6 +139,23 @@ export default class Container {
if (floatingStackIndex == undefined && stack.item.id != "tiny:air") floatingStackIndex = mouseSlot.slotIndex
else if (stack.item.id == "tiny:air" || floatingStackIndex == mouseSlot.slotIndex) floatingStackIndex = undefined
}
} else if (button == 2) {
if (floatingStackIndex == undefined) {
// TODO: pick up half stack
} else {
const stack = inventory.get(mouseSlot.slotIndex)
const floating = Container.floatingStack()!

if (stack.item.id == "tiny:air") {
inventory.set(mouseSlot.slotIndex, new ItemStack(floating.item, 1))
if (floating.amount > 1) floating.amount--
else inventory.set(floatingStackIndex, new ItemStack("tiny:air", 1))
} else if (stack.match(floating)) {
stack.amount++
if (floating.amount > 1) floating.amount--
else inventory.set(floatingStackIndex, new ItemStack("tiny:air", 1))
}
}
}

return true
Expand Down

0 comments on commit ec7e02c

Please sign in to comment.