entity

package
v0.0.0-...-2a33acd Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsObject

func IsObject(etype Type) bool

Types

type Attributes

type Attributes struct {
	CanFly  bool
	Hostile bool
	Data    int
	// contains filtered or unexported fields
}

func (Attributes) Merge

func (a Attributes) Merge(other Attributes) Attributes

type Base

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

func (*Base) ApplyVelocity

func (b *Base) ApplyVelocity()

This sets the new position of the entity to be it's current position plus it's velocity. This should be called at the end of Tick(), if you are making custom entity AI.

Once Tick() has exited, if needs_pos_update is true, Collide will be called. If the position is valid, then position packets will be sent.

func (*Base) BlockPos

func (b *Base) BlockPos() block.Pos

func (*Base) Collide

func (b *Base) Collide(info *CollisionInfo)

Used internally once world collision is finished. Should never be called.

func (*Base) EID

func (b *Base) EID() uint32

func (*Base) GetLiving

func (b *Base) GetLiving() (*Living, bool)

func (*Base) Height

func (b *Base) Height() float64

func (*Base) Hit

func (b *Base) Hit(other Entity)

Called when this entity punches other.

func (*Base) Metadata

func (b *Base) Metadata() *metadata.Metadata

func (*Base) NeedsPosUpdate

func (b *Base) NeedsPosUpdate() bool

func (*Base) NeedsVelUpdate

func (b *Base) NeedsVelUpdate() bool

func (*Base) NewX

func (b *Base) NewX() float64

Position that will be set next tick

func (*Base) NewY

func (b *Base) NewY() float64

func (*Base) NewZ

func (b *Base) NewZ() float64

func (*Base) SetNewPosition

func (b *Base) SetNewPosition(x, y, z float64)

This will trigger collision detection next tick, and verify this position at that time. This should be called if you want to move an entity (not a player, call Teleport for players).

func (*Base) SetVelocity

func (b *Base) SetVelocity(x, y, z int16)

This sets the entity's velocity. This does not ensure that any packets will be sent, as ApplyVelocity() still must be called.

func (*Base) Tick

func (b *Base) Tick()

This does basic things, such as apply gravity to the velocity, and set needs_pos_update if the velocity is non zero. This should be called before anything else happens in a custom Tick() function.

func (*Base) Time

func (b *Base) Time() int

Returns the current time for the player. This is a counter that starts at 0 when they log in, and increases once every tick

func (*Base) Vx

func (b *Base) Vx() int16

func (*Base) Vy

func (b *Base) Vy() int16

func (*Base) Vz

func (b *Base) Vz() int16

func (*Base) Width

func (b *Base) Width() float64

Hitbox size

func (*Base) X

func (b *Base) X() float64

Current position. Only updated after each game tick.

func (*Base) Y

func (b *Base) Y() float64

func (*Base) Z

func (b *Base) Z() float64

type CollisionInfo

type CollisionInfo struct {
	// Set to true if the hitbox has collided with any face
	DidCollide bool
	// this is the position that the entity should be at, so that they are not inside a block
	NewX, NewY, NewZ float64
	// hit values for all directions. Used to set velocity to 0 if they were moving in that direciton
	// HitNY is essentially if they are on the ground
	HitPX, HitPY, HitPZ, HitNX, HitNY, HitNZ bool
}

type Entity

type Entity interface {
	// Used internally to see if the entity's position changed last tick
	NeedsPosUpdate() bool
	// Getter for position. Only updated after calling Tick()
	X() float64
	Y() float64
	Z() float64
	// Getter for next position. Calculated on the spot, and is the position + velocity
	NewX() float64
	NewY() float64
	NewZ() float64
	// Block getter. Finds the negative coordinate correctly.
	BlockPos() block.Pos

	// Hitbox size
	Width() float64
	Height() float64

	// Used internally for knockback, and entity velocity in general
	Vx() int16
	Vy() int16
	Vz() int16

	// Entity's id in the world. Is a counter that starts from 1
	EID() uint32

	// Used for knockback. This might also trigger collision next tick, because of the subsequent position change.
	// If you are clearing the velicty, then it will not cause collision to occur.
	SetVelocity(x, y, z int16)
	// Will set the position fields, and trigger collision detection on the next tick.
	// Will also send position packets if the move was valid. Do not call this for players! Call Teleport for players.
	SetNewPosition(x, y, z float64)

	// Called when this entity gets punched by another entity.
	Hit(other Entity)

	// Called whenever the entity hits a block. Can be overriden to make bouncy snowballs, for example.
	Collide(info *CollisionInfo)

	// This will get a pointer to a living struct, if this is a living entity.
	// Used for combat, as all living entities have health/armor
	GetLiving() (*Living, bool)

	// Called internally whenever a game tick occurs. Do not call this function, unless you know what you are doing.
	// The main thing that will happen when you call this is that the position will be updated to whatever the New position is,
	// and velocity will be applied. This will also trigger pathfinding (if there is any).
	// It will basically speed up the entity if you call this. So don't call it
	Tick()

	// This gets a pointer to the metadata for this entity. It can be edited with Write(),
	// and will be marked dirty each time you update it.
	Metadata() *metadata.Metadata

	// Returns the number of ticks since this entity spawned. Used internally for timers, and attack damage
	// calculations. This is safe to call.
	Time() int
}

