Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strictly remove arrow if it has been picked up #879

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/entity/item_behaviour.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func (i *ItemBehaviour) merge(e *Ent, other *Ent) bool {

// collect makes a collector collect the item (or at least part of it).
func (i *ItemBehaviour) collect(e *Ent, collector Collector) {
if !collector.CanCollect() {
return
}
w, pos := e.World(), e.Position()
n := collector.Collect(i.i)
if n == 0 {
Expand All @@ -156,6 +159,8 @@ func (i *ItemBehaviour) collect(e *Ent, collector Collector) {
// a player or a zombie.
type Collector interface {
world.Entity
// CanCollect returns whether the Collector is able to pick up an item or not.
CanCollect() bool
// Collect collects the stack passed. It is called if the Collector is standing near an item entity that
// may be picked up.
// The count of items collected from the stack n is returned.
Expand Down
6 changes: 6 additions & 0 deletions server/entity/projectile.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func (lt *ProjectileBehaviour) tryPickup(e *Ent) {
if !ok {
continue
}

if !collector.CanCollect() {
continue
}

// A collector was within range to pick up the entity.
lt.close = true
for _, viewer := range w.Viewers(e.pos) {
Expand All @@ -229,6 +234,7 @@ func (lt *ProjectileBehaviour) tryPickup(e *Ent) {
if lt.conf.PickupItem.Empty() {
return
}

_ = collector.Collect(lt.conf.PickupItem)
}
}
Expand Down
17 changes: 13 additions & 4 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -2046,13 +2046,22 @@ func (p *Player) Rotation() cube.Rotation {
return cube.Rotation{p.yaw.Load(), p.pitch.Load()}
}

// Collect makes the player collect the item stack passed, adding it to the inventory. The amount of items that could
// be added is returned.
func (p *Player) Collect(s item.Stack) int {
// CanCollect returns whether the player is able to pick up an item stack or not.
func (p *Player) CanCollect() bool {
if p.Dead() {
return 0
return false
}
if !p.GameMode().AllowsInteraction() {
return false
}

return true
}

// Collect makes the player collect the item stack passed, adding it to the inventory. The amount of items that could
// be added is returned.
func (p *Player) Collect(s item.Stack) int {
if !p.CanCollect() {
return 0
}
ctx := event.C()
Expand Down
Loading