Skip to content

Commit

Permalink
feat(docs): EntityType basics
Browse files Browse the repository at this point in the history
  • Loading branch information
ChampionAsh5357 committed Jun 2, 2024
1 parent 6bf5517 commit ad5bf52
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion docs/entities/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends ExampleEntity> type, Level level) {
super(type, level);
// ...
}

// ...
}

// In some class that holds registry objects
public static final DeferredRegister<EntityType<?>> REGISTRAR = DeferredRegister.create(Registries.ENTITY_TYPE, MOD_ID);

public static final DeferredHolder<EntityType<?>, EntityType<ExampleEntity>> 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

Expand Down Expand Up @@ -69,5 +104,7 @@ TODO
[entity]: #everything-revolves-around-entity
[entityrenderer]: ./renderer.md
[summon]: #summoning-an-entity
[registered]: ../concepts/registries.md#methods-for-registering
<!-- Replace with living entity docs -->
[living]: #
[mobcategory]: #

1 comment on commit ad5bf52

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying with Cloudflare Pages

Name Result
Last commit: ad5bf521e201cdb696f0feabcaa3dcb02d91e78b
Status: ✅ Deploy successful!
Preview URL: https://72042281.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-95.neoforged-docs-previews.pages.dev

Please sign in to comment.