Skip to content

Commit

Permalink
address the leftover comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Dec 2, 2024
1 parent 362280b commit a1746fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion docs/entities/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sidebar_position: 2

One of the most important use cases of entities is to store data of some sort. All entities store some default data, such as their type and their position. This article will explain how to add your own data, as well as how to synchronize that data.

The most simple way to add data is as a field in your `Entity` class. You can then interact with this data in any way you wish. However, this quickly becomes very annoying as soon as you have to synchronize that data.
The most simple way to add data is as a field in your `Entity` class. You can then interact with this data in any way you wish. However, this quickly becomes very annoying as soon as you have to synchronize that data. This is because most entity logic is run on the server only, and it is only occasionally (depending on the [`EntityType`][entitytype]'s `clientUpdateInterval` value) that an update is sent to the client; this is also the cause for easily noticeable entity "lags" when the server's tick speed is too slow.

As such, vanilla introduces a few systems to help with that. These systems generally exist in parallel and can be replaced with one another, this is due to legacy reasons.

Expand Down Expand Up @@ -87,6 +87,7 @@ Entities have been patched to extend `AttachmentHolder` and as such support data
Of course, you can also always opt to use a custom packet to send additional information when needed. Please refer to the [Networking articles][networking] for more information.

[attachment]: ../datastorage/attachments.md
[entitytype]: index.md#entitytype
[nbt]: ../datastorage/nbt.md
[networking]: ../networking/index.md
[registration]: ../concepts/registries.md#methods-for-registering
Expand Down
8 changes: 4 additions & 4 deletions docs/entities/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ While not all entities have the concept of hit points, they can still all receiv

Damaging an entity is possible by calling `Entity#hurt`. `Entity#hurt` takes two arguments: the [`DamageSource`][damagesource] and the damage amount, as a float in half hearts. For example, calling `entity.hurt(entity.damageSources().wither(), 4.25)` will cause a little over two hearts of wither damage.

In turn, entities can also modify the behavior in `#hurt` by overriding it. For example, we could make our entity take double damage from fire, and no damage from any other source, like so:
In turn, entities can also modify that behavior. This isn't done by overriding `#hurt`, as it is a final method. Rather, there are two methods `#hurtServer` and `#hurtClient` that each handle damage logic for the corresponding side. `#hurtClient` is commonly used to tell the client that an attack has succeeded, even though that may not always be true, mainly for playing attack sounds and other effects regardless. For changing damage behavior, we mainly care about `#hurtServer`, which we can override like so:

```java
@Override
// The boolean return value determines whether the entity was actually damaged or not.
public boolean hurt(DamageSource damageSource, float amount) {
public boolean hurtServer(ServerLevel level, DamageSource damageSource, float amount) {
if (damageSource.is(DamageTypeTags.IS_FIRE)) {
return super.hurt(damageSource, amount * 2);
return super.hurt(level, damageSource, amount * 2);
} else {
return false;
}
Expand All @@ -203,7 +203,7 @@ Quite often, you will want your entity to do something (e.g. move) every tick. T

- `#tick`: This is the central tick method, and the one you will want to override in 99% of cases.
- By default, this forwards to `#baseTick`, however this is overridden by almost every subclass.
- `#baseTick`: This method handles updating some values common to all entities, including the "on fire" state, freezing from powder snow, the swimming state, and passing through portals.
- `#baseTick`: This method handles updating some values common to all entities, including the "on fire" state, freezing from powder snow, the swimming state, and passing through portals. `LivingEntity` additionally handles drowning, in-block damage, and updates to the damage tracker here. Override this method if you want to change or add to that logic.
- By default, `Entity#tick` will forward to this method.
- `#rideTick`: This method is called for passengers of other entities, for example for players riding horses, or any entity that rides another entity due to use of the `/ride` command.
- By default, this does some checks and then calls `#tick`. Skeletons and players override this method for special handling of riding entities.
Expand Down

1 comment on commit a1746fe

@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: a1746fef90e60a1969ca5aec4f42bcf3b2c8cd09
Status: ✅ Deploy successful!
Preview URL: https://f8a14c0f.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-171.neoforged-docs-previews.pages.dev

Please sign in to comment.