github.com/df-mc/dragonfly@v0.9.13/server/block/model/trapdoor.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  // Trapdoor is a model used for trapdoors. It has no solid faces and a bounding box that changes depending on
     9  // the direction of the trapdoor.
    10  type Trapdoor struct {
    11  	// Facing is the facing direction of the Trapdoor. In addition to the texture, it influences the direction in which
    12  	// the Trapdoor is opened.
    13  	Facing cube.Direction
    14  	// Open and Top specify if the Trapdoor is opened and if it's in the top or bottom part of a block respectively.
    15  	Open, Top bool
    16  }
    17  
    18  // BBox returns a physics.BBox that depends on the facing direction of the Trapdoor and whether it is open and in the
    19  // top part of the block.
    20  func (t Trapdoor) BBox(cube.Pos, *world.World) []cube.BBox {
    21  	if t.Open {
    22  		return []cube.BBox{full.ExtendTowards(t.Facing.Face(), -0.8125)}
    23  	} else if t.Top {
    24  		return []cube.BBox{cube.Box(0, 0.8125, 0, 1, 1, 1)}
    25  	}
    26  	return []cube.BBox{cube.Box(0, 0, 0, 1, 0.1875, 1)}
    27  }
    28  
    29  // FaceSolid returns true if the face is completely filled with the trapdoor.
    30  func (t Trapdoor) FaceSolid(pos cube.Pos, face cube.Face, w *world.World) bool {
    31  	if t.Open {
    32  		return t.Facing.Face().Opposite() == face
    33  	} else if t.Top {
    34  		return face == cube.FaceUp
    35  	}
    36  	return face == cube.FaceDown
    37  }