Skip to content

Ships Core Entity

Mose edited this page Feb 9, 2021 · 1 revision

Entity

The Entity API within Ships Core is a bit different to many other implementations of Entity API in Minecraft.

When it comes to Entity class's in Ships Core, there are three main classes. Entity<?>, LiveEntity (which extends Entity) and EntitySnapshot (Which also extends Entity). After understanding these three classes, then its simple to understand.

Entity<?> class

The base Entity class is what you will be used to if you have used any sort of OOP API. Types of Entities extend onto common classes between them that extend onto more classes and eventually end up at Entity.

What makes this Entity API different is the Live and Snapshot varients of the entity.

##EntitySnapshot

A Entity Snapshot is all the data to make up the entity stored within a single class however does not relate to an actual entity in the world.

This means that you can create a entity snapshot and then spawn multiple copies of that entity into the minecraft world as specified from the entity snapshot.

Snapshots are also amazing for ... Well creating a snapshot of a entities state for if you wish to save that moment in time.

Every Entity will come with a Entity class for that Type, such as the Creeper will have a Entity class of Creeper<?> however you may have noticed the generic. This is because the Creeper class is not the highest level from the class, but instead either LiveCreeper or CreeperSnapshot is.

Creating a entity snapshot from a entity

This is the simplest way of creating a snapshot as you already have a starting point. You can create a snapshot of a entity from either a LiveEntity or a EntitySnapshot and therefore it is within the base entity class.

Entity<?> entity;
EntitySnapshot snapshot = entity.createSnapshot();

Live Entity

The Live entity relates to any entity within a world.

When it comes to functions that are unique to the Live variant, there shouldn't be many. Only functions that could only apply to the real entity such as sending a chat message to a player as only the real player can read those messages.