gl01/internal/world/blocks/slab.go

101 lines
2.5 KiB
Go
Raw Permalink Normal View History

2022-10-12 08:24:00 +08:00
package blocks
import (
"edgaru089.ink/go/gl01/internal/util/itype"
"edgaru089.ink/go/gl01/internal/world"
2022-10-12 08:24:00 +08:00
)
type SlabBehaviour struct{}
func (SlabBehaviour) Static() bool { return true }
func (SlabBehaviour) RequireDataset() bool { return false }
func (SlabBehaviour) RequireBlockUpdate() bool { return false }
func (SlabBehaviour) Appearance(position itype.Vec3i, aux int, data itype.Dataset, w *world.World) world.BlockAppearance {
var hitbox itype.Boxd
if aux > 0 { // Bottom slab
hitbox = itype.Boxd{0, 0, 0, 1, 0.5, 1}
} else { // Top slab
hitbox = itype.Boxd{0, 0.5, 0, 1, 0.5, 1}
}
return world.BlockAppearance{
Name: "",
Transparent: true,
NotSolid: false,
Hitbox: []itype.Boxd{hitbox},
Lookbox: []itype.Boxd{hitbox},
RenderType: world.CustomRendering,
CustomRenderAppend: func(
position itype.Vec3i,
aux int,
data itype.Dataset,
w *world.World,
vertexArray []world.Vertex, vertsWater []world.Vertex) (verts, waters []world.Vertex) {
var offset itype.Vec3f
if aux < 0 {
offset = itype.Vec3f{0, 0.5, 0}
aux = -aux
}
var name string
switch aux {
case Stone:
name = "stone"
case Sand:
name = "sand"
case PlanksOak:
name = "planks_oak"
}
vertexArray = appendFace(itype.YMinus, position, name+".png", itype.Vec3f{0, 0, 0}.Add(offset), vertexArray)
vertexArray = appendFace(itype.YPlus, position, name+".png", itype.Vec3f{0, -0.5, 0}.Add(offset), vertexArray)
vertexArray = appendFaceSized(
itype.XPlus,
position,
name+".png",
itype.Vec3f{1, 0.5, 1},
itype.Vec3f{0, 0, 0}.Add(offset),
itype.Rectf{0, 0, 1, 0.5},
vertexArray,
)
vertexArray = appendFaceSized(
itype.XMinus,
position,
name+".png",
itype.Vec3f{1, 0.5, 1},
itype.Vec3f{0, 0, 0}.Add(offset),
itype.Rectf{0, 0, 1, 0.5},
vertexArray,
)
vertexArray = appendFaceSized(
itype.ZPlus,
position,
name+".png",
itype.Vec3f{1, 0.5, 1},
itype.Vec3f{0, 0, 0}.Add(offset),
itype.Rectf{0, 0, 1, 0.5},
vertexArray,
)
vertexArray = appendFaceSized(
itype.ZMinus,
position,
name+".png",
itype.Vec3f{1, 0.5, 1},
itype.Vec3f{0, 0, 0}.Add(offset),
itype.Rectf{0, 0, 1, 0.5},
vertexArray,
)
return vertexArray, vertsWater
},
}
}
func (SlabBehaviour) BlockUpdate(position itype.Vec3i, aux int, data itype.Dataset, w *world.World) bool {
return false
}
func (SlabBehaviour) Break(position itype.Vec3i, aux int, data itype.Dataset, w *world.World) {}