Skip to content

Datapacks

CleverNucleus edited this page Jun 21, 2021 · 6 revisions

Datapacks

Definitions

  • Player Attributes: Entity Attributes that the player has, exposed through datapacks.
  • Vanilla Attributes: Player Attributes that exist in the game already (such as max health).
  • Default Attributes: Player Attributes implemented by default with PlayerEx (including vanilla attributes).

Description

PlayerEx exposes player attributes through datapacks. This allows for complete customisability over player attributes. Since datapacks are server-sided, player attributes are synced to the client on world join, meaning a server can customise player attributes and have those changes reflected in the client(s), without the client requiring the datapack that implemented those changes. Note that a server restart is required when changes are made to player attributes through datapacks, and the /reload command and F3 + T keys have no impact on PlayerEx datapacks.

Datapack Method

A minor caveat to exposing player attributes through datapacks is that the datapack must be loaded before (or during) the world start. You can't load a world and then load/reload a datapack - the world would have to be restarted. As such, there are a few ways to modify player attributes through datapacks:

Editing the PlayerEx mod jar directly

You can open the PlayerEx mod jar and edit the mod-provided datapack directly.

Loading datapacks on Singleplayer

When going to create a world, you can load the appropriate datapack(s) of your choice through the client's provided loader (datapacks button).

Loading datapacks on a Server and in General

The following is the recommended method to load PlayerEx datapacks, as well one of the only ways to load PlayerEx datapacks on a server apart from modyfing the PlayerEx mod jar directly.

Installing the Open Loader mod allows for datapacks to be loaded during the worlds first creation/start, by placing the datapack in Open Loader's config folder (see the Open Loader page for information on how to do this).

Structure

The structure that a PlayerEx datapack should follow is shown below: Example datapack structure

If another mod has added its own attributes using the PlayerEx API, they likely have another folder under data titled as their modid; you can also add this folder into your datapack and edit their attributes.

Editing the Datapack

Adding a player attribute is as simple as adding a new .json file to the correct data folder; if you are not a developer and just wish to add an attribute, then it is advisable to add the attribute to the playerex folder, otherwise use your own modid. To modify an attribute just edit the relevant json. It is not recommended to remove any of the default attributes outright, as all the default attributes are implemented into the game. However, it is possible to remove that attribute's functionality (i.e. lifesteal): its default value is 0, at which the attribute has no game impact, so the correct way to disable it's functionality is to stop other attributes from increasing lifesteal's value - this is easy and only requires you to remove any functions from attributes that modify lifesteal's value.

An example datapack is provided here. This example pack includes all the default attributes with their default state (i.e. the default PlayerEx implementation).