This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorial:entity [2020/06/11 20:18] draylar created |
tutorial:entity [2021/01/30 00:38] (current) oroarmor [Spawning your Entity] |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== Creating an Entity ===== | ===== Creating an Entity ===== | ||
+ | |||
+ | //The source code for this project can be found [[https://github.com/Draylar/entity-testing|here]] on the entity branch.// | ||
Entities are a movable object in a world with logic attached to them. A few examples include: | Entities are a movable object in a world with logic attached to them. A few examples include: | ||
Line 17: | Line 19: | ||
The two generic entity classes that come after ''LivingEntity'' are: | The two generic entity classes that come after ''LivingEntity'' are: | ||
* ''MobEntity'' | * ''MobEntity'' | ||
- | * ''MobEntityWithAi'' | + | * ''PathAwareEntity'' |
- | ''MobEntity'' has AI logic and movement controls. ''MobEntityWithAi'' provides extra capabilities | + | ''MobEntity'' has AI logic and movement controls. ''PathAwareEntity'' provides extra capabilities |
for pathfinding favor, and various AI tasks require this to operate. | for pathfinding favor, and various AI tasks require this to operate. | ||
- | In this tutorial, we will look at creating a cube entity that extends ''MobEntityWithAi''. | + | In this tutorial, we will look at creating a cube entity that extends ''PathAwareEntity''. |
This entity will have a model & texture. Movement and mechanics will be covered in a future tutorial. | This entity will have a model & texture. Movement and mechanics will be covered in a future tutorial. | ||
===== Creating & Registering an Entity ===== | ===== Creating & Registering an Entity ===== | ||
- | Create a class that extends ''MobEntityWithAi''. This class serves as the brains and main hub for our custom entity. | + | Create a class that extends ''PathAwareEntity''. This class serves as the brains and main hub for our custom entity. |
<code java [enable_line_numbers="true"]> | <code java [enable_line_numbers="true"]> | ||
/* | /* | ||
- | * Our Cube Entity extends MobEntityWithAi, which extends MobEntity, which extends LivingEntity. | + | * Our Cube Entity extends PathAwareEntity, which extends MobEntity, which extends LivingEntity. |
* | * | ||
* LivingEntity has health and can deal damage. | * LivingEntity has health and can deal damage. | ||
* MobEntity has movement controls and AI capabilities. | * MobEntity has movement controls and AI capabilities. | ||
- | * MobEntityWithAi has pathfinding favor and slightly tweaked leash behavior. | + | * PathAwareEntity has pathfinding favor and slightly tweaked leash behavior. |
*/ | */ | ||
- | public class CubeEntity extends MobEntityWithAi { | + | public class CubeEntity extends PathAwareEntity { |
- | public CubeEntity(EntityType<? extends MobEntityWithAi> entityType, World world) { | + | public CubeEntity(EntityType<? extends PathAwareEntity> entityType, World world) { |
super(entityType, world); | super(entityType, world); | ||
} | } | ||
Line 254: | Line 256: | ||
You can spawn your entity by typing ''/summon entitytesting:cube'' in-game. Press f3+b to view hitboxes: | You can spawn your entity by typing ''/summon entitytesting:cube'' in-game. Press f3+b to view hitboxes: | ||
{{https://i.imgur.com/MmQvluB.png}} | {{https://i.imgur.com/MmQvluB.png}} | ||
+ | |||
+ | **NOTE:** If your entity does not extend ''LivingEntity'' you have to create your own spawn packet handler. Either do this through the networking API, or mixin to ''ClientPlayNetworkHandler#onEntitySpawn'' | ||
+ | ===== Adding tasks & activities ===== | ||
+ | |||
+ | To add activities see [[:villager_activities|here]]. | ||