• Forums

Navigation

  • Home
  • Style Guide
  • Getting Started
    • Home
    • Structuring Your Mod
    • Forge Update Checker
    • Dependency Management
    • Debug Profiler
  • Concepts
    • Sides
    • Resources
    • Registries
    • The Fingerprint Violation Event
    • Internationalization and localization
  • Blocks
    • Home
    • Intro to Blockstates
    • Interaction
  • Animation API
    • Intro to the Animation API
    • Armatures
    • Animation State Machines
    • Using the API
  • Tile Entities
    • Home
    • Special Renderer
  • Items
    • Home
    • Loot Tables
  • Models
    • Intro to Models
    • Model Files
    • Blockstates
      • Intro to Blockstate JSONs
      • Forge Blockstate JSON
    • Connecting Blocks and Items to Models
    • Coloring Textures
    • Item Property Overrides
    • Advanced Models
      • Intro to Advanced Models
      • IModel
      • IModelState and IModelPart
      • IBakedModel
      • Extended Blockstates
      • Perspective
      • ItemOverrideList
      • ICustomModelLoader
  • Rendering
    • TileEntityItemStackRenderer
  • Events
    • Basic Usage
  • Networking
    • Home
    • Overview
    • SimpleImpl
    • Entities
      • Spawn Data
      • Dynamic Data
  • Data Storage
    • Capabilities
    • World Saved Data
    • Extended Entity Properties
    • Config Annotations
  • Utilities
    • Recipes
    • OreDictionary
    • PermissionAPI
  • Effects
    • Sounds
  • Conventions
    • Versioning
    • Locations
    • Loading Stages
  • Contributing to Forge
    • Getting Started
    • PR Guidelines

Entities

In addition to regular network messages, there are various other systems provided to handle synchronizing entity data.

Spawn Data

In general, the spawning of modded entities is handled seperately, by Forge.

Note

This means that simply extending a vanilla entity class may not inherit all its behaviour here. You may need to implement certain vanilla behaviours yourself.

You can add extra data to the spawn packet Forge sends by implementing the following interfaces.

IEntityAdditionalSpawnData

If your entity has data that is needed on the client, but doesn’t change over time, then it can be added to the entity spawn packet using this interface. writeSpawnData() and readSpawnData() control how the data should be en/decoded to/from the network buffer, in a similar fashion to the toBytes()/fromBytes() methods in IMessage.

IThrowableEntity

This is for “projectile” type entities. Implementing this interface will cause the ID of the “source” entity, as well as the initial velocity, to be sent to the client with the spawn packet.

Dynamic Data

Data Parameters

This is the main vanilla system for synchronizing entity data from the server to the client. As such, a number of vanilla examples are available to refer to.

Firstly you need a DataParameter<T> for the data you wish to keep synchronized. This should be stored as a static final field in your entity class, obtained by calling EntityDataManager.createKey() and passing the entity class and a serializer for that type of data. The available serializer implementations can be found as static constants within the DataSerializers class.

Warning

You should only create data parameters for your own entities, within that entity’s class. Adding parameters to entities you do not control can cause the IDs used to send that data over the network to become desynchronized, causing difficult to debug crashes.

Then, override entityInit() and call this.dataManager.register() for each of your data parameters, passing the parameter and an initial value to use. Remember to always call super.entityInit() first!

You can then get and set these values via your entity’s dataManager instance. Changes made will be synchronized to the client automatically.

Built with MkDocs using a custom theme. Hosted by Read the Docs.
Enable Dark Theme