Skip to content

Commit

Permalink
collectcooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
RestartFU committed Jun 1, 2024
1 parent fe750f0 commit ffe1703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion server/block/hopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Hopper struct {
LastTick int64
// TransferCooldown is the duration until the hopper can transfer items again.
TransferCooldown int64
// CollectCooldown is the duration until the hopper can collect items again.
CollectCooldown int64

inventory *inventory.Inventory
viewerMu *sync.RWMutex
Expand Down Expand Up @@ -124,13 +126,16 @@ func (h Hopper) UseOnBlock(pos cube.Pos, face cube.Face, _ mgl64.Vec3, w *world.
// Tick ...
func (h Hopper) Tick(currentTick int64, pos cube.Pos, w *world.World) {
h.TransferCooldown--
h.CollectCooldown--
h.LastTick = currentTick
if h.TransferCooldown > 0 {

if h.TransferCooldown > 0 || h.CollectCooldown >= 0 {
w.SetBlock(pos, h, nil)
return
}

h.TransferCooldown = 0
h.CollectCooldown = 0
if h.Powered {
w.SetBlock(pos, h, nil)
return
Expand Down
7 changes: 5 additions & 2 deletions server/entity/item_behaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ func (i *ItemBehaviour) Item() item.Stack {
func (i *ItemBehaviour) Tick(e *Ent) *Movement {
w := e.World()
pos := cube.PosFromVec3(e.Position())
blockPos := pos.Side(cube.FaceDown)

bl, ok := w.Block(pos.Side(cube.FaceDown)).(block.Hopper)
if ok && !bl.Powered {
bl, ok := w.Block(blockPos).(block.Hopper)
if ok && !bl.Powered && bl.CollectCooldown <= 0 {
_, err := bl.Inventory().AddItem(i.i)
if err != nil {
// We couldn't add any of the item to the inventory, so we ignore it.
return i.passive.Tick(e)
}

_ = e.Close()
bl.CollectCooldown = 4
w.SetBlock(blockPos, bl, nil)
}
return i.passive.Tick(e)
}
Expand Down

0 comments on commit ffe1703

Please sign in to comment.