github.com/df-mc/dragonfly@v0.9.13/server/block/model/thin.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  // Thin is a model for thin, partial blocks such as a glass pane or an iron bar. It changes its bounding box depending
     9  // on solid faces next to it.
    10  type Thin struct{}
    11  
    12  // BBox returns a slice of physics.BBox that depends on the blocks surrounding the Thin block. Thin blocks can connect
    13  // to any other Thin block, wall or solid faces of other blocks.
    14  func (t Thin) BBox(pos cube.Pos, w *world.World) []cube.BBox {
    15  	const offset = 0.4375
    16  
    17  	boxes := make([]cube.BBox, 0, 5)
    18  	mainBox := cube.Box(offset, 0, offset, 1-offset, 1, 1-offset)
    19  
    20  	for _, f := range cube.HorizontalFaces() {
    21  		pos := pos.Side(f)
    22  		block := w.Block(pos)
    23  
    24  		_, thin := block.Model().(Thin)
    25  		_, wall := block.Model().(Wall)
    26  		if thin || wall || block.Model().FaceSolid(pos, f.Opposite(), w) {
    27  			boxes = append(boxes, mainBox.ExtendTowards(f, offset))
    28  		}
    29  	}
    30  	return append(boxes, mainBox)
    31  }
    32  
    33  // FaceSolid returns true if the face passed is cube.FaceDown.
    34  func (t Thin) FaceSolid(_ cube.Pos, face cube.Face, _ *world.World) bool {
    35  	return face == cube.FaceDown
    36  }