Skip to content

Instantly share code, notes, and snippets.

@apace100
Created May 21, 2023 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apace100/bfbf82a8f9d6bd2db13e4feaf653a6b0 to your computer and use it in GitHub Desktop.
Save apace100/bfbf82a8f9d6bd2db13e4feaf653a6b0 to your computer and use it in GitHub Desktop.
Deprecation of damage sources in Apoli (Minecraft 1.19.4+)

TL;DR for Datapackers - What you should do

If you're creating a datapack with Apoli, e.g. an Origins datapack, you should check whether you use any of these things:

  • damage entity action
  • damage bientity action
  • damage_over_time power type

While your datapack might work without any changes, you should update it to ensure correct functionality both now and going forward.

To update to using damage types, change from using the field source or damage_source to using the new field damage_type. Register a new damage type for each different kind of damage you use in your datapack, and specify the ID in the corresponding action or power.

An example of these changes can be found in Origins: https://github.com/apace100/origins-fabric/commit/74fce872d8bb8a1c0d1d1089a4c7983ff083cfbc

Keep in mind that updating to damage types will make your pack not work on previous versions, so you should clearly communicate this when you publish your datapack.

That's it! If you're interested on the technical background, feel free to read on.

Changes in Vanilla

With Minecraft 1.19.4, damage sources are now separate from the new concept of "damage types". Where before, a damage source would specify the attacking entity, the source entity, and properties of the damage, it now only specifies the attacking and source entities and only holds a reference to a "damage type", which in turn controls the damage properties. While damage sources could be created on-the-fly in 1.19.3 and below with arbitrary combinations of properties, the damage types which took over this job are part of a dynamic registry, meaning they're more "static" than damage sources were, and well-defined. Datapacks can register new damage types themselves. Most of the properties of a damage type, which previously were managed in code on the damage source, are now data-driven and managed via damage type tags. To read more about damage types and their JSON format, check out the Minecraft Wiki and the page on damage type tags.

Damage Sources in Apoli for MC 1.19.3 and below

Apoli made use of the very dynamic nature of damage sources, by allowing datapackers to specify whatever type of damage they'd like to use in actions like damage, or power types like damage_over_time. It allowed specifying the damage properties bypasses_armor, fire, unblockable, magic, out_of_world, projectile and explosive via boolean fields, as well as specifying a name which in turn was used to create death messages.

Damage Sources in Apoli for MC 1.19.4 and up

To ensure backwards compatibility, Apoli will still read out the previously used damage source fields. However, it will not create a damage type for each damage source specified in an Apoli-based datapack.

Instead, Apoli will perform a search of all registered damage types. Among those, it looks for a damage type which is contained in tags matching the desired properties (the ones set to true) and not contained in undesired properties (the ones set to false). It will then use the damage type which matches the specified properties in the damage source field the best, but before doing so, will insert the name into the damage source. This insertion ensures that the damage will display the correct death message if it deals a fatal blow.

In case no registered damage type matches the desired properties perfectly, a warning will be produced in the console.

To specify a damage type, datapackers can use the damage_type field which was added alongside the legacy source or damage_source fields.

Why should I update my pack?

As a datapacker, you may notice your pack still works the same, even though you use one of the changed features. However, you should still consider updating to use damage types, for the following reasons:

  1. There may not be a perfect match for your damage type properties, causing the damage to be functionally different from what you want in some cases (e.g. not bypassing armor, or not counting as fire damage).
  2. Even if there is a perfect match now, there is no guarantee that Vanilla registered types change in the future meaning you might lose that perfectly matching damage type your pack relies on now.
  3. Which damage type matches your damage source depends on the registry, thus may differ depending on the installed mods or even the world a player is playing in.
  4. The concept of damage sources as they were used in Apoli, and along with that the associated fields source and damage_source, are deprecated, and are likely to be removed in a future update.
  5. Using damage_type is more performant, as no search of registered damage types has to be performed to match your source.
  6. Registering your custom damage type gives you more control, as it allows to modify scaling and exhaustion value of the damage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment