From a4d1a51c1f079887479cd000fb20b4e4c9bba66b Mon Sep 17 00:00:00 2001 From: ethaniccc <59127626+ethaniccc@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:33:49 -0400 Subject: [PATCH] block/model: Use new world.BlockSource instead of world.World for easier use as an individual package (#923) --- server/block/model/anvil.go | 4 ++-- server/block/model/cactus.go | 4 ++-- server/block/model/cake.go | 4 ++-- server/block/model/campfire.go | 4 ++-- server/block/model/carpet.go | 4 ++-- server/block/model/chain.go | 4 ++-- server/block/model/chest.go | 4 ++-- server/block/model/cocoa_bean.go | 4 ++-- server/block/model/composter.go | 7 ++++--- server/block/model/decorated_pot.go | 4 ++-- server/block/model/door.go | 4 ++-- server/block/model/empty.go | 4 ++-- server/block/model/enchanting_table.go | 4 ++-- server/block/model/fence.go | 8 ++++---- server/block/model/fence_gate.go | 4 ++-- server/block/model/grindstone.go | 4 ++-- server/block/model/hopper.go | 4 ++-- server/block/model/ladder.go | 4 ++-- server/block/model/lantern.go | 4 ++-- server/block/model/leaves.go | 4 ++-- server/block/model/lectern.go | 4 ++-- server/block/model/skull.go | 4 ++-- server/block/model/slab.go | 4 ++-- server/block/model/solid.go | 4 ++-- server/block/model/stair.go | 18 +++++++++--------- server/block/model/stonecutter.go | 4 ++-- server/block/model/thin.go | 8 ++++---- server/block/model/tilled_grass.go | 4 ++-- server/block/model/trapdoor.go | 4 ++-- server/block/model/wall.go | 4 ++-- server/world/block_model.go | 8 ++++---- server/world/block_source.go | 9 +++++++++ 32 files changed, 86 insertions(+), 76 deletions(-) create mode 100644 server/world/block_source.go diff --git a/server/block/model/anvil.go b/server/block/model/anvil.go index ba8c45f6f..899e25889 100644 --- a/server/block/model/anvil.go +++ b/server/block/model/anvil.go @@ -12,11 +12,11 @@ type Anvil struct { } // BBox ... -func (a Anvil) BBox(cube.Pos, *world.World) []cube.BBox { +func (a Anvil) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{full.Stretch(a.Facing.RotateLeft().Face().Axis(), -0.125)} } // FaceSolid ... -func (Anvil) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Anvil) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/cactus.go b/server/block/model/cactus.go index 4a0853107..b7566c575 100644 --- a/server/block/model/cactus.go +++ b/server/block/model/cactus.go @@ -9,11 +9,11 @@ import ( type Cactus struct{} // BBox returns a physics.BBox that is slightly smaller than a full block. -func (Cactus) BBox(cube.Pos, *world.World) []cube.BBox { +func (Cactus) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0.025, 0, 0.025, 0.975, 1, 0.975)} } // FaceSolid always returns false. -func (Cactus) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Cactus) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/cake.go b/server/block/model/cake.go index 558e9e83a..ab575c93e 100644 --- a/server/block/model/cake.go +++ b/server/block/model/cake.go @@ -13,12 +13,12 @@ type Cake struct { } // BBox returns an BBox with a size that depends on the amount of bites taken. -func (c Cake) BBox(cube.Pos, *world.World) []cube.BBox { +func (c Cake) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0.0625, 0, 0.0625, 0.9375, 0.5, 0.9375). ExtendTowards(cube.FaceWest, -(float64(c.Bites) / 8))} } // FaceSolid always returns false. -func (c Cake) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (c Cake) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/campfire.go b/server/block/model/campfire.go index 8c4f816e3..ae13f8363 100644 --- a/server/block/model/campfire.go +++ b/server/block/model/campfire.go @@ -9,11 +9,11 @@ import ( type Campfire struct{} // BBox returns a flat BBox with a height of 0.4375. -func (Campfire) BBox(cube.Pos, *world.World) []cube.BBox { +func (Campfire) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0, 0, 0, 1, 0.4375, 1)} } // FaceSolid returns true if the face is down. -func (Campfire) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (Campfire) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face == cube.FaceDown } diff --git a/server/block/model/carpet.go b/server/block/model/carpet.go index 444f25de2..4d5ce1568 100644 --- a/server/block/model/carpet.go +++ b/server/block/model/carpet.go @@ -9,11 +9,11 @@ import ( type Carpet struct{} // BBox returns a flat BBox with a width of 0.0625. -func (Carpet) BBox(cube.Pos, *world.World) []cube.BBox { +func (Carpet) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0, 0, 0, 1, 0.0625, 1)} } // FaceSolid always returns false. -func (Carpet) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Carpet) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/chain.go b/server/block/model/chain.go index 345c875e2..459b431a2 100644 --- a/server/block/model/chain.go +++ b/server/block/model/chain.go @@ -12,11 +12,11 @@ type Chain struct { } // BBox ... -func (c Chain) BBox(cube.Pos, *world.World) []cube.BBox { +func (c Chain) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0.40625, 0.40625, 0.40625, 0.59375, 0.59375, 0.59375).Stretch(c.Axis, 0.40625)} } // FaceSolid ... -func (Chain) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Chain) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/chest.go b/server/block/model/chest.go index 98b52741b..2adde25e5 100644 --- a/server/block/model/chest.go +++ b/server/block/model/chest.go @@ -10,11 +10,11 @@ import ( type Chest struct{} // BBox returns a physics.BBox that is slightly smaller than a full block. -func (Chest) BBox(cube.Pos, *world.World) []cube.BBox { +func (Chest) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0.025, 0, 0.025, 0.975, 0.95, 0.975)} } // FaceSolid always returns false. -func (Chest) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Chest) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/cocoa_bean.go b/server/block/model/cocoa_bean.go index 81160ae76..d61493ba3 100644 --- a/server/block/model/cocoa_bean.go +++ b/server/block/model/cocoa_bean.go @@ -15,7 +15,7 @@ type CocoaBean struct { } // BBox returns a single physics.BBox whose size depends on the age of the CocoaBean. -func (c CocoaBean) BBox(cube.Pos, *world.World) []cube.BBox { +func (c CocoaBean) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{full. Stretch(c.Facing.RotateRight().Face().Axis(), -(6-float64(c.Age))/16). ExtendTowards(cube.FaceDown, -0.25). @@ -25,6 +25,6 @@ func (c CocoaBean) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid always returns false. -func (c CocoaBean) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (c CocoaBean) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/composter.go b/server/block/model/composter.go index bde940f10..338b256c5 100644 --- a/server/block/model/composter.go +++ b/server/block/model/composter.go @@ -1,9 +1,10 @@ package model import ( + "math" + "github.com/df-mc/dragonfly/server/block/cube" "github.com/df-mc/dragonfly/server/world" - "math" ) // Composter is a model used by composter blocks. It is solid on all sides apart from the top, and the height of the @@ -14,7 +15,7 @@ type Composter struct { } // BBox ... -func (c Composter) BBox(_ cube.Pos, _ *world.World) []cube.BBox { +func (c Composter) BBox(_ cube.Pos, _ world.BlockSource) []cube.BBox { compostHeight := math.Abs(math.Min(float64(c.Level), 7)*0.125 - 0.0625) return []cube.BBox{ cube.Box(0, 0, 0, 1, 1, 0.125), @@ -26,6 +27,6 @@ func (c Composter) BBox(_ cube.Pos, _ *world.World) []cube.BBox { } // FaceSolid returns true for all faces other than the top. -func (Composter) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (Composter) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face != cube.FaceUp } diff --git a/server/block/model/decorated_pot.go b/server/block/model/decorated_pot.go index aeb39f66b..d9a7e343d 100644 --- a/server/block/model/decorated_pot.go +++ b/server/block/model/decorated_pot.go @@ -10,11 +10,11 @@ import ( type DecoratedPot struct{} // BBox returns a physics.BBox that is slightly smaller than a full block. -func (DecoratedPot) BBox(cube.Pos, *world.World) []cube.BBox { +func (DecoratedPot) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0.025, 0, 0.025, 0.975, 1, 0.975)} } // FaceSolid always returns true for the top and bottom face, and false for all other faces. -func (DecoratedPot) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (DecoratedPot) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face.Axis() == cube.Y } diff --git a/server/block/model/door.go b/server/block/model/door.go index 4216c27ed..66cb5a802 100644 --- a/server/block/model/door.go +++ b/server/block/model/door.go @@ -18,7 +18,7 @@ type Door struct { // BBox returns a physics.BBox that depends on if the Door is open, what direction it is facing and whether it is // attached to the right/left side of a block. -func (d Door) BBox(cube.Pos, *world.World) []cube.BBox { +func (d Door) BBox(cube.Pos, world.BlockSource) []cube.BBox { if d.Open { if d.Right { return []cube.BBox{full.ExtendTowards(d.Facing.RotateLeft().Face(), -0.8125)} @@ -29,6 +29,6 @@ func (d Door) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid always returns false. -func (d Door) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (d Door) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/empty.go b/server/block/model/empty.go index cf6c66b98..949ae97c3 100644 --- a/server/block/model/empty.go +++ b/server/block/model/empty.go @@ -9,11 +9,11 @@ import ( type Empty struct{} // BBox returns an empty slice. -func (Empty) BBox(cube.Pos, *world.World) []cube.BBox { +func (Empty) BBox(cube.Pos, world.BlockSource) []cube.BBox { return nil } // FaceSolid always returns false. -func (Empty) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Empty) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/enchanting_table.go b/server/block/model/enchanting_table.go index 66933d5e1..57ecb1ac2 100644 --- a/server/block/model/enchanting_table.go +++ b/server/block/model/enchanting_table.go @@ -9,11 +9,11 @@ import ( type EnchantingTable struct{} // BBox ... -func (EnchantingTable) BBox(cube.Pos, *world.World) []cube.BBox { +func (EnchantingTable) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0, 0, 0, 1, 0.75, 1)} } // FaceSolid ... -func (EnchantingTable) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (EnchantingTable) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/fence.go b/server/block/model/fence.go index 787e1086e..08a3eb28a 100644 --- a/server/block/model/fence.go +++ b/server/block/model/fence.go @@ -14,7 +14,7 @@ type Fence struct { } // BBox returns multiple physics.BBox depending on how many connections it has with the surrounding blocks. -func (f Fence) BBox(pos cube.Pos, w *world.World) []cube.BBox { +func (f Fence) BBox(pos cube.Pos, s world.BlockSource) []cube.BBox { const offset = 0.375 boxes := make([]cube.BBox, 0, 5) @@ -22,9 +22,9 @@ func (f Fence) BBox(pos cube.Pos, w *world.World) []cube.BBox { for i := cube.Face(2); i < 6; i++ { pos := pos.Side(i) - block := w.Block(pos) + block := s.Block(pos) - if fence, ok := block.Model().(Fence); (ok && fence.Wood == f.Wood) || block.Model().FaceSolid(pos, i, w) { + if fence, ok := block.Model().(Fence); (ok && fence.Wood == f.Wood) || block.Model().FaceSolid(pos, i, s) { boxes = append(boxes, mainBox.ExtendTowards(i, offset)) } else if _, ok := block.Model().(FenceGate); ok { boxes = append(boxes, mainBox.ExtendTowards(i, offset)) @@ -34,6 +34,6 @@ func (f Fence) BBox(pos cube.Pos, w *world.World) []cube.BBox { } // FaceSolid returns true if the face is cube.FaceDown or cube.FaceUp. -func (f Fence) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (f Fence) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face == cube.FaceDown || face == cube.FaceUp } diff --git a/server/block/model/fence_gate.go b/server/block/model/fence_gate.go index 6ee64a3f1..e87728e4f 100644 --- a/server/block/model/fence_gate.go +++ b/server/block/model/fence_gate.go @@ -15,7 +15,7 @@ type FenceGate struct { } // BBox returns up to one physics.BBox depending on the facing direction of the FenceGate and whether it is open. -func (f FenceGate) BBox(cube.Pos, *world.World) []cube.BBox { +func (f FenceGate) BBox(cube.Pos, world.BlockSource) []cube.BBox { if f.Open { return nil } @@ -23,6 +23,6 @@ func (f FenceGate) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid always returns false. -func (f FenceGate) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (f FenceGate) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/grindstone.go b/server/block/model/grindstone.go index a92149c83..85c2a5813 100644 --- a/server/block/model/grindstone.go +++ b/server/block/model/grindstone.go @@ -12,11 +12,11 @@ type Grindstone struct { } // BBox ... -func (g Grindstone) BBox(cube.Pos, *world.World) []cube.BBox { +func (g Grindstone) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0.125, 0.125, 0.125, 0.825, 0.825, 0.825).Stretch(g.Axis, 0.125)} } // FaceSolid always returns false. -func (g Grindstone) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (g Grindstone) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/hopper.go b/server/block/model/hopper.go index f84821545..da0c18dfa 100644 --- a/server/block/model/hopper.go +++ b/server/block/model/hopper.go @@ -9,7 +9,7 @@ import ( type Hopper struct{} // BBox returns a physics.BBox that spans a full block. -func (h Hopper) BBox(cube.Pos, *world.World) []cube.BBox { +func (h Hopper) BBox(cube.Pos, world.BlockSource) []cube.BBox { bbox := []cube.BBox{full.ExtendTowards(cube.FaceUp, -0.375)} for _, f := range cube.HorizontalFaces() { bbox = append(bbox, full.ExtendTowards(f, -0.875)) @@ -18,6 +18,6 @@ func (h Hopper) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid only returns true for the top face of the hopper. -func (Hopper) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (Hopper) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face == cube.FaceUp } diff --git a/server/block/model/ladder.go b/server/block/model/ladder.go index cd18b8938..57802e064 100644 --- a/server/block/model/ladder.go +++ b/server/block/model/ladder.go @@ -12,11 +12,11 @@ type Ladder struct { } // BBox returns one physics.BBox that depends on the facing direction of the Ladder. -func (l Ladder) BBox(cube.Pos, *world.World) []cube.BBox { +func (l Ladder) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{full.ExtendTowards(l.Facing, -0.8125)} } // FaceSolid always returns false. -func (l Ladder) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (l Ladder) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/lantern.go b/server/block/model/lantern.go index 2e87cd136..18eecd076 100644 --- a/server/block/model/lantern.go +++ b/server/block/model/lantern.go @@ -12,7 +12,7 @@ type Lantern struct { } // BBox returns a physics.BBox attached to either the ceiling or to the ground. -func (l Lantern) BBox(cube.Pos, *world.World) []cube.BBox { +func (l Lantern) BBox(cube.Pos, world.BlockSource) []cube.BBox { if l.Hanging { return []cube.BBox{cube.Box(0.3125, 0.125, 0.3125, 0.6875, 0.625, 0.6875)} } @@ -20,6 +20,6 @@ func (l Lantern) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid always returns false. -func (l Lantern) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (l Lantern) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/leaves.go b/server/block/model/leaves.go index 556bcd598..20a62a6ee 100644 --- a/server/block/model/leaves.go +++ b/server/block/model/leaves.go @@ -10,11 +10,11 @@ import ( type Leaves struct{} // BBox returns a physics.BBox that spans a full block. -func (Leaves) BBox(cube.Pos, *world.World) []cube.BBox { +func (Leaves) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{full} } // FaceSolid always returns false. -func (Leaves) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Leaves) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/lectern.go b/server/block/model/lectern.go index 99c2f3afa..bb153f9e0 100644 --- a/server/block/model/lectern.go +++ b/server/block/model/lectern.go @@ -9,11 +9,11 @@ import ( type Lectern struct{} // BBox ... -func (Lectern) BBox(cube.Pos, *world.World) []cube.BBox { +func (Lectern) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0, 0, 0, 1, 0.9, 1)} } // FaceSolid ... -func (Lectern) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Lectern) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/skull.go b/server/block/model/skull.go index 88df594a0..2407510d4 100644 --- a/server/block/model/skull.go +++ b/server/block/model/skull.go @@ -14,7 +14,7 @@ type Skull struct { } // BBox ... -func (s Skull) BBox(cube.Pos, *world.World) []cube.BBox { +func (s Skull) BBox(cube.Pos, world.BlockSource) []cube.BBox { box := cube.Box(0.25, 0, 0.25, 0.75, 0.5, 0.75) if !s.Hanging { return []cube.BBox{box} @@ -23,6 +23,6 @@ func (s Skull) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid ... -func (Skull) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Skull) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/slab.go b/server/block/model/slab.go index 02d91ab60..6cd8bd169 100644 --- a/server/block/model/slab.go +++ b/server/block/model/slab.go @@ -15,7 +15,7 @@ type Slab struct { // BBox returns either a physics.BBox spanning a full block or a half block in the top/bottom part of the block, // depending on the Double and Top fields. -func (s Slab) BBox(cube.Pos, *world.World) []cube.BBox { +func (s Slab) BBox(cube.Pos, world.BlockSource) []cube.BBox { if s.Double { return []cube.BBox{full} } @@ -27,7 +27,7 @@ func (s Slab) BBox(cube.Pos, *world.World) []cube.BBox { // FaceSolid returns true if the Slab is double, or if the face is cube.FaceUp when the Top field is true, or if the // face is cube.FaceDown when the Top field is false. -func (s Slab) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (s Slab) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { if s.Double { return true } else if s.Top { diff --git a/server/block/model/solid.go b/server/block/model/solid.go index aa10d865a..3e7ef9005 100644 --- a/server/block/model/solid.go +++ b/server/block/model/solid.go @@ -13,11 +13,11 @@ type Solid struct{} var full = cube.Box(0, 0, 0, 1, 1, 1) // BBox returns a physics.BBox spanning a full block. -func (Solid) BBox(cube.Pos, *world.World) []cube.BBox { +func (Solid) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{full} } // FaceSolid always returns true. -func (Solid) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Solid) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return true } diff --git a/server/block/model/stair.go b/server/block/model/stair.go index 1d7e358b4..d5c1f882b 100644 --- a/server/block/model/stair.go +++ b/server/block/model/stair.go @@ -18,12 +18,12 @@ type Stair struct { // BBox returns a slice of physics.BBox depending on if the Stair is upside down and which direction it is facing. // Additionally, these BBoxs depend on the Stair blocks surrounding this one, which can influence the model. -func (s Stair) BBox(pos cube.Pos, w *world.World) []cube.BBox { +func (s Stair) BBox(pos cube.Pos, bs world.BlockSource) []cube.BBox { b := []cube.BBox{cube.Box(0, 0, 0, 1, 0.5, 1)} if s.UpsideDown { b[0] = cube.Box(0, 0.5, 0, 1, 1, 1) } - t := s.cornerType(pos, w) + t := s.cornerType(pos, bs) face, oppositeFace := s.Facing.Face(), s.Facing.Opposite().Face() if t == noCorner || t == cornerRightInner || t == cornerLeftInner { @@ -57,7 +57,7 @@ func (s Stair) BBox(pos cube.Pos, w *world.World) []cube.BBox { } // FaceSolid returns true for all faces of the Stair that are completely filled. -func (s Stair) FaceSolid(pos cube.Pos, face cube.Face, w *world.World) bool { +func (s Stair) FaceSolid(pos cube.Pos, face cube.Face, bs world.BlockSource) bool { if !s.UpsideDown && face == cube.FaceDown { // Non-upside-down stairs have a closed side at the bottom. return true @@ -65,7 +65,7 @@ func (s Stair) FaceSolid(pos cube.Pos, face cube.Face, w *world.World) bool { // Upside-down stairs always have a closed side at the top. return true } - t := s.cornerType(pos, w) + t := s.cornerType(pos, bs) if t == cornerRightOuter || t == cornerLeftOuter { // Small corner blocks, they do not block water flowing out horizontally. return false @@ -89,25 +89,25 @@ const ( // cornerType returns the type of the corner that the stairs form, or 0 if it does not form a corner with any // other stairs. -func (s Stair) cornerType(pos cube.Pos, w *world.World) uint8 { +func (s Stair) cornerType(pos cube.Pos, bs world.BlockSource) uint8 { rotatedFacing := s.Facing.RotateRight() - if closedSide, ok := w.Block(pos.Side(s.Facing.Face())).Model().(Stair); ok && closedSide.UpsideDown == s.UpsideDown { + if closedSide, ok := bs.Block(pos.Side(s.Facing.Face())).Model().(Stair); ok && closedSide.UpsideDown == s.UpsideDown { if closedSide.Facing == rotatedFacing { return cornerLeftOuter } else if closedSide.Facing == rotatedFacing.Opposite() { // This will only form a corner if there is not a stair on the right of this one with the same // direction. - if side, ok := w.Block(pos.Side(s.Facing.RotateRight().Face())).Model().(Stair); !ok || side.Facing != s.Facing || side.UpsideDown != s.UpsideDown { + if side, ok := bs.Block(pos.Side(s.Facing.RotateRight().Face())).Model().(Stair); !ok || side.Facing != s.Facing || side.UpsideDown != s.UpsideDown { return cornerRightOuter } return noCorner } } - if openSide, ok := w.Block(pos.Side(s.Facing.Opposite().Face())).Model().(Stair); ok && openSide.UpsideDown == s.UpsideDown { + if openSide, ok := bs.Block(pos.Side(s.Facing.Opposite().Face())).Model().(Stair); ok && openSide.UpsideDown == s.UpsideDown { if openSide.Facing == rotatedFacing { // This will only form a corner if there is not a stair on the right of this one with the same // direction. - if side, ok := w.Block(pos.Side(s.Facing.RotateRight().Face())).Model().(Stair); !ok || side.Facing != s.Facing || side.UpsideDown != s.UpsideDown { + if side, ok := bs.Block(pos.Side(s.Facing.RotateRight().Face())).Model().(Stair); !ok || side.Facing != s.Facing || side.UpsideDown != s.UpsideDown { return cornerRightInner } } else if openSide.Facing == rotatedFacing.Opposite() { diff --git a/server/block/model/stonecutter.go b/server/block/model/stonecutter.go index 10033e223..24bd38003 100644 --- a/server/block/model/stonecutter.go +++ b/server/block/model/stonecutter.go @@ -9,11 +9,11 @@ import ( type Stonecutter struct{} // BBox ... -func (Stonecutter) BBox(cube.Pos, *world.World) []cube.BBox { +func (Stonecutter) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0, 0, 0, 1, 0.5625, 1)} } // FaceSolid ... -func (Stonecutter) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (Stonecutter) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return false } diff --git a/server/block/model/thin.go b/server/block/model/thin.go index eaea8e065..89251e361 100644 --- a/server/block/model/thin.go +++ b/server/block/model/thin.go @@ -11,7 +11,7 @@ type Thin struct{} // BBox returns a slice of physics.BBox that depends on the blocks surrounding the Thin block. Thin blocks can connect // to any other Thin block, wall or solid faces of other blocks. -func (t Thin) BBox(pos cube.Pos, w *world.World) []cube.BBox { +func (t Thin) BBox(pos cube.Pos, s world.BlockSource) []cube.BBox { const offset = 0.4375 boxes := make([]cube.BBox, 0, 5) @@ -19,11 +19,11 @@ func (t Thin) BBox(pos cube.Pos, w *world.World) []cube.BBox { for _, f := range cube.HorizontalFaces() { pos := pos.Side(f) - block := w.Block(pos) + block := s.Block(pos) _, thin := block.Model().(Thin) _, wall := block.Model().(Wall) - if thin || wall || block.Model().FaceSolid(pos, f.Opposite(), w) { + if thin || wall || block.Model().FaceSolid(pos, f.Opposite(), s) { boxes = append(boxes, mainBox.ExtendTowards(f, offset)) } } @@ -31,6 +31,6 @@ func (t Thin) BBox(pos cube.Pos, w *world.World) []cube.BBox { } // FaceSolid returns true if the face passed is cube.FaceDown. -func (t Thin) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (t Thin) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face == cube.FaceDown } diff --git a/server/block/model/tilled_grass.go b/server/block/model/tilled_grass.go index 92de71828..48d735abd 100644 --- a/server/block/model/tilled_grass.go +++ b/server/block/model/tilled_grass.go @@ -9,11 +9,11 @@ import ( type TilledGrass struct{} // BBox returns a physics.BBox that spans an entire block. -func (TilledGrass) BBox(cube.Pos, *world.World) []cube.BBox { +func (TilledGrass) BBox(cube.Pos, world.BlockSource) []cube.BBox { return []cube.BBox{full.ExtendTowards(cube.FaceDown, 0.0625)} } // FaceSolid always returns true. -func (TilledGrass) FaceSolid(cube.Pos, cube.Face, *world.World) bool { +func (TilledGrass) FaceSolid(cube.Pos, cube.Face, world.BlockSource) bool { return true } diff --git a/server/block/model/trapdoor.go b/server/block/model/trapdoor.go index cbb8d3e14..dac777892 100644 --- a/server/block/model/trapdoor.go +++ b/server/block/model/trapdoor.go @@ -17,7 +17,7 @@ type Trapdoor struct { // BBox returns a physics.BBox that depends on the facing direction of the Trapdoor and whether it is open and in the // top part of the block. -func (t Trapdoor) BBox(cube.Pos, *world.World) []cube.BBox { +func (t Trapdoor) BBox(cube.Pos, world.BlockSource) []cube.BBox { if t.Open { return []cube.BBox{full.ExtendTowards(t.Facing.Face(), -0.8125)} } else if t.Top { @@ -27,7 +27,7 @@ func (t Trapdoor) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid returns true if the face is completely filled with the trapdoor. -func (t Trapdoor) FaceSolid(pos cube.Pos, face cube.Face, w *world.World) bool { +func (t Trapdoor) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { if t.Open { return t.Facing.Face().Opposite() == face } else if t.Top { diff --git a/server/block/model/wall.go b/server/block/model/wall.go index a76652072..884f34c19 100644 --- a/server/block/model/wall.go +++ b/server/block/model/wall.go @@ -20,7 +20,7 @@ type Wall struct { } // BBox ... -func (w Wall) BBox(cube.Pos, *world.World) []cube.BBox { +func (w Wall) BBox(cube.Pos, world.BlockSource) []cube.BBox { postHeight := 0.8125 if w.Post { postHeight = 1 @@ -42,6 +42,6 @@ func (w Wall) BBox(cube.Pos, *world.World) []cube.BBox { } // FaceSolid returns true if the face is in the Y axis. -func (w Wall) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool { +func (w Wall) FaceSolid(_ cube.Pos, face cube.Face, _ world.BlockSource) bool { return face.Axis() == cube.Y } diff --git a/server/world/block_model.go b/server/world/block_model.go index 89c04164e..8c7f17d91 100644 --- a/server/world/block_model.go +++ b/server/world/block_model.go @@ -8,21 +8,21 @@ import ( // whether specific faces are solid wrt. being able to, for example, place torches onto those sides. type BlockModel interface { // BBox returns the bounding boxes that a block with this model can be collided with. - BBox(pos cube.Pos, w *World) []cube.BBox + BBox(pos cube.Pos, s BlockSource) []cube.BBox // FaceSolid checks if a specific face of a block at the position in a world passed is solid. Blocks may // be attached to these faces. - FaceSolid(pos cube.Pos, face cube.Face, w *World) bool + FaceSolid(pos cube.Pos, face cube.Face, s BlockSource) bool } // unknownModel is the model used for unknown blocks. It is the equivalent of a fully solid model. type unknownModel struct{} // BBox ... -func (u unknownModel) BBox(cube.Pos, *World) []cube.BBox { +func (u unknownModel) BBox(cube.Pos, BlockSource) []cube.BBox { return []cube.BBox{cube.Box(0, 0, 0, 1, 1, 1)} } // FaceSolid ... -func (u unknownModel) FaceSolid(cube.Pos, cube.Face, *World) bool { +func (u unknownModel) FaceSolid(cube.Pos, cube.Face, BlockSource) bool { return true } diff --git a/server/world/block_source.go b/server/world/block_source.go new file mode 100644 index 000000000..975364a34 --- /dev/null +++ b/server/world/block_source.go @@ -0,0 +1,9 @@ +package world + +import "github.com/df-mc/dragonfly/server/block/cube" + +// BlockSource represents a source for obtaining blocks. +type BlockSource interface { + // Block returns the block at the given position in the block source. + Block(cube.Pos) Block +}