use of slimeknights.tconstruct.library.tools.stat.IToolStat in project TinkersConstruct by SlimeKnights.
the class StatsNBT method readFromNBT.
/**
* Reads the stat from NBT
*/
public static StatsNBT readFromNBT(@Nullable Tag inbt) {
if (inbt == null || inbt.getId() != Tag.TAG_COMPOUND) {
return EMPTY;
}
ImmutableMap.Builder<IToolStat<?>, Object> builder = ImmutableMap.builder();
// simply try each key as a tool stat
CompoundTag nbt = (CompoundTag) inbt;
for (String key : nbt.getAllKeys()) {
Tag tag = nbt.get(key);
if (tag != null) {
IToolStat<?> stat = readStatIdFromNBT(key);
if (stat != null) {
Object value = stat.read(tag);
if (value != null) {
builder.put(stat, value);
}
}
}
}
return new StatsNBT(builder.build());
}
use of slimeknights.tconstruct.library.tools.stat.IToolStat in project TinkersConstruct by SlimeKnights.
the class StatsNBT method serializeToNBT.
/**
* Writes these stats to NBT
*/
public CompoundTag serializeToNBT() {
CompoundTag nbt = new CompoundTag();
for (Entry<IToolStat<?>, Object> entry : stats.entrySet()) {
IToolStat<?> stat = entry.getKey();
Tag serialized = serialize(stat, entry.getValue());
if (serialized != null) {
nbt.put(stat.getName().toString(), serialized);
}
}
return nbt;
}
Aggregations