entity

package
v0.0.0-...-d1826b6 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: AGPL-3.0, 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) cube.Direction

Facing returns the horizontal direction that an entity is facing.

Types

type Collector

type Collector interface {
	world.Entity
	// Collect collects the stack passed. It is called if the Collector is standing near an item entity that
	// may be picked up.
	// The count of items collected from the stack n is returned.
	Collect(stack item.Stack) (n int)
}

Collector represents an entity in the world that is able to collect an item, typically an entity such as a player or a zombie.

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. Add panics if the effect has a negative duration or level.

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.Type, 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 {
	// 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 (t *FallingBlock) Close() error

Close closes the transform and removes the associated entity from the world.

func (*FallingBlock) DecodeNBT

func (f *FallingBlock) DecodeNBT(data map[string]interface{}) interface{}

DecodeNBT decodes the relevant data from the entity NBT passed and returns a new FallingBlock entity.

func (*FallingBlock) EncodeEntity

func (f *FallingBlock) EncodeEntity() string

EncodeEntity ...

func (*FallingBlock) EncodeNBT

func (f *FallingBlock) EncodeNBT() map[string]interface{}

EncodeNBT encodes the FallingBlock entity to a map that can be encoded for NBT.

func (*FallingBlock) Name

func (f *FallingBlock) Name() string

Name ...

func (*FallingBlock) Position

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

Position returns the current position of the entity.

func (*FallingBlock) Rotation

func (t *FallingBlock) Rotation() (float64, float64)

Rotation always returns 0.

func (*FallingBlock) SetVelocity

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

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

func (*FallingBlock) Tick

func (f *FallingBlock) Tick(_ int64)

Tick ...

func (*FallingBlock) Velocity

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

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

func (*FallingBlock) World

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

World returns the world of the entity.

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 HealthManager

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

HealthManager handles the health of an entity.

func NewHealthManager

func NewHealthManager() *HealthManager

NewHealthManager returns a new health manager with a default of 20 health and max health.

func (*HealthManager) AddHealth

func (m *HealthManager) AddHealth(health float64)

AddHealth adds a given amount of health points to the player. If the health added to the current health exceeds the max, health will be set to the max. If the health is instead negative and results in a health lower than 0, the final health will be 0.

func (*HealthManager) Health

func (m *HealthManager) Health() float64

Health returns the current health of an entity.

func (*HealthManager) MaxHealth

func (m *HealthManager) MaxHealth() float64

MaxHealth returns the maximum health of the entity.

func (*HealthManager) SetMaxHealth

func (m *HealthManager) SetMaxHealth(max float64)

SetMaxHealth changes the max health of an entity to the maximum passed. If the maximum is set to 0 or lower, SetMaxHealth will default to a value of 1.

type Item

type Item struct {
	// 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 (t *Item) Close() error

Close closes the transform and removes the associated entity from the world.

func (*Item) DecodeNBT

func (it *Item) DecodeNBT(data map[string]interface{}) interface{}

DecodeNBT decodes the properties in a map to an Item and returns a new Item entity.

func (*Item) EncodeEntity

func (it *Item) EncodeEntity() string

EncodeEntity ...

func (*Item) EncodeNBT

func (it *Item) EncodeNBT() map[string]interface{}

EncodeNBT encodes the Item entity's properties as a map and returns it.

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) Position

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

Position returns the current position of the entity.

func (*Item) Rotation

func (t *Item) Rotation() (float64, float64)

Rotation always returns 0.

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 (t *Item) SetVelocity(v mgl64.Vec3)

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

func (*Item) Tick

func (it *Item) Tick(current int64)

Tick ticks the entity, performing movement.

func (*Item) Velocity

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

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

func (*Item) World

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

World returns the world of the entity.

type Lightning

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

Lightning is a lethal element to thunderstorms. Lightning momentarily increases the skylight's brightness to slightly greater than full daylight.

func NewLightning

func NewLightning(pos mgl64.Vec3) *Lightning

NewLightning creates a lightning entity. The lightning entity will be positioned at the position passed.

func (Lightning) AABB

func (Lightning) AABB() physics.AABB

AABB ...

func (*Lightning) Close

func (li *Lightning) Close() error

Close closes the lighting.

func (*Lightning) EncodeEntity

func (li *Lightning) EncodeEntity() string

EncodeEntity ...

func (*Lightning) Name

func (li *Lightning) Name() string

Name ...

func (Lightning) OnGround

func (Lightning) OnGround() bool

OnGround ...

func (*Lightning) Position

func (li *Lightning) Position() mgl64.Vec3

Position returns the current position of the lightning entity.

func (*Lightning) Rotation

func (li *Lightning) Rotation() (yaw, pitch float64)

Rotation ...

func (*Lightning) Tick

func (li *Lightning) Tick(_ int64)

Tick ...

func (*Lightning) World

func (li *Lightning) World() *world.World

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

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 {
	Gravity           float64
	DragBeforeGravity bool
	Drag              float64
	// 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.

func (*MovementComputer) TickMovement

func (c *MovementComputer) TickMovement(e world.Entity, pos, vel mgl64.Vec3, yaw, pitch float64) (mgl64.Vec3, mgl64.Vec3)

TickMovement performs a movement tick on an entity. Velocity is applied and changed according to the values of its Drag and Gravity. The new position of the entity after movement is returned.

type Solidifiable

type Solidifiable interface {
	// Solidifies returns whether the falling block can solidify at the position it is currently in. If so,
	// the block will immediately stop falling.
	Solidifies(pos cube.Pos, w *world.World) bool
}

Solidifiable represents a block that can solidify by specific adjacent blocks. An example is concrete powder, which can turn into concrete by touching water.

type Text

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

Text is an entity that only displays floating text. The entity is otherwise invisible and cannot be moved.

func NewText

func NewText(text string, pos mgl64.Vec3) *Text

NewText creates and returns a new Text entity with the text and position provided.

func (*Text) AABB

func (t *Text) AABB() physics.AABB

AABB returns an empty physics.AABB so that players cannot interact with the entity.

func (*Text) Close

func (t *Text) Close() error

Close closes the transform and removes the associated entity from the world.

func (*Text) DecodeNBT

func (t *Text) DecodeNBT(data map[string]interface{}) interface{}

DecodeNBT decodes the data passed to create and return a new Text entity.

func (*Text) EncodeEntity

func (t *Text) EncodeEntity() string

EncodeEntity returns the ID for falling blocks.

func (*Text) EncodeNBT

func (t *Text) EncodeNBT() map[string]interface{}

EncodeNBT encodes the Text entity to a map representation that can be encoded to NBT.

func (*Text) Immobile

func (t *Text) Immobile() bool

Immobile always returns true.

func (*Text) Name

func (t *Text) Name() string

Name returns the name of the text entity, including the text written on it.

func (*Text) NameTag

func (t *Text) NameTag() string

NameTag returns the text passed to NewText.

func (*Text) Position

func (t *Text) Position() mgl64.Vec3

Position returns the current position of the entity.

func (*Text) Rotation

func (t *Text) Rotation() (float64, float64)

Rotation always returns 0.

func (*Text) SetVelocity

func (t *Text) SetVelocity(v mgl64.Vec3)

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

func (*Text) Velocity

func (t *Text) Velocity() mgl64.Vec3

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

func (*Text) World

func (t *Text) World() *world.World

World returns the world of the entity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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