func New

func New(etype Type,
	eid uint32,
	uuid util.UUID,
	x, y, z float64,
	pitch, yaw, head_pitch byte,
	vx, vy, vz int16,
	attr *Attributes) Entity

type Living

type Living interface {
	Entity
	Damage(amount float32)
	Health() float32
	// This uses the time since last damaged, and checks if you were attacked in one half of a second
	ImmuneToAttacks() bool
	Equipment() map[int]*item.Stack
}

type LivingBase

type LivingBase struct {
	Base
	// contains filtered or unexported fields
}

func NewLivingBase

func NewLivingBase(attr Attributes,
	etype Type, eid uint32, uuid util.UUID,
	x, y, z float64,
	pitch, yaw, head_pitch byte,
	vx, vy, vz int16) *LivingBase

func (*LivingBase) Damage

func (l *LivingBase) Damage(amount float32)

func (*LivingBase) Equipment

func (l *LivingBase) Equipment() map[int]*item.Stack

func (*LivingBase) Health

func (l *LivingBase) Health() float32

func (*LivingBase) ImmuneToAttacks

func (l *LivingBase) ImmuneToAttacks() bool

This returns true if the entity was attacked within half second

func (*LivingBase) SetHealth

func (l *LivingBase) SetHealth(val float32)

func (*LivingBase) Tick

func (l *LivingBase) Tick()

type Object

type Object struct {
	Base
	// contains filtered or unexported fields
}

type StructuredEntityMetadata

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

type Type

type Type int32

Entity type. Should be used by value. This understands what type it inherits from, and how to format entity metadata. It also knows what version it was added, and the versions that it's various fields were added. Whenever you need to reference an entity by type, you should use this type.

const (
	Type_AreaEffectCloud Type = iota
	Type_ArmorStand
	Type_Arrow
	Type_Bat
	Type_Bee
	Type_Blaze
	Type_Boat
	Type_Cat
	Type_CaveSpider
	Type_Chicken
	Type_Cod
	Type_Cow
	Type_Creeper
	Type_Donkey
	Type_Dolphin
	Type_DragonFireball
	Type_Drowned
	Type_ElderGuardian
	Type_EndCrystal
	Type_EnderDragon
	Type_Enderman
	Type_Endermite
	Type_EvokerFangs
	Type_Evoker
	Type_ExpOrb
	Type_EyeOfEnder
	Type_FallingBlock
	Type_FireworkRocket
	Type_Fox
	Type_Ghast
	Type_Giant
	Type_Guardian
	Type_Horse
	Type_Husk
	Type_Illusioner
	Type_Item
	Type_ItemFrame
	Type_Fireball
	Type_LeashKnot
	Type_Llama
	Type_LlamaSpit
	Type_MagmaCube
	Type_Minecart
	Type_ChestMinecart
	Type_CommandMinecart
	Type_FurnaceMinecart
	Type_HopperMinecart
	Type_SpawnerMinecart
	Type_TntMinecart
	Type_Mule
	Type_Mooshroom
	Type_Ocelot
	Type_Painting
	Type_Panda
	Type_Parrot
	Type_Pig
	Type_Pufferfish
	Type_ZombiePigman
	Type_PolarBear
	Type_PrimedTNT
	Type_Rabbit
	Type_Salmon
	Type_Sheep
	Type_Shulker
	Type_ShulkerBullet
	Type_Silverfish
	Type_Skeleton
	Type_SkeletonHorse
	Type_Slime
	Type_SmallFireball
	Type_SnowGolem
	Type_Snowball
	Type_SpectralArrow
	Type_Spider
	Type_Squid
	Type_Stray
	Type_TraderLlama
	Type_TropicalFish
	Type_Turtle
	Type_ThrownEgg
	Type_ThrownEnderPearl
	Type_ThrownExpBottle
	Type_ThrownPotion
	Type_Trident
	Type_Vex
	Type_Villager
	Type_IronGolem
	Type_Vindicator
	Type_Pillager
	Type_WanderingTrader
	Type_Witch
	Type_Wither
	Type_WitherSkeleton
	Type_WitherSkull
	Type_Wolf
	Type_Zombie
	Type_ZombieHorse
	Type_ZombieVillager
	Type_Phantom
	Type_Ravager
	Type_LightningBolt
	Type_Player
	Type_FishingBobber
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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