worldgen water, fixes
This commit is contained in:
49
internal/world/blocks/default.go
Normal file
49
internal/world/blocks/default.go
Normal file
@ -0,0 +1,49 @@
|
||||
package blocks
|
||||
|
||||
import "edgaru089.ml/go/gl01/internal/world"
|
||||
|
||||
const (
|
||||
Nil = iota
|
||||
|
||||
Debug
|
||||
DebugDir
|
||||
DebugNonexist
|
||||
|
||||
Stone
|
||||
Dirt
|
||||
Grass
|
||||
Bedrock
|
||||
Sand
|
||||
LogOak
|
||||
LeavesOak
|
||||
PlanksOak
|
||||
|
||||
Water
|
||||
|
||||
Count
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
world.RegisterBlockBehaviour(1, world.BlockBehaviourStatic(world.BlockAppearance{Name: "debug"}))
|
||||
world.RegisterBlockBehaviour(2, world.BlockBehaviourStatic(world.BlockAppearance{Name: "debug_dir", RenderType: world.SixTexture}))
|
||||
world.RegisterBlockBehaviour(3, world.BlockBehaviourStatic(world.BlockAppearance{Name: "debug_nonexist"}))
|
||||
|
||||
world.RegisterBlockBehaviour(4, world.BlockBehaviourStatic(world.BlockAppearance{Name: "stone"}))
|
||||
world.RegisterBlockBehaviour(5, world.BlockBehaviourStatic(world.BlockAppearance{Name: "dirt"}))
|
||||
world.RegisterBlockBehaviour(6, world.BlockBehaviourStatic(world.BlockAppearance{Name: "grass", RenderType: world.ThreeTexture}))
|
||||
world.RegisterBlockBehaviour(7, world.BlockBehaviourStatic(world.BlockAppearance{Name: "bedrock"}))
|
||||
world.RegisterBlockBehaviour(8, world.BlockBehaviourStatic(world.BlockAppearance{Name: "sand"}))
|
||||
world.RegisterBlockBehaviour(9, world.BlockBehaviourStatic(world.BlockAppearance{Name: "log_oak", RenderType: world.ThreeTexture}))
|
||||
world.RegisterBlockBehaviour(10, world.BlockBehaviourStatic(world.BlockAppearance{Name: "leaves_oak"}))
|
||||
|
||||
world.RegisterBlockBehaviour(11, world.BlockBehaviourStatic(world.BlockAppearance{Name: "planks_oak"}))
|
||||
|
||||
world.RegisterBlockBehaviour(12, WaterBehaviour{})
|
||||
|
||||
if Count != 13 {
|
||||
panic("world.DefaultBlocks: block count not correct (check for block numbering in default_blocks.go)")
|
||||
}
|
||||
|
||||
world.DoneRegisteringBlockBehaviour()
|
||||
}
|
78
internal/world/blocks/helper_appendface.go
Normal file
78
internal/world/blocks/helper_appendface.go
Normal file
@ -0,0 +1,78 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"edgaru089.ml/go/gl01/internal/asset"
|
||||
"edgaru089.ml/go/gl01/internal/util/itype"
|
||||
"edgaru089.ml/go/gl01/internal/world"
|
||||
)
|
||||
|
||||
// texname is the full filename of the texture file (with .png)
|
||||
// faceOffset is added to each vertex
|
||||
func appendFace(face itype.Direction, pos itype.Vec3i, texname string, faceOffset itype.Vec3f, arr []world.Vertex) []world.Vertex {
|
||||
|
||||
switch face {
|
||||
case itype.XPlus: // X+
|
||||
arr = append(arr,
|
||||
// Vertex Position Normal Vector(normalized) Texture Coord Light
|
||||
world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{1, 0, 0}, itype.Vec2f{0, 1}, 16},
|
||||
)
|
||||
case itype.XMinus: // X-
|
||||
arr = append(arr,
|
||||
world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{-1, 0, 0}, itype.Vec2f{1, 0}, 16},
|
||||
)
|
||||
case itype.YPlus: // Y+
|
||||
arr = append(arr,
|
||||
world.Vertex{pos.Addv(0, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 1, 0}, itype.Vec2f{1, 0}, 16},
|
||||
)
|
||||
case itype.YMinus: // Y-
|
||||
arr = append(arr,
|
||||
world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, -1, 0}, itype.Vec2f{1, 1}, 16},
|
||||
)
|
||||
case itype.ZPlus: // Z+
|
||||
arr = append(arr,
|
||||
world.Vertex{pos.Addv(0, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{0, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 1).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, 1}, itype.Vec2f{1, 1}, 16},
|
||||
)
|
||||
case itype.ZMinus: // Z-
|
||||
arr = append(arr,
|
||||
world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(0, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{1, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(0, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{1, 1}, 16},
|
||||
world.Vertex{pos.Addv(1, 1, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{0, 0}, 16},
|
||||
world.Vertex{pos.Addv(1, 0, 0).ToFloat32().Add(faceOffset), itype.Vec3f{0, 0, -1}, itype.Vec2f{0, 1}, 16},
|
||||
)
|
||||
}
|
||||
|
||||
texrect := asset.WorldTextureAtlas.RectNormalized(texname)
|
||||
for i := len(arr) - 6; i < len(arr); i++ {
|
||||
arr[i].Texture[0] = texrect.Left + arr[i].Texture[0]*texrect.Width
|
||||
arr[i].Texture[1] = texrect.Top + arr[i].Texture[1]*texrect.Height
|
||||
}
|
||||
|
||||
return arr
|
||||
}
|
37
internal/world/blocks/water.go
Normal file
37
internal/world/blocks/water.go
Normal file
@ -0,0 +1,37 @@
|
||||
package blocks
|
||||
|
||||
import (
|
||||
"edgaru089.ml/go/gl01/internal/util/itype"
|
||||
"edgaru089.ml/go/gl01/internal/world"
|
||||
)
|
||||
|
||||
type WaterBehaviour struct{}
|
||||
|
||||
func (WaterBehaviour) Static() bool { return false }
|
||||
func (WaterBehaviour) RequireDataset() bool { return false }
|
||||
func (WaterBehaviour) RequireBlockUpdate() bool { return false }
|
||||
func (b WaterBehaviour) Appearance(position itype.Vec3i, aux int, data itype.Dataset, w *world.World) world.BlockAppearance {
|
||||
return world.BlockAppearance{
|
||||
Name: "water",
|
||||
Transparent: true,
|
||||
NotSolid: true,
|
||||
|
||||
RenderType: world.CustomRendering,
|
||||
CustomRenderAppend: func(
|
||||
position itype.Vec3i,
|
||||
aux int,
|
||||
data itype.Dataset,
|
||||
w *world.World,
|
||||
vertexArray []world.Vertex) []world.Vertex {
|
||||
|
||||
if block := w.Block(position.Addv(0, 1, 0)); block.Id != Water {
|
||||
return appendFace(itype.YPlus, position, "water.png", itype.Vec3f{0, -0.125, 0}, vertexArray)
|
||||
}
|
||||
|
||||
return vertexArray
|
||||
},
|
||||
}
|
||||
}
|
||||
func (WaterBehaviour) BlockUpdate(position itype.Vec3i, aux int, data itype.Dataset, w *world.World) bool {
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user