Search in sources :

Example 91 with TagCompound

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

the class CustomInventory method load.

public void load(TagCompound nbtTagCompound) {
    TagList items = nbtTagCompound.getAs("Items", TagList.class);
    for (int i = 0; i < items.size(); i++) {
        TagCompound itemCompound = items.getTagAs(i, TagCompound.class);
        ItemStack itemStack = ItemStackNBTConverter.compoundToItemStack(itemCompound);
        setItem(itemCompound.getAs("Slot", TagByte.class).getByteData(), itemStack);
    }
}
Also used : TagList(de.keyle.knbt.TagList) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 92 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) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 93 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));
    TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(villager);
    Set<String> allowedTags = Sets.newHashSet("Riches", "Career", "CareerLevel", "Willing", "Inventory", "Offers");
    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 94 with TagCompound

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

the class EggIconService method updateIcon.

@Override
public void updateIcon(MyPetType type, IconMenuItem icon) {
    icon.setMaterial(Material.MONSTER_EGG);
    TagCompound entityTag = new TagCompound();
    switch(type) {
        case Bat:
            entityTag.put("id", new TagString("Bat"));
            break;
        case Blaze:
            entityTag.put("id", new TagString("Blaze"));
            break;
        case CaveSpider:
            entityTag.put("id", new TagString("CaveSpider"));
            break;
        case Chicken:
            entityTag.put("id", new TagString("Chicken"));
            break;
        case Cow:
            entityTag.put("id", new TagString("Cow"));
            break;
        case Creeper:
            entityTag.put("id", new TagString("Creeper"));
            break;
        case EnderDragon:
            entityTag.put("id", new TagString("EnderDragon"));
            break;
        case Enderman:
            entityTag.put("id", new TagString("Enderman"));
            break;
        case Endermite:
            entityTag.put("id", new TagString("Endermite"));
            break;
        case Ghast:
            entityTag.put("id", new TagString("Ghast"));
            break;
        case Giant:
            entityTag.put("id", new TagString("Giant"));
            break;
        case Guardian:
            entityTag.put("id", new TagString("Guardian"));
            break;
        case Horse:
            entityTag.put("id", new TagString("EntityHorse"));
            break;
        case IronGolem:
            entityTag.put("id", new TagString("VillagerGolem"));
            icon.setGlowing(true);
            break;
        case MagmaCube:
            entityTag.put("id", new TagString("LavaSlime"));
            break;
        case Mooshroom:
            entityTag.put("id", new TagString("MushroomCow"));
            break;
        case Ocelot:
            entityTag.put("id", new TagString("Ozelot"));
            break;
        case Pig:
            entityTag.put("id", new TagString("pig"));
            break;
        case PigZombie:
            entityTag.put("id", new TagString("PigZombie"));
            break;
        case PolarBear:
            entityTag.put("id", new TagString("PolarBear"));
            break;
        case Rabbit:
            entityTag.put("id", new TagString("Rabbit"));
            break;
        case Sheep:
            entityTag.put("id", new TagString("Sheep"));
            break;
        case Silverfish:
            entityTag.put("id", new TagString("Silverfish"));
            break;
        case Skeleton:
            entityTag.put("id", new TagString("Skeleton"));
            break;
        case Slime:
            entityTag.put("id", new TagString("Slime"));
            break;
        case Snowman:
            entityTag.put("id", new TagString("Snowman"));
            break;
        case Spider:
            entityTag.put("id", new TagString("Spider"));
            break;
        case Squid:
            entityTag.put("id", new TagString("Squid"));
            break;
        case Witch:
            entityTag.put("id", new TagString("Witch"));
            break;
        case Wither:
            entityTag.put("id", new TagString("WitherBoss"));
            icon.setGlowing(true);
            break;
        case Wolf:
            entityTag.put("id", new TagString("Wolf"));
            break;
        case Villager:
            entityTag.put("id", new TagString("Villager"));
            break;
        case Zombie:
            entityTag.put("id", new TagString("Zombie"));
            break;
    }
    icon.addTag("EntityTag", entityTag);
}
Also used : TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

Example 95 with TagCompound

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

the class Behavior method save.

public TagCompound save() {
    TagCompound nbtTagCompound = new TagCompound();
    nbtTagCompound.getCompoundData().put("Mode", new TagString(behavior.name()));
    return nbtTagCompound;
}
Also used : TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

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