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

Remove resending blocks for obstructedPos #807

Closed
wants to merge 18 commits into from
Closed
Changes from 13 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
17 changes: 12 additions & 5 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,10 @@ func (p *Player) placeBlock(pos cube.Pos, b world.Block, ignoreBBox bool) bool {
p.resendBlocks(pos, w, cube.Faces()...)
return false
}
if !ignoreBBox && p.obstructedPos(pos, b) {
p.resendBlocks(pos, w, cube.Faces()...)
if ok, resend := p.obstructedPos(pos, b); !ignoreBBox && ok {
if resend {
p.resendBlocks(pos, w, cube.Faces()...)
}
return false
}

Expand All @@ -1718,25 +1720,30 @@ func (p *Player) placeBlock(pos cube.Pos, b world.Block, ignoreBBox bool) bool {

// obstructedPos checks if the position passed is obstructed if the block passed is attempted to be placed.
// The function returns true if there is an entity in the way that could prevent the block from being placed.
func (p *Player) obstructedPos(pos cube.Pos, b world.Block) bool {
func (p *Player) obstructedPos(pos cube.Pos, b world.Block) (bool, bool) {
w := p.World()
blockBoxes := b.Model().BBox(pos, w)
for i, box := range blockBoxes {
blockBoxes[i] = box.Translate(pos.Vec3())
}

resend := true
around := w.EntitiesWithin(cube.Box(-3, -3, -3, 3, 3, 3).Translate(pos.Vec3()), nil)
for _, e := range around {
switch e.Type().(type) {
case entity.ItemType, entity.ArrowType:
continue
default:
if e == p {
resend = false
}
Comment on lines +1772 to +1774
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section isn't entirely clear to me. If any of the entities in this 7x7x7 bounding box is the player itself, it will not resend. This doesn't quite sound right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is enough latency the client position might be in the block that the client wants to be placed.
You can easily try this out by having >=150ms and stacking blocks under you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything I would first move this block inside of the if cube.AnyIntersections {} block, because the player might not even be intersecting in the first place. But then I'm still not sure if it would work as expected. Imagine there was another player that this intersected with, in addition to the player itself, should it be resent or not?


if cube.AnyIntersections(blockBoxes, e.Type().BBox(e).Translate(e.Position()).Grow(-1e-6)) {
return true
return true, resend
}
}
}
return false
return false, resend
}

// BreakBlock makes the player break a block in the world at a position passed. If the player is unable to
Expand Down
Loading