Skip to content

Morph API

Budschie edited this page Aug 10, 2022 · 2 revisions

The goal of this page is to show how to interact with the code of this mod via Java. If you want to instead write a datapack, you should take a look at File Layouts and [Datapack Overview](https://github.com/Budschie/BudschieMorphMod/wiki/Datapack-Overview


The API

There are currently a bunch of ways to interact with this mod.

Morph players

For example, there is the class MorphUtil: It contains a bunch of useful utils related to this mod. If you want to automatically morph the player to an entity, calling MorphUtil.morphToServer is your best bet, just make sure to insert a if(!level.isClientSide()) check to make sure that this method is indeed only being called on the logical server side.

Prevent players from morphing

There are also a bunch of events dedicated to handle morphing. For a full list of them, just look into the class PlayerMorphEvent. If you want to prevent a player from morphing, this is probably the best event for this kind of thing.

Modify morphs on creation

If your goal is to modify the creation of morphs which is not covered by data transformers and morph_nbt files, use the MorphCreatedFromEntityEvent.

Handle morph acquisition

There is also the AcquiredMorphEvent to hook into the behavior of acquiring morphs.

Modify appearance of morphs

To render the morph instead of the player, a proxy entity representing the morph is being created. You can use the InitializeMorphEntityEvent, which is being fired solely on the logical (and therefor also physical) client side whenever a proxy entity has been created out of a morph, to modify this entity on creation.

If you want to change certain data of the proxy entity on a per-tick basis, create a class and implement the IEntitySynchronizer interface. Then, after filling this class with code accordingly (the JavaDoc of this interface is your best guide here), register the synchronizer on the FMLClientSetupEvent event by calling the thread-safe method EntitySynchronizerRegistry.addEntitySynchronizer.

Clone this wiki locally