Search in sources :

Example 1 with GlowVillager

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
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag) List(java.util.List) MerchantRecipe(org.bukkit.inventory.MerchantRecipe) GlowVillager(net.glowstone.entity.passive.GlowVillager) EntityType(org.bukkit.entity.EntityType) NbtSerialization(net.glowstone.io.nbt.NbtSerialization) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) MerchantRecipe(org.bukkit.inventory.MerchantRecipe) GlowVillager(net.glowstone.entity.passive.GlowVillager) List(java.util.List) ArrayList(java.util.ArrayList) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 2 with GlowVillager

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);
}
Also used : GlowVillager(net.glowstone.entity.passive.GlowVillager) GlowZombieVillager(net.glowstone.entity.monster.GlowZombieVillager)

Aggregations

GlowVillager (net.glowstone.entity.passive.GlowVillager)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GlowZombieVillager (net.glowstone.entity.monster.GlowZombieVillager)1 NbtSerialization (net.glowstone.io.nbt.NbtSerialization)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 EntityType (org.bukkit.entity.EntityType)1 ItemStack (org.bukkit.inventory.ItemStack)1 MerchantRecipe (org.bukkit.inventory.MerchantRecipe)1