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§
Sourcefn encode(
&self,
src: &EntityRef<'_>,
dst: &mut CompoundTag,
) -> Result<(), String>
fn encode( &self, src: &EntityRef<'_>, dst: &mut CompoundTag, ) -> Result<(), String>
Encode components stored accessible from the given entity reference into given destination compound tag.
Sourcefn decode(
&self,
src: &CompoundTag,
dst: &mut EntityBuilder,
) -> Result<(), String>
fn decode( &self, src: &CompoundTag, dst: &mut EntityBuilder, ) -> Result<(), String>
Decode given source compound tag and add decoded components into the given entity builder.
Sourcefn default(&self, dst: &mut EntityBuilder)
fn default(&self, dst: &mut EntityBuilder)
Add default components to the given entity builder.