github.com/df-mc/dragonfly@v0.9.13/server/block/model/slab.go (about)

     1  package model
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/world"
     6  )
     7  
     8  // Slab is the model of a slab-like block, which is either a half block or a full block, depending on if the
     9  // slab is double.
    10  type Slab struct {
    11  	// Double and Top specify if the Slab is a double slab and if it's in the top slot respectively. If Double is true,
    12  	// the BBox returned is always a full block.
    13  	Double, Top bool
    14  }
    15  
    16  // BBox returns either a physics.BBox spanning a full block or a half block in the top/bottom part of the block,
    17  // depending on the Double and Top fields.
    18  func (s Slab) BBox(cube.Pos, *world.World) []cube.BBox {
    19  	if s.Double {
    20  		return []cube.BBox{full}
    21  	}
    22  	if s.Top {
    23  		return []cube.BBox{cube.Box(0, 0.5, 0, 1, 1, 1)}
    24  	}
    25  	return []cube.BBox{cube.Box(0, 0, 0, 1, 0.5, 1)}
    26  }
    27  
    28  // FaceSolid returns true if the Slab is double, or if the face is cube.FaceUp when the Top field is true, or if the
    29  // face is cube.FaceDown when the Top field is false.
    30  func (s Slab) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool {
    31  	if s.Double {
    32  		return true
    33  	} else if s.Top {
    34  		return face == cube.FaceUp
    35  	}
    36  	return face == cube.FaceDown
    37  }