entity

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirectionVector

func DirectionVector(e world.Entity) mgl64.Vec3

DirectionVector returns a vector that describes the direction of the entity passed. The length of the Vec3 returned is always 1.

func EyePosition

func EyePosition(e world.Entity) mgl64.Vec3

EyePosition returns the position of the eyes of the entity if the entity implements entity.Eyed, or the actual position if it doesn't.

func Facing

func Facing(e world.Entity) world.Direction

Facing returns the horizontal direction that an entity is facing.

Types

type EffectManager

type EffectManager struct {
	// contains filtered or unexported fields
}

EffectManager manages the effects of an entity. The effect manager will only store effects that last for a specific duration. Instant effects are applied instantly and not stored.

func NewEffectManager

func NewEffectManager() *EffectManager

NewEffectManager creates and returns a new initialised EffectManager.

func (*EffectManager) Add

func (m *EffectManager) Add(e effect.Effect, entity Living) effect.Effect

Add adds an effect to the manager. If the effect is instant, it is applied to the Living entity passed immediately. If not, the effect is added to the EffectManager and is applied to the entity every time the Tick method is called. Effect levels of 0 or below will not do anything. Effect returns the final effect it added to the entity. That might be the effect passed or an effect with a higher level/duration than the one passed.

func (*EffectManager) Effects

func (m *EffectManager) Effects() []effect.Effect

Effects returns a list of all effects currently present in the effect manager. This will never include effects that have expired.

func (*EffectManager) Remove

func (m *EffectManager) Remove(e effect.Effect, entity Living)

Remove removes any Effect present in the EffectManager with the type of the effect passed.

func (*EffectManager) Tick

func (m *EffectManager) Tick(entity Living)

Tick ticks the EffectManager, applying all of its effects to the Living entity passed when applicable and removing expired effects.

type Eyed

type Eyed interface {
	// EyeHeight returns the offset from their base position that the eyes of an entity are found at.
	EyeHeight() float64
}

Eyed represents an entity that has eyes.

type FallingBlock

type FallingBlock struct {
	*MovementComputer
	// contains filtered or unexported fields
}

FallingBlock is the entity form of a block that appears when a gravity-affected block loses its support.

func NewFallingBlock

func NewFallingBlock(block world.Block, pos mgl64.Vec3) *FallingBlock

NewFallingBlock ...

func (*FallingBlock) AABB

func (f *FallingBlock) AABB() physics.AABB

AABB ...

func (*FallingBlock) Block

func (f *FallingBlock) Block() world.Block

Block ...

func (*FallingBlock) Close

func (f *FallingBlock) Close() error

Close ...

func (*FallingBlock) EncodeEntity

func (f *FallingBlock) EncodeEntity() string

EncodeEntity ...

func (*FallingBlock) Name

func (f *FallingBlock) Name() string

Name ...

func (*FallingBlock) Pitch

func (f *FallingBlock) Pitch() float64

Pitch ...

func (*FallingBlock) Position

func (f *FallingBlock) Position() mgl64.Vec3

Position ...

func (*FallingBlock) SetVelocity

func (f *FallingBlock) SetVelocity(v mgl64.Vec3)

SetVelocity ...

func (*FallingBlock) State

func (f *FallingBlock) State() []state.State

State ...

func (*FallingBlock) Tick

func (f *FallingBlock) Tick(_ int64)

Tick ...

func (*FallingBlock) Velocity

func (f *FallingBlock) Velocity() mgl64.Vec3

Velocity ...

func (*FallingBlock) World

func (f *FallingBlock) World() *world.World

World ...

func (*FallingBlock) Yaw

func (f *FallingBlock) Yaw() float64

Yaw ...

type Flammable

type Flammable interface {
	// FireProof is whether the entity is currently fire proof.
	FireProof() bool
	// OnFireDuration returns duration of fire in ticks.
	OnFireDuration() time.Duration
	// SetOnFire sets the entity on fire for the specified duration.
	SetOnFire(duration time.Duration)
	// Extinguish extinguishes the entity.
	Extinguish()
}

Flammable is an interface for entities that can be set on fire.

