world/entity.go

33 lines
543 B
Go
Raw Permalink Normal View History

2021-05-24 09:51:12 +00:00
package world
import "sync"
// Entity represents an entity within the world.
type Entity struct {
t int // Type
x, y, z int
sync.RWMutex
}
// NewEntity returns a new Entity.
func NewEntity(t int) *Entity {
return &Entity{t: t}
}
// Is returns whether the Entity matches the specified type.
func (e *Entity) Is(t int) bool {
e.RLock()
defer e.RUnlock()
return e.t == t
}
// Coordinates returns the position of the entity.
func (e *Entity) Coordinates() (x, y, z int) {
e.RLock()
defer e.RUnlock()
return e.x, e.y, e.z
}