use of net.minecraft.nbt.NbtElement in project EdenClient by HahaOO7.
the class PerWorldConfig method save.
private void save(NbtCompound tag, Object obj) {
for (Field field : obj.getClass().getDeclaredFields()) {
if (!field.isAnnotationPresent(ConfigSubscriber.class))
continue;
Class<?> c = getClass(field);
ConfigLoader<NbtElement, ?> loader = getLoader(c);
if (loader == null) {
System.err.println("Error loading config: No loader found for class: " + c.getCanonicalName());
continue;
}
try {
field.setAccessible(true);
tag.put(field.getName(), loader.save(field.get(obj)));
} catch (IllegalAccessException e) {
System.err.println("Error loading config: Can't access field: " + c.getCanonicalName() + "." + field.getName());
}
}
}
use of net.minecraft.nbt.NbtElement in project frame-fabric by moddingplayground.
the class FrameBannerPatternConversions method makeData.
/**
* Parses the given NBT data into a list of {@link FrameBannerPatternData} objects.
*
* @param nbt a nullable {@link NbtList} with Frame banner pattern data
*/
public static List<FrameBannerPatternData> makeData(NbtList nbt) {
List<FrameBannerPatternData> res = new ArrayList<>();
if (nbt != null) {
for (NbtElement t : nbt) {
NbtCompound patternNbt = (NbtCompound) t;
FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(new Identifier(patternNbt.getString("Pattern")));
if (pattern != null) {
DyeColor color = DyeColor.byId(patternNbt.getInt("Color"));
int index = patternNbt.getInt("Index");
res.add(new FrameBannerPatternData(pattern, color, index));
}
}
}
return res;
}
use of net.minecraft.nbt.NbtElement in project frame-fabric by moddingplayground.
the class BannerBlockEntityMixin method frame_setBannerPatternNbt.
@Override
public void frame_setBannerPatternNbt(NbtList nbt) {
frame_bannerPatternsTag = nbt;
if (frame_bannerPatternsTag != null) {
// validate NBT data, removing and/or resetting invalid data
for (Iterator<NbtElement> itr = frame_bannerPatternsTag.iterator(); itr.hasNext(); ) {
NbtCompound element = (NbtCompound) itr.next();
Identifier id = Identifier.tryParse(element.getString("Pattern"));
int colorId = element.getInt("Color");
int index = element.getInt("Index");
if (id == null || !FrameBannerPatterns.REGISTRY.getIds().contains(id)) {
itr.remove();
} else {
int rtColorId = DyeColor.byId(colorId).getId();
if (rtColorId != colorId) {
element.putInt("Color", rtColorId);
}
if (index < 0) {
element.putInt("Index", 0);
}
}
}
// the Java API requires that this sort be stable
frame_bannerPatternsTag.sort(comparingInt(t -> ((NbtCompound) t).getInt("Index")));
}
}
use of net.minecraft.nbt.NbtElement in project meteor-client by MeteorDevelopment.
the class Marker method fromTag.
@Override
public Module fromTag(NbtCompound tag) {
super.fromTag(tag);
markers.clear();
NbtList list = tag.getList("markers", 10);
for (NbtElement tagII : list) {
NbtCompound tagI = (NbtCompound) tagII;
String type = tagI.getString("type");
BaseMarker marker = factory.createMarker(type);
if (marker != null) {
NbtCompound markerTag = (NbtCompound) tagI.get("marker");
if (markerTag != null)
marker.fromTag(markerTag);
markers.add(marker);
}
}
return this;
}
use of net.minecraft.nbt.NbtElement in project meteor-client by MeteorDevelopment.
the class BlockListSetting method load.
@Override
protected List<Block> load(NbtCompound tag) {
get().clear();
NbtList valueTag = tag.getList("value", 8);
for (NbtElement tagI : valueTag) {
Block block = Registry.BLOCK.get(new Identifier(tagI.asString()));
if (filter == null || filter.test(block))
get().add(block);
}
return get();
}
Aggregations