Trait DataMap
pub trait DataMap {
type Entry: DataMapEntry;
type Value;
// Required methods
fn id(&self) -> &str;
fn decode(&self, value: &Tag) -> Option<Self::Value>;
// Provided method
fn ty(&self) -> DataMapType { ... }
}Expand description
A data map a mod registers and reads, typed (NeoForge’s DataMapType<R, T>): its id, the
registry its entries are in (through DataMap::Entry), and how a value decodes.
Register it in data_map_types with DataMap::ty, then read an entry’s value with
ItemKey::data or BlockKey::data. A value arrives as the NBT form of the JSON a file
held: a whole number is an Int, or a Long past i32, a fraction a Double, a boolean a
Byte, an object a Compound and an array a List. Integers outside signed
64-bit range and null at any nesting depth return DataMapError::Undecodable
rather than changing the value. Fractional/exponent JSON tokens use the parser’s
f64 value; empty and heterogeneous arrays retain their elements.
use mod_api::{DataMap, ItemKey, Tag};
/// `projecte:emc`: an item's EMC value.
struct Emc;
impl DataMap for Emc {
type Entry = ItemKey;
type Value = i64;
fn id(&self) -> &str {
"projecte:emc"
}
fn decode(&self, value: &Tag) -> Option<i64> {
match value {
Tag::Int(value) => Some(i64::from(*value)),
Tag::Long(value) => Some(*value),
_ => None,
}
}
}
assert_eq!(Emc.ty().registry, "minecraft:item");Required Associated Types§
type Entry: DataMapEntry
type Entry: DataMapEntry
type Value
type Value
The value an entry holds.
Required Methods§
Provided Methods§
fn ty(&self) -> DataMapType
fn ty(&self) -> DataMapType
The type to push in data_map_types: this map’s id, for its entries’ registry.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".