Java Reference
In-Depth Information
Modify Entities
Entities, as you might expect, are quite different from blocks. For one thing,
there are many more kinds of entities, and they have different kinds of abilities
(and functions for us). With blocks, all you have to do is change the block
type and perhaps add some additional information (like on a sign), but entities
are more complicated.
To start off, all entities have the capabilities described in
net.canarymod.api.enti-
ty.Entity
. Each
Entity
object includes the following useful functions:
getLocation()
Return the
Location
of the entity
Set time to keep an entity on fire
setFireTicks(int ticks)
setRider(Entity rider)
Set the entity's rider
spawn()
Spawn this kind of
Entity
into the world
teleport(Location location)
Teleport the entity to a new location
Then, depending further on the type of the entity, you might have other cool
functions to play with. Living entities (
net.canarymod.api.entity.living.EntityLiving
), for
example, have the following extra functions that other nonliving entities don't
have:
getItemInHand()
Return the item this entity is holding.
setAttackTarget(LivingBaseliving-
base)
Set this entity's attack target.
getHealth()
Return a
double
of this entity's health. It can
be zero (dead) up to the amount returned by
getMaxHealth()
.
Set the health. Zero is dead, without causing
damage.
setHealth(double health)
kill()
Kill this entity, causing damage (and loot
drops, etc.).
You may have noticed that not all these functions are declared in
EntityLiving
itself. This is where Java gets a little messy. The familiar entity objects
incorporate a lot of different parent recipes. For instance, a
Cow
is an
Ageable
,
an
EntityAnimal
, an
EntityLiving
object, and, of course, an
Entity
.
That means it uses functions from all these different parents. For example,
because
Cow
inherits from
Ageable
, you get functions where you can alter a
Cow
property to change its growing age.