From ad5bf521e201cdb696f0feabcaa3dcb02d91e78b Mon Sep 17 00:00:00 2001 From: ChampionAsh5357 Date: Sun, 2 Jun 2024 11:42:38 -0400 Subject: [PATCH] feat(docs): EntityType basics --- docs/entities/index.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/entities/index.md b/docs/entities/index.md index 088d959f..b9f789d4 100644 --- a/docs/entities/index.md +++ b/docs/entities/index.md @@ -23,7 +23,42 @@ The simplest and most trivial entity does absolutely nothing. Most users will on ## `EntityType`: The Grounding Principle -TODO +An `EntityType` is the singleton that defines what an entity is. Multiple entities within the world can be associated with one `EntityType`. The `EntityType` also links an [`EntityRenderer`][entityrenderer] to its corresponding `Entity` class. It also defines default properties that all entities with this type has. The `EntityType` must be [registered]. + +An `EntityType` can be constructed via `EntityType.Builder#of`. This method takes in two parameters: an `EntityType.EntityFactory` that [constructs a default `Entity` instance][entity], and a [`MobCategory`][mobcategory] indicating the entity type. The `EntityType` can be built via `EntityType.Builder#build` by passing in `null` as the argument. + +:::info +The `String` in the `build` method represents the registry name of the `EntityType` and is used when dealing with data fixers. The reason we pass in `null` is that data fixers go unused in mod development. If a value is passed in, then Vanilla's data fixer will continually throw a warning when loading the game as there is no definition within an applicable schema. +::: + +```java +// For some entity +public static class ExampleEntity extends Entity { + + // This is the constructor definition for use in 'EntityType.EntityFactory' + public ExampleEntity(EntityType type, Level level) { + super(type, level); + // ... + } + + // ... +} + +// In some class that holds registry objects +public static final DeferredRegister> REGISTRAR = DeferredRegister.create(Registries.ENTITY_TYPE, MOD_ID); + +public static final DeferredHolder, EntityType> EXAMPLE_ENITTY = REGISTRAR.register( + "example_entity", + () -> EntityType.Builder.of( + ExampleEntity::new // The constructor definition, + MobCategory.MISC // Category for entities that do not generally extend 'Mob' + ).build(null) // String value goes unused +); +``` + +:::note +The builder contains many methods that will be further discussed in other sections to help with understanding. An example for applying each to an `EntityType` will be provided there. +::: ### Entity Dimensions @@ -69,5 +104,7 @@ TODO [entity]: #everything-revolves-around-entity [entityrenderer]: ./renderer.md [summon]: #summoning-an-entity +[registered]: ../concepts/registries.md#methods-for-registering [living]: # +[mobcategory]: #