use of net.glowstone.entity.passive.GlowVillager in project Glowstone by GlowstoneMC.
the class VillagerStore method load.
@Override
public void load(GlowVillager entity, CompoundTag compound) {
super.load(entity, compound);
compound.tryGetInt("Profession").filter(GlowVillager::isValidProfession).map(GlowVillager::getProfessionById).ifPresent(entity::setProfession);
compound.tryGetInt("Career").map(GlowVillager::getProfessionById).ifPresent(career -> {
entity.setProfession(career);
entity.setCareerLevel(compound.tryGetInt("CareerLevel").orElse(1));
});
compound.readInt("Riches", entity::setRiches);
compound.readBoolean("Willing", entity::setWilling);
// Recipes
compound.readCompound("Offers", offers -> offers.readCompoundList("Recipes", recipesList -> {
// clear defaults
entity.clearRecipes();
List<MerchantRecipe> recipes = new ArrayList<>(recipesList.size());
for (CompoundTag recipeTag : recipesList) {
recipeTag.readItem("sell", sell -> {
List<ItemStack> ingredients = new ArrayList<>(2);
recipeTag.readItem("buy", ingredients::add);
recipeTag.readItem("buyB", ingredients::add);
boolean experienceReward = recipeTag.getBoolean("rewardExp", false);
int uses = recipeTag.getInt("uses");
int maxUses = recipeTag.getInt("maxUses");
MerchantRecipe recipe = new MerchantRecipe(sell, uses, maxUses, experienceReward);
recipe.setIngredients(ingredients);
recipes.add(recipe);
});
}
entity.setRecipes(recipes);
}));
// TODO: remaining data
}
use of net.glowstone.entity.passive.GlowVillager in project Glowstone by GlowstoneMC.
the class ZombieVillagerStore method load.
@Override
public void load(GlowZombie zombie, CompoundTag compound) {
checkArgument(zombie instanceof GlowZombieVillager);
GlowZombieVillager entity = (GlowZombieVillager) zombie;
super.load(entity, compound);
entity.setVillagerProfession(compound.tryGetInt(PROFESSION).filter(GlowVillager::isValidProfession).map(GlowVillager::getProfessionById).orElseGet(() -> getRandomProfession(ThreadLocalRandom.current())));
entity.setConversionTime(compound.tryGetInt(CONVERSION_TIME).orElse(-1));
compound.readUniqueId(CONVERSION_PLAYER, entity::setConversionPlayerId);
}
Aggregations