Skip to content

Commit 8004a6f

Browse files
committed
player/player.go: placeBlock: Only resend blocks if entities other than the player itself obstruct a position.
Closes #807.
1 parent f4a6aa2 commit 8004a6f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

server/player/player.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,13 @@ func (p *Player) placeBlock(pos cube.Pos, b world.Block, ignoreBBox bool) bool {
18401840
p.resendBlocks(pos, cube.Faces()...)
18411841
return false
18421842
}
1843-
if !ignoreBBox && p.obstructedPos(pos, b) {
1844-
p.resendBlocks(pos, cube.Faces()...)
1843+
if obstructed, selfOnly := p.obstructedPos(pos, b); obstructed && !ignoreBBox {
1844+
if !selfOnly {
1845+
// Only resend blocks if there were other entities blocking the
1846+
// placement than the player itself. Resending blocks placed inside
1847+
// the player itself leads to synchronisation issues.
1848+
p.resendBlocks(pos, cube.Faces()...)
1849+
}
18451850
return false
18461851
}
18471852

@@ -1856,9 +1861,13 @@ func (p *Player) placeBlock(pos cube.Pos, b world.Block, ignoreBBox bool) bool {
18561861
return true
18571862
}
18581863

1859-
// obstructedPos checks if the position passed is obstructed if the block passed is attempted to be placed.
1860-
// The function returns true if there is an entity in the way that could prevent the block from being placed.
1861-
func (p *Player) obstructedPos(pos cube.Pos, b world.Block) bool {
1864+
// obstructedPos checks if the position passed is obstructed if the block
1865+
// passed is attempted to be placed. The function returns true as the first
1866+
// bool if there is an entity in the way that could prevent the block from
1867+
// being placed.
1868+
// If the only entity preventing the block from being placed is the player
1869+
// itself, the second bool returned is true too.
1870+
func (p *Player) obstructedPos(pos cube.Pos, b world.Block) (obstructed, selfOnly bool) {
18621871
blockBoxes := b.Model().BBox(pos, p.tx)
18631872
for i, box := range blockBoxes {
18641873
blockBoxes[i] = box.Translate(pos.Vec3())
@@ -1871,11 +1880,15 @@ func (p *Player) obstructedPos(pos cube.Pos, b world.Block) bool {
18711880
continue
18721881
default:
18731882
if cube.AnyIntersections(blockBoxes, t.BBox(e).Translate(e.Position()).Grow(-1e-6)) {
1874-
return true
1883+
obstructed = true
1884+
if e.H() == p.handle {
1885+
continue
1886+
}
1887+
return true, false
18751888
}
18761889
}
18771890
}
1878-
return false
1891+
return obstructed, true
18791892
}
18801893

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

0 commit comments

Comments
 (0)