Skip to content

Commit

Permalink
Update hopper.go
Browse files Browse the repository at this point in the history
  • Loading branch information
RestartFU committed May 29, 2024
1 parent 16e6672 commit 3eb264e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions server/block/hopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,13 @@ func (h Hopper) insertItem(pos cube.Pos, w *world.World) bool {
var (
sourceSlot int
sourceStack item.Stack

//targetStack item.Stack
//targetSlot int
)

for slot, stack := range h.inventory.Slots() {
for slot, stack := range h.inventory.Items() {
if stack.Empty() {
continue
}
fmt.Println(stack, slot)
sourceStack, sourceSlot = stack, slot
break
}
Expand All @@ -187,11 +185,21 @@ func (h Hopper) insertItem(pos cube.Pos, w *world.World) bool {
return false
}

_, err := dest.Inventory().AddItem(sourceStack.Grow(-sourceStack.Count() + 1))
if err != nil {
// The destination is full.
return false
if e, ok := dest.(HopperInsertable); !ok {
_, err := dest.Inventory().AddItem(sourceStack)
if err != nil {
// The destination is full.
return false
}
} else {
targetStack, targetSlot := e.InsertItem(sourceStack)
if targetStack.Empty() {
// The destination is full.
return false
}
_ = dest.Inventory().SetItem(targetSlot, targetStack)
}

_ = h.inventory.SetItem(sourceSlot, sourceStack.Grow(-1))
return true
}
Expand Down

0 comments on commit 3eb264e

Please sign in to comment.