Skip to content
Merged
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
8 changes: 2 additions & 6 deletions simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,12 +1018,8 @@ func (s *Simulator) isInsideCobweb(state *MovementState) bool {
continue
}

boxes := s.World.BlockCollisions(pos)
for _, box := range boxes {
if bb.IntersectsWith(box.Translate(posVec3(pos))) {
insideCobweb = true
break
}
if bb.IntersectsWith(cube.Box32(0, 0, 0, 1, 1, 1).Translate(posVec3(pos))) {
insideCobweb = true
}
if insideCobweb {
break
Expand Down
23 changes: 21 additions & 2 deletions simulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type cobwebWorld struct {
pos cube.Pos
}

type nonCollidingCobwebWorld struct {
cobwebWorld
}

func (w cobwebWorld) Block(pos cube.Pos) world.Block {
if pos == w.pos {
return block.Cobweb{}
Expand All @@ -54,6 +58,10 @@ func (w cobwebWorld) BlockCollisions(pos cube.Pos) []cube.BBox32 {
return []cube.BBox32{cube.Box32(0, 0, 0, 1, 1, 1)}
}

func (nonCollidingCobwebWorld) BlockCollisions(cube.Pos) []cube.BBox32 {
return nil
}

func (cobwebWorld) GetNearbyBBoxes(cube.BBox32) []cube.BBox32 {
return nil
}
Expand Down Expand Up @@ -147,14 +155,25 @@ func newBaseState() *MovementState {
}
}

func TestInsideCobwebTranslatesBlockLocalCollisionBoxes(t *testing.T) {
func TestInsideCobwebTranslatesBlockVolume(t *testing.T) {
pos := cube.Pos{32, 64, -24}
sim := &Simulator{World: cobwebWorld{pos: pos}}
state := newBaseState()
state.Pos = mgl32.Vec3{float32(pos.X()) + 0.5, float32(pos.Y()), float32(pos.Z()) + 0.5}

if !sim.isInsideCobweb(state) {
t.Fatal("expected collision with block-local cobweb box away from the origin")
t.Fatal("expected intersection with translated cobweb block volume away from the origin")
}
}

func TestInsideCobwebUsesFullBlockVolumeWithoutCollisionBoxes(t *testing.T) {
pos := cube.Pos{32, 64, -24}
sim := &Simulator{World: nonCollidingCobwebWorld{cobwebWorld{pos: pos}}}
state := newBaseState()
state.Pos = mgl32.Vec3{float32(pos.X()) + 0.5, float32(pos.Y()), float32(pos.Z()) + 0.5}

if !sim.isInsideCobweb(state) {
t.Fatal("expected a non-collidable cobweb to occupy its full block volume")
}
}

Expand Down