use of net.minecraft.nbt.NbtElement in project Polymorph by TheIllusiveC4.
the class AbstractStackRecipeData method readNbt.
@Override
public void readNbt(NbtCompound pCompound) {
if (pCompound.contains("SelectedRecipe")) {
this.loadedRecipe = new Identifier(pCompound.getString("SelectedRecipe"));
}
if (pCompound.contains("RecipeDataSet")) {
Set<RecipePair> dataset = this.getRecipesList();
dataset.clear();
NbtList list = pCompound.getList("RecipeDataSet", NbtType.COMPOUND);
for (NbtElement inbt : list) {
NbtCompound tag = (NbtCompound) inbt;
Identifier id = Identifier.tryParse(tag.getString("Id"));
ItemStack stack = ItemStack.fromNbt(tag.getCompound("ItemStack"));
dataset.add(new RecipePairImpl(id, stack));
}
}
}
use of net.minecraft.nbt.NbtElement in project Primeval by devs-immortal.
the class VesselItem method getBundledStacks.
private static Stream<ItemStack> getBundledStacks(ItemStack stack) {
NbtCompound nbtCompound = stack.getNbt();
if (nbtCompound == null) {
return Stream.empty();
} else {
NbtList nbtList = nbtCompound.getList("Items", 10);
Stream<NbtElement> var10000 = nbtList.stream();
Objects.requireNonNull(NbtCompound.class);
return var10000.map(NbtCompound.class::cast).map(ItemStack::fromNbt);
}
}
use of net.minecraft.nbt.NbtElement in project bewitchment by MoriyaShiine.
the class DemonEntity method readCustomDataFromNbt.
@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);
dataTracker.set(MALE, nbt.getBoolean("Male"));
if (nbt.contains("Offers")) {
offers.clear();
NbtList offersList = nbt.getList("Offers", NbtType.COMPOUND);
for (NbtElement offerTag : offersList) {
offers.add(new DemonTradeOffer((NbtCompound) offerTag));
}
}
tradeResetTimer = nbt.getInt("TradeResetTimer");
}
use of net.minecraft.nbt.NbtElement in project EdenClient by HahaOO7.
the class ChestShopLoader method load.
public ChestShopMap load(NbtList tag) {
ChestShopMap map = new ChestShopMap();
for (NbtElement element : tag) {
ChestShopEntry entry = new ChestShopEntry((NbtCompound) element);
ChestShopSet set = map.computeIfAbsent(entry.getChunkPos(), k -> new ChestShopSet());
set.add(entry);
}
return map;
}
use of net.minecraft.nbt.NbtElement in project EdenClient by HahaOO7.
the class PerWorldConfig method load.
private void load(NbtCompound tag, Object obj) {
for (Field field : obj.getClass().getDeclaredFields()) {
var annotation = field.getDeclaredAnnotation(ConfigSubscriber.class);
if (annotation == null)
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);
String fieldName = field.getName();
NbtElement nbt = tag.contains(fieldName) ? tag.get(fieldName) : loader.parse(annotation.value());
Object value;
try {
value = loader.load(nbt);
} catch (ClassCastException e) {
System.err.println("Error while loading " + field.getName() + " in class " + obj.getClass().getSimpleName());
value = loader.load(loader.parse(annotation.value()));
}
field.set(obj, value);
} catch (IllegalAccessException e) {
System.err.println("Error loading config: Can't access field: " + c.getCanonicalName() + "." + field.getName());
}
}
}
Aggregations