EntityCodec

Trait EntityCodec 

Source
pub trait EntityCodec: Send + Sync {
    // Required methods
    fn encode(
        &self,
        src: &EntityRef<'_>,
        dst: &mut CompoundTag,
    ) -> Result<(), String>;
    fn decode(
        &self,
        src: &CompoundTag,
        dst: &mut EntityBuilder,
    ) -> Result<(), String>;
    fn default(&self, dst: &mut EntityBuilder);
}
Expand description

This trait describes a specific way of encoding, decoding and building a default variant of a component structure for an entity. This trait should usually be implemented for each component of an entity, however because it doesn’t provide any type restriction you can encode, decode and add whatever default value you want.

Structures implementing this trait can be zero-sized and defined statically, doing this allows you to make &'static dyn EntityCodec references that can be used as constants to define default codecs for an entity component structure.

Required Methods§

Source

fn encode( &self, src: &EntityRef<'_>, dst: &mut CompoundTag, ) -> Result<(), String>

Encode components stored accessible from the given entity reference into given destination compound tag.

Source

fn decode( &self, src: &CompoundTag, dst: &mut EntityBuilder, ) -> Result<(), String>

Decode given source compound tag and add decoded components into the given entity builder.

Source

fn default(&self, dst: &mut EntityBuilder)

Add default components to the given entity builder.

Implementors§