type Item

type Item struct {
	*MovementComputer
	// contains filtered or unexported fields
}

Item represents an item entity which may be added to the world. Players and several humanoid entities such as zombies are able to pick up these entities so that the items are added to their inventory.

func NewItem

func NewItem(i item.Stack, pos mgl64.Vec3) *Item

NewItem creates a new item entity using the item stack passed. The item entity will be positioned at the position passed. If the stack's count exceeds its max count, the count of the stack will be changed to the maximum.

func (*Item) AABB

func (it *Item) AABB() physics.AABB

AABB ...

func (*Item) Close

func (it *Item) Close() error

Close closes the item, removing it from the world that it is currently in.

func (*Item) EncodeEntity

func (it *Item) EncodeEntity() string

EncodeEntity ...

func (*Item) Item

func (it *Item) Item() item.Stack

Item returns the item stack that the item entity holds.

func (*Item) Name

func (it *Item) Name() string

Name ...

func (*Item) Pitch

func (it *Item) Pitch() float64

Pitch always returns 0.

func (*Item) Position

func (it *Item) Position() mgl64.Vec3

Position returns the current position of the item entity.

func (*Item) SetPickupDelay

func (it *Item) SetPickupDelay(d time.Duration)

SetPickupDelay sets a delay passed until the item can be picked up. If d is negative or d.Seconds()*20 higher than math.MaxInt16, the item will never be able to be picked up.

func (*Item) SetVelocity

func (it *Item) SetVelocity(v mgl64.Vec3)

SetVelocity sets the velocity of the item entity. The values in the Vec3 passed represent the speed on that axis in blocks/tick.

func (*Item) State

func (it *Item) State() []state.State

State ...

func (*Item) Tick

func (it *Item) Tick(current int64)

Tick ticks the entity, performing movement.

func (*Item) Velocity

func (it *Item) Velocity() mgl64.Vec3

Velocity returns the current velocity of the item. The values in the Vec3 returned represent the speed on that axis in blocks/tick.

func (*Item) World

func (it *Item) World() *world.World

World returns the world that the item entity is currently in, or nil if it is not added to a world.

func (*Item) Yaw

func (it *Item) Yaw() float64

Yaw always returns 0.

type Living

type Living interface {
	world.Entity
	// Health returns the health of the entity.
	Health() float64
	// MaxHealth returns the maximum health of the entity.
	MaxHealth() float64
	// SetMaxHealth changes the maximum health of the entity to the value passed.
	SetMaxHealth(v float64)
	// AttackImmune checks if the entity is currently immune to entity attacks. Entities typically turn
	// immune for half a second after being attacked.
	AttackImmune() bool
	// Hurt hurts the entity for a given amount of damage. The source passed represents the cause of the
	// damage, for example damage.SourceEntityAttack if the entity is attacked by another entity.
	// If the final damage exceeds the health that the player currently has, the entity is killed.
	Hurt(damage float64, source damage.Source)
	// Heal heals the entity for a given amount of health. The source passed represents the cause of the
	// healing, for example healing.SourceFood if the entity healed by having a full food bar. If the health
	// added to the original health exceeds the entity's max health, Heal may not add the full amount.
	Heal(health float64, source healing.Source)
	// KnockBack knocks the entity back with a given force and height. A source is passed which indicates the
	// source of the velocity, typically the position of an attacking entity. The source is used to calculate
	// the direction which the entity should be knocked back in.
	KnockBack(src mgl64.Vec3, force, height float64)
	// Speed returns the current speed of the living entity. The default value is different for each entity.
	Speed() float64
	// SetSpeed sets the speed of an entity to a new value.
	SetSpeed(float64)
}

Living represents an entity that is alive and that has health. It is able to take damage and will die upon taking fatal damage.

type MovementComputer

type MovementComputer struct {
	// contains filtered or unexported fields
}

MovementComputer is used to compute movement of an entity. When constructed, the gravity of the entity the movement is computed for must be passed.

func (*MovementComputer) OnGround

func (c *MovementComputer) OnGround() bool

OnGround checks if the entity that this computer calculates is currently on the ground.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL