Search in sources :

Example 86 with TagCompound

use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.

the class RepositoryMyPetConverterService method v1_16_R1.

public void v1_16_R1(StoredMyPet pet) {
    TagCompound info = pet.getInfo();
    switch(pet.getPetType()) {
        case PigZombie:
            pet.setPetType(MyPetType.ZombifiedPiglin);
    }
    pet.setInfo(info);
}
Also used : TagCompound(de.keyle.knbt.TagCompound)

Example 87 with TagCompound

use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.

the class EntityConverterService method convertSaddledHorse.

public void convertSaddledHorse(AbstractHorse horse, TagCompound properties) {
    if (horse.getInventory() instanceof HorseInventory) {
        if (horse.getInventory().getSaddle() != null) {
            TagCompound saddle = MyPetApi.getPlatformHelper().itemStackToCompund(horse.getInventory().getSaddle());
            properties.getCompoundData().put("Saddle", saddle);
        }
    }
}
Also used : HorseInventory(org.bukkit.inventory.HorseInventory) TagCompound(de.keyle.knbt.TagCompound)

Example 88 with TagCompound

use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.

the class EntityConverterService method convertVillager.

public void convertVillager(Villager villager, TagCompound properties) {
    int profession = villager.getProfession().ordinal();
    properties.getCompoundData().put("Profession", new TagInt(profession));
    int type = villager.getVillagerType().ordinal();
    properties.getCompoundData().put("VillagerType", new TagInt(type));
    int level = villager.getVillagerLevel();
    properties.getCompoundData().put("VillagerLevel", new TagInt(level));
    TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(villager);
    Set<String> allowedTags = Sets.newHashSet("RestocksToday", "FoodLevel", "Gossips", "Offers", "LastRestock", "Inventory", "Xp");
    Set<String> keys = new HashSet<>(villagerTag.getCompoundData().keySet());
    for (String key : keys) {
        if (allowedTags.contains(key)) {
            continue;
        }
        villagerTag.remove(key);
    }
    properties.getCompoundData().put("OriginalData", villagerTag);
}
Also used : TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound) HashSet(java.util.HashSet)

Example 89 with TagCompound

use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.

the class EntityConverterService method convertEquipable.

public void convertEquipable(LivingEntity entity, TagCompound properties) {
    List<TagCompound> equipmentList = new ArrayList<>();
    if (random.nextFloat() <= entity.getEquipment().getChestplateDropChance()) {
        ItemStack itemStack = entity.getEquipment().getChestplate();
        if (itemStack != null && itemStack.getType() != Material.AIR) {
            TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
            item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Chestplate.getSlotId()));
            equipmentList.add(item);
        }
    }
    if (random.nextFloat() <= entity.getEquipment().getHelmetDropChance()) {
        ItemStack itemStack = entity.getEquipment().getHelmet();
        if (itemStack != null && itemStack.getType() != Material.AIR) {
            TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
            item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Helmet.getSlotId()));
            equipmentList.add(item);
        }
    }
    if (random.nextFloat() <= entity.getEquipment().getLeggingsDropChance()) {
        ItemStack itemStack = entity.getEquipment().getLeggings();
        if (itemStack != null && itemStack.getType() != Material.AIR) {
            TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
            item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Leggins.getSlotId()));
            equipmentList.add(item);
        }
    }
    if (random.nextFloat() <= entity.getEquipment().getBootsDropChance()) {
        ItemStack itemStack = entity.getEquipment().getBoots();
        if (itemStack != null && itemStack.getType() != Material.AIR) {
            TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
            item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Boots.getSlotId()));
            equipmentList.add(item);
        }
    }
    properties.getCompoundData().put("Equipment", new TagList(equipmentList));
}
Also used : ArrayList(java.util.ArrayList) TagInt(de.keyle.knbt.TagInt) TagList(de.keyle.knbt.TagList) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 90 with TagCompound

use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.

the class EntityConverterService method convertZombieVillager.

public void convertZombieVillager(ZombieVillager zombie, TagCompound properties) {
    properties.getCompoundData().put("Profession", new TagInt(zombie.getVillagerProfession().ordinal()));
    TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(zombie);
    Set<String> allowedTags = Sets.newHashSet("VillagerData");
    Set<String> keys = new HashSet<>(villagerTag.getCompoundData().keySet());
    for (String key : keys) {
        if (allowedTags.contains(key)) {
            continue;
        }
        villagerTag.remove(key);
    }
    properties.getCompoundData().put("VillagerData", villagerTag);
}
Also used : TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound) HashSet(java.util.HashSet)

Aggregations

TagCompound (de.keyle.knbt.TagCompound)199 TagInt (de.keyle.knbt.TagInt)67 TagByte (de.keyle.knbt.TagByte)65 TagList (de.keyle.knbt.TagList)57 ItemStack (org.bukkit.inventory.ItemStack)53 ArrayList (java.util.ArrayList)27 TagString (de.keyle.knbt.TagString)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 CompoundTag (net.minecraft.nbt.CompoundTag)12 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)11 TagShort (de.keyle.knbt.TagShort)10 HashSet (java.util.HashSet)9 MaterialData (org.bukkit.material.MaterialData)9 ListTag (net.minecraft.nbt.ListTag)8 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)6 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)6 TagBase (de.keyle.knbt.TagBase)5 List (java.util.List)5 ItemStack (net.minecraft.world.item.ItemStack)4 WorldGroup (de.Keyle.MyPet.api.WorldGroup)3