worldgen water, fixes
This commit is contained in:
@@ -34,6 +34,7 @@ type BlockAppearance struct {
|
||||
position itype.Vec3i,
|
||||
aux int,
|
||||
data itype.Dataset,
|
||||
world *World,
|
||||
vertexArray []Vertex,
|
||||
) []Vertex
|
||||
}
|
||||
@@ -59,7 +60,7 @@ type BlockBehaviour interface {
|
||||
// with Minor ID aux, and Dataset data.
|
||||
//
|
||||
// If RequireDataset if false, data is nil.
|
||||
Appearance(position itype.Vec3i, aux int, data itype.Dataset) BlockAppearance
|
||||
Appearance(position itype.Vec3i, aux int, data itype.Dataset, world *World) BlockAppearance
|
||||
|
||||
// BlockUpdate is called when RequireBlockUpdate is true and the block at
|
||||
// global position Position, with Minor ID aux, and Dataset data has a neighbor
|
||||
@@ -68,7 +69,7 @@ type BlockBehaviour interface {
|
||||
// If RequireDataset if false, data is nil.
|
||||
//
|
||||
// Return true if this block also changed state, false otherwise.
|
||||
BlockUpdate(position itype.Vec3i, aux int, data itype.Dataset) bool
|
||||
BlockUpdate(position itype.Vec3i, aux int, data itype.Dataset, world *World) bool
|
||||
}
|
||||
|
||||
type blockBehaviourStatic struct {
|
||||
@@ -78,10 +79,10 @@ type blockBehaviourStatic struct {
|
||||
func (blockBehaviourStatic) Static() bool { return true }
|
||||
func (blockBehaviourStatic) RequireDataset() bool { return false }
|
||||
func (blockBehaviourStatic) RequireBlockUpdate() bool { return false }
|
||||
func (b blockBehaviourStatic) Appearance(position itype.Vec3i, aux int, data itype.Dataset) BlockAppearance {
|
||||
func (b blockBehaviourStatic) Appearance(position itype.Vec3i, aux int, data itype.Dataset, world *World) BlockAppearance {
|
||||
return b.app
|
||||
}
|
||||
func (blockBehaviourStatic) BlockUpdate(position itype.Vec3i, aux int, data itype.Dataset) bool {
|
||||
func (blockBehaviourStatic) BlockUpdate(position itype.Vec3i, aux int, data itype.Dataset, world *World) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ func RegisterBlockBehaviour(id int, b BlockBehaviour) bool {
|
||||
func DoneRegisteringBlockBehaviour() {
|
||||
for id, b := range behaviour {
|
||||
if b.Static() {
|
||||
appearance[id] = b.Appearance(itype.Vec3i{}, 0, nil)
|
||||
appearance[id] = b.Appearance(itype.Vec3i{}, 0, nil, nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +121,7 @@ func DoneRegisteringBlockBehaviour() {
|
||||
}
|
||||
|
||||
// GetBlockAppearance gets the block appearance of the given block in the fastest way possible.
|
||||
func GetBlockAppearance(position itype.Vec3i, id, aux int, data itype.Dataset) BlockAppearance {
|
||||
func GetBlockAppearance(position itype.Vec3i, id, aux int, data itype.Dataset, world *World) BlockAppearance {
|
||||
if app, ok := appearance[id]; ok { // Cache
|
||||
if app.Hitbox == (itype.Boxd{}) {
|
||||
app.Hitbox = itype.Boxd{
|
||||
@@ -137,7 +138,7 @@ func GetBlockAppearance(position itype.Vec3i, id, aux int, data itype.Dataset) B
|
||||
panic(fmt.Sprint("invalid block type ", id))
|
||||
}
|
||||
|
||||
app := b.Appearance(position, aux, data)
|
||||
app := b.Appearance(position, aux, data, world)
|
||||
if app.Hitbox == (itype.Boxd{}) {
|
||||
app.Hitbox = itype.Boxd{
|
||||
OffX: 0, OffY: 0, OffZ: 0,
|
||||
@@ -157,12 +158,13 @@ type Block struct {
|
||||
Id, Aux int
|
||||
Dataset itype.Dataset
|
||||
Behaviour BlockBehaviour
|
||||
World *World
|
||||
}
|
||||
|
||||
// Appearance is a shortcut for Behaviour.Appearance().
|
||||
// It returns the Appearance of the block with the given parameters.
|
||||
func (b *Block) Appearance(position itype.Vec3i) BlockAppearance {
|
||||
return b.Behaviour.Appearance(position, b.Aux, b.Dataset)
|
||||
func (b Block) Appearance(position itype.Vec3i) BlockAppearance {
|
||||
return b.Behaviour.Appearance(position, b.Aux, b.Dataset, b.World)
|
||||
}
|
||||
|
||||
// BlockUpdate is a shortcut for Behaviour.BlockUpdate().
|
||||
@@ -173,6 +175,6 @@ func (b *Block) Appearance(position itype.Vec3i) BlockAppearance {
|
||||
// If RequireDataset if false, data is nil.
|
||||
//
|
||||
// Return true if this block also changed state, false otherwise.
|
||||
func (b *Block) BlockUpdate(position itype.Vec3i) bool {
|
||||
return b.Behaviour.BlockUpdate(position, b.Aux, b.Dataset)
|
||||
func (b Block) BlockUpdate(position itype.Vec3i) bool {
|
||||
return b.Behaviour.BlockUpdate(position, b.Aux, b.Dataset, b.World)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user