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

     1  package customblock
     2  
     3  // Method is the method to use when rendering a material for a custom block.
     4  type Method struct {
     5  	renderMethod
     6  }
     7  
     8  // OpaqueRenderMethod returns the opaque rendering method for a material. It does not render an alpha layer, meaning it
     9  // does not support transparent or translucent textures, only textures that are fully opaque.
    10  func OpaqueRenderMethod() Method {
    11  	return Method{0}
    12  }
    13  
    14  // AlphaTestRenderMethod returns the alpha_test rendering method for a material. It does not allow for translucent
    15  // textures, only textures that are fully opaque or fully transparent, used for blocks such as regular glass. It also
    16  // disables ambient occlusion by default.
    17  func AlphaTestRenderMethod() Method {
    18  	return Method{1}
    19  }
    20  
    21  // BlendRenderMethod returns the blend rendering method for a material. It allows for transparent and translucent
    22  // textures, used for blocks such as stained-glass. It also disables ambient occlusion by default.
    23  func BlendRenderMethod() Method {
    24  	return Method{2}
    25  }
    26  
    27  // DoubleSidedRenderMethod returns the double_sided rendering method for a material. It is used to completely disable
    28  // backface culling, which would be used for flat faces visible from both sides.
    29  func DoubleSidedRenderMethod() Method {
    30  	return Method{3}
    31  }
    32  
    33  type renderMethod uint8
    34  
    35  // Uint8 returns the render method as a uint8.
    36  func (m renderMethod) Uint8() uint8 {
    37  	return uint8(m)
    38  }
    39  
    40  // String ...
    41  func (m renderMethod) String() string {
    42  	switch m {
    43  	case 0:
    44  		return "opaque"
    45  	case 1:
    46  		return "alpha_test"
    47  	case 2:
    48  		return "blend"
    49  	case 3:
    50  		return "double_sided"
    51  	}
    52  	panic("should never happen")
    53  }
    54  
    55  // AmbientOcclusion returns if ambient occlusion should be enabled by default for a material using this rendering method.
    56  func (m renderMethod) AmbientOcclusion() bool {
    57  	return m != 1 && m != 2
    58  }