up3
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package customblock
|
||||
|
||||
// Material represents a single material used for rendering part of a custom block.
|
||||
type Material struct {
|
||||
// texture is the name of the texture for the material.
|
||||
texture string
|
||||
// renderMethod is the method to use when rendering the material.
|
||||
renderMethod Method
|
||||
// faceDimming is if the material should be dimmed by the direction it's facing.
|
||||
faceDimming bool
|
||||
// ambientOcclusion is if the material should have ambient occlusion applied when lighting.
|
||||
ambientOcclusion bool
|
||||
}
|
||||
|
||||
// NewMaterial returns a new Material with the provided information. It enables face dimming by default and ambient
|
||||
// occlusion based on the render method given.
|
||||
func NewMaterial(texture string, method Method) Material {
|
||||
return Material{
|
||||
texture: texture,
|
||||
renderMethod: method,
|
||||
faceDimming: true,
|
||||
ambientOcclusion: method.AmbientOcclusion(),
|
||||
}
|
||||
}
|
||||
|
||||
// WithFaceDimming returns a copy of the Material with face dimming enabled.
|
||||
func (m Material) WithFaceDimming() Material {
|
||||
m.faceDimming = true
|
||||
return m
|
||||
}
|
||||
|
||||
// WithoutFaceDimming returns a copy of the Material with face dimming disabled.
|
||||
func (m Material) WithoutFaceDimming() Material {
|
||||
m.faceDimming = false
|
||||
return m
|
||||
}
|
||||
|
||||
// WithAmbientOcclusion returns a copy of the Material with ambient occlusion enabled.
|
||||
func (m Material) WithAmbientOcclusion() Material {
|
||||
m.ambientOcclusion = true
|
||||
return m
|
||||
}
|
||||
|
||||
// WithoutAmbientOcclusion returns a copy of the Material with ambient occlusion disabled.
|
||||
func (m Material) WithoutAmbientOcclusion() Material {
|
||||
m.ambientOcclusion = false
|
||||
return m
|
||||
}
|
||||
|
||||
// Encode returns the material encoded as a map that can be sent over the network to the client.
|
||||
func (m Material) Encode() map[string]any {
|
||||
return map[string]any{
|
||||
"texture": m.texture,
|
||||
"render_method": m.renderMethod.String(),
|
||||
"face_dimming": m.faceDimming,
|
||||
"ambient_occlusion": m.ambientOcclusion,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package customblock
|
||||
|
||||
import (
|
||||
"github.com/df-mc/dragonfly/server/block/cube"
|
||||
"github.com/go-gl/mathgl/mgl64"
|
||||
)
|
||||
|
||||
// Properties represents the different properties that can be applied to a block or a permutation.
|
||||
type Properties struct {
|
||||
// CollisionBox represents the bounding box of the block that the player can collide with. This cannot exceed the
|
||||
// position of the current block in the world, otherwise it will be cut off at the edge.
|
||||
CollisionBox cube.BBox
|
||||
// Cube determines whether the block should inherit the default cube geometry. This will only be considered if the
|
||||
// Geometry field is empty.
|
||||
Cube bool
|
||||
// Geometry represents the geometry identifier that should be used for the block. If you want to use the default
|
||||
// cube geometry, leave this field empty and set Cube to true.
|
||||
Geometry string
|
||||
// MapColour represents the hex colour that should be used for the block on a map.
|
||||
MapColour string
|
||||
// Rotation represents the rotation of the block. Rotations are only applied in 90 degree increments, meaning
|
||||
// 1 = 90 degrees, 2 = 180 degrees, 3 = 270 degrees and 4 = 360 degrees.
|
||||
Rotation cube.Pos
|
||||
// Scale is the scale of the block, with 1 being the default scale in all axes. When scaled, the block cannot
|
||||
// exceed a 30x30x30 pixel area otherwise the client will not render the block.
|
||||
Scale mgl64.Vec3
|
||||
// SelectionBox represents the bounding box of the block that the player can interact with. This cannot exceed the
|
||||
// position of the current block in the world, otherwise it will be cut off at the edge.
|
||||
SelectionBox cube.BBox
|
||||
// Textures define the textures that should be used for the block. The key is the target of the texture, such as
|
||||
// "*" for all sides, or one of "up", "down", "north", "south", "east", "west" for a specific side.
|
||||
Textures map[string]Material
|
||||
// Translation is the translation of the block within itself. When translated, the block cannot exceed a 30x30x30
|
||||
// pixel area otherwise the client will not render the block.
|
||||
Translation mgl64.Vec3
|
||||
}
|
||||
|
||||
// Permutation represents a specific permutation for a block that is only applied when the condition is met.
|
||||
type Permutation struct {
|
||||
Properties
|
||||
// Condition is a molang query that is used to determine whether the permutation should be applied.
|
||||
// Only the latest version of molang is supported.
|
||||
Condition string
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package customblock
|
||||
|
||||
// Method is the method to use when rendering a material for a custom block.
|
||||
type Method struct {
|
||||
renderMethod
|
||||
}
|
||||
|
||||
// OpaqueRenderMethod returns the opaque rendering method for a material. It does not render an alpha layer, meaning it
|
||||
// does not support transparent or translucent textures, only textures that are fully opaque.
|
||||
func OpaqueRenderMethod() Method {
|
||||
return Method{0}
|
||||
}
|
||||
|
||||
// AlphaTestRenderMethod returns the alpha_test rendering method for a material. It does not allow for translucent
|
||||
// textures, only textures that are fully opaque or fully transparent, used for blocks such as regular glass. It also
|
||||
// disables ambient occlusion by default.
|
||||
func AlphaTestRenderMethod() Method {
|
||||
return Method{1}
|
||||
}
|
||||
|
||||
// BlendRenderMethod returns the blend rendering method for a material. It allows for transparent and translucent
|
||||
// textures, used for blocks such as stained-glass. It also disables ambient occlusion by default.
|
||||
func BlendRenderMethod() Method {
|
||||
return Method{2}
|
||||
}
|
||||
|
||||
// DoubleSidedRenderMethod returns the double_sided rendering method for a material. It is used to completely disable
|
||||
// backface culling, which would be used for flat faces visible from both sides.
|
||||
func DoubleSidedRenderMethod() Method {
|
||||
return Method{3}
|
||||
}
|
||||
|
||||
type renderMethod uint8
|
||||
|
||||
// Uint8 returns the render method as a uint8.
|
||||
func (m renderMethod) Uint8() uint8 {
|
||||
return uint8(m)
|
||||
}
|
||||
|
||||
// String ...
|
||||
func (m renderMethod) String() string {
|
||||
switch m {
|
||||
case 0:
|
||||
return "opaque"
|
||||
case 1:
|
||||
return "alpha_test"
|
||||
case 2:
|
||||
return "blend"
|
||||
case 3:
|
||||
return "double_sided"
|
||||
}
|
||||
panic("should never happen")
|
||||
}
|
||||
|
||||
// AmbientOcclusion returns if ambient occlusion should be enabled by default for a material using this rendering method.
|
||||
func (m renderMethod) AmbientOcclusion() bool {
|
||||
return m != 1 && m != 2
|
||||
}
|
||||
Reference in New Issue
Block a user