entity: physics rewrite

This commit is contained in:
2022-02-01 23:48:39 +08:00
parent 25872b257d
commit 37ee76e9fc
9 changed files with 201 additions and 256 deletions

View File

@ -20,10 +20,10 @@ const (
type BlockAppearance struct {
Name string // A short name, like "stone" or "dirt", used for texture lookups
Transparent bool // Is block transparent?
NotSolid bool // Is block not solid, i.e., has no solid hitbox? (this makes the zero value reasonable)
NotSolid bool // Is block not solid, i.e., has no hitbox at all? (this makes the zero value reasonable)
Light int // The light level it emits, 0 is none
Hitbox itype.Boxd // Hitbox, in block-local coordinates; empty slice means a default hitbox of 1x1x1
Hitbox []itype.Boxd // Hitbox, in block-local coordinates; empty slice means a default hitbox of 1x1x1
RenderType BlockRenderType // Rendering type, defaults to OneTexture (zero value)
@ -124,11 +124,11 @@ 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, world *World) BlockAppearance {
if app, ok := appearance[id]; ok { // Cache
if app.Hitbox == (itype.Boxd{}) {
app.Hitbox = itype.Boxd{
if len(app.Hitbox) == 0 {
app.Hitbox = []itype.Boxd{{
OffX: 0, OffY: 0, OffZ: 0,
SizeX: 1, SizeY: 1, SizeZ: 1,
}
}}
}
return app
}
@ -140,11 +140,11 @@ func GetBlockAppearance(position itype.Vec3i, id, aux int, data itype.Dataset, w
}
app := b.Appearance(position, aux, data, world)
if app.Hitbox == (itype.Boxd{}) {
app.Hitbox = itype.Boxd{
if len(app.Hitbox) == 0 {
app.Hitbox = []itype.Boxd{{
OffX: 0, OffY: 0, OffZ: 0,
SizeX: 1, SizeY: 1, SizeZ: 1,
}
}}
}
return app
}
@ -165,7 +165,14 @@ type Block struct {
// 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, b.World)
app := b.Behaviour.Appearance(position, b.Aux, b.Dataset, b.World)
if !app.NotSolid && len(app.Hitbox) == 0 {
app.Hitbox = []itype.Boxd{{
OffX: 0, OffY: 0, OffZ: 0,
SizeX: 1, SizeY: 1, SizeZ: 1,
}}
}
return app
}
// BlockUpdate is a shortcut for Behaviour.BlockUpdate().