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

     1  package customblock
     2  
     3  // Material represents a single material used for rendering part of a custom block.
     4  type Material struct {
     5  	// texture is the name of the texture for the material.
     6  	texture string
     7  	// renderMethod is the method to use when rendering the material.
     8  	renderMethod Method
     9  	// faceDimming is if the material should be dimmed by the direction it's facing.
    10  	faceDimming bool
    11  	// ambientOcclusion is if the material should have ambient occlusion applied when lighting.
    12  	ambientOcclusion bool
    13  }
    14  
    15  // NewMaterial returns a new Material with the provided information. It enables face dimming by default and ambient
    16  // occlusion based on the render method given.
    17  func NewMaterial(texture string, method Method) Material {
    18  	return Material{
    19  		texture:          texture,
    20  		renderMethod:     method,
    21  		faceDimming:      true,
    22  		ambientOcclusion: method.AmbientOcclusion(),
    23  	}
    24  }
    25  
    26  // WithFaceDimming returns a copy of the Material with face dimming enabled.
    27  func (m Material) WithFaceDimming() Material {
    28  	m.faceDimming = true
    29  	return m
    30  }
    31  
    32  // WithoutFaceDimming returns a copy of the Material with face dimming disabled.
    33  func (m Material) WithoutFaceDimming() Material {
    34  	m.faceDimming = false
    35  	return m
    36  }
    37  
    38  // WithAmbientOcclusion returns a copy of the Material with ambient occlusion enabled.
    39  func (m Material) WithAmbientOcclusion() Material {
    40  	m.ambientOcclusion = true
    41  	return m
    42  }
    43  
    44  // WithoutAmbientOcclusion returns a copy of the Material with ambient occlusion disabled.
    45  func (m Material) WithoutAmbientOcclusion() Material {
    46  	m.ambientOcclusion = false
    47  	return m
    48  }
    49  
    50  // Encode returns the material encoded as a map that can be sent over the network to the client.
    51  func (m Material) Encode() map[string]any {
    52  	return map[string]any{
    53  		"texture":           m.texture,
    54  		"render_method":     m.renderMethod.String(),
    55  		"face_dimming":      m.faceDimming,
    56  		"ambient_occlusion": m.ambientOcclusion,
    57  	}
    58  }