Search in sources :

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

Example 17 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.compundToItemStack(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 18 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 : TagInt(de.keyle.knbt.TagInt) TagList(de.keyle.knbt.TagList) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 19 with TagCompound

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

the class EntityConverterService method convertEntity.

@Override
public void convertEntity(MyPet myPet, LivingEntity normalEntity) {
    if (myPet instanceof MyCreeper) {
        if (((MyCreeper) myPet).isPowered()) {
            ((Creeper) normalEntity).setPowered(true);
        }
    } else if (myPet instanceof MyEnderman) {
        if (((MyEnderman) myPet).hasBlock()) {
            MaterialData materialData = new MaterialData(((MyEnderman) myPet).getBlock().getType(), ((MyEnderman) myPet).getBlock().getData().getData());
            ((Enderman) normalEntity).setCarriedMaterial(materialData);
        }
    } else if (myPet instanceof MyIronGolem) {
        ((IronGolem) normalEntity).setPlayerCreated(true);
    } else if (myPet instanceof MyMagmaCube) {
        ((MagmaCube) normalEntity).setSize(((MyMagmaCube) myPet).getSize());
    } else if (myPet instanceof MyOcelot) {
        ((Ocelot) normalEntity).setCatType(Ocelot.Type.WILD_OCELOT);
        ((Ocelot) normalEntity).setTamed(false);
    } else if (myPet instanceof MyPig) {
        ((Pig) normalEntity).setSaddle(((MyPig) myPet).hasSaddle());
    } else if (myPet instanceof MySheep) {
        ((Sheep) normalEntity).setSheared(((MySheep) myPet).isSheared());
        ((Sheep) normalEntity).setColor(((MySheep) myPet).getColor());
    } else if (myPet instanceof MyVillager) {
        MyVillager villagerPet = (MyVillager) myPet;
        Villager.Profession profession = Villager.Profession.values()[villagerPet.getProfession()];
        ((Villager) normalEntity).setProfession(profession);
        if (villagerPet.hasOriginalData()) {
            TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(normalEntity);
            for (String key : villagerPet.getOriginalData().getCompoundData().keySet()) {
                villagerTag.put(key, villagerPet.getOriginalData().get(key));
            }
            MyPetApi.getPlatformHelper().applyTagToEntity(villagerTag, normalEntity);
        }
    } else if (myPet instanceof MyWolf) {
        ((Wolf) normalEntity).setTamed(false);
    } else if (myPet instanceof MySlime) {
        ((Slime) normalEntity).setSize(((MySlime) myPet).getSize());
    } else if (myPet instanceof MyZombie) {
        if (((MyZombie) myPet).isVillager()) {
            Villager.Profession profession = Villager.Profession.values()[((MyZombie) myPet).getProfession()];
            ((Zombie) normalEntity).setVillagerProfession(profession);
        }
    } else if (myPet instanceof MySkeleton) {
        ((Skeleton) normalEntity).setSkeletonType(Skeleton.SkeletonType.values()[((MySkeleton) myPet).getType()]);
        if (((MySkeleton) myPet).isWither()) {
            normalEntity.getEquipment().setItemInHand(new ItemStack(Material.STONE_SWORD));
        } else {
            normalEntity.getEquipment().setItemInHand(new ItemStack(Material.BOW));
        }
    } else if (myPet instanceof MyPigZombie) {
        normalEntity.getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
    } else if (myPet instanceof MyHorse) {
        Horse.Variant type = Horse.Variant.values()[((MyHorse) myPet).getHorseType()];
        Horse.Style style = Horse.Style.values()[(((MyHorse) myPet).getVariant() >>> 8)];
        Horse.Color color = Horse.Color.values()[(((MyHorse) myPet).getVariant() & 0xFF)];
        ((Horse) normalEntity).setVariant(type);
        ((Horse) normalEntity).setColor(color);
        ((Horse) normalEntity).setStyle(style);
        ((Horse) normalEntity).setCarryingChest(((MyHorse) myPet).hasChest());
        if (((MyHorse) myPet).hasSaddle()) {
            ((Horse) normalEntity).getInventory().setSaddle(((MyHorse) myPet).getSaddle().clone());
        }
        if (((MyHorse) myPet).hasArmor()) {
            ((Horse) normalEntity).getInventory().setArmor(((MyHorse) myPet).getArmor().clone());
        }
        ((Horse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyRabbit) {
        ((Rabbit) normalEntity).setRabbitType(((MyRabbit) myPet).getVariant().getBukkitType());
    } else if (myPet instanceof MyGuardian) {
        ((Guardian) normalEntity).setElder(((MyGuardian) myPet).isElder());
    }
    if (myPet instanceof MyPetBaby && normalEntity instanceof Ageable) {
        if (((MyPetBaby) myPet).isBaby()) {
            ((Ageable) normalEntity).setBaby();
        } else {
            ((Ageable) normalEntity).setAdult();
        }
    }
}
Also used : TagCompound(de.keyle.knbt.TagCompound) MyPetBaby(de.Keyle.MyPet.api.entity.MyPetBaby) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack)

Example 20 with TagCompound

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

the class EntityConverterService method convertEntity.

@Override
public void convertEntity(MyPet myPet, LivingEntity normalEntity) {
    if (myPet instanceof MyCreeper) {
        if (((MyCreeper) myPet).isPowered()) {
            ((Creeper) normalEntity).setPowered(true);
        }
    } else if (myPet instanceof MyEnderman) {
        if (((MyEnderman) myPet).hasBlock()) {
            MaterialData materialData = new MaterialData(((MyEnderman) myPet).getBlock().getType(), ((MyEnderman) myPet).getBlock().getData().getData());
            ((Enderman) normalEntity).setCarriedMaterial(materialData);
        }
    } else if (myPet instanceof MyIronGolem) {
        ((IronGolem) normalEntity).setPlayerCreated(true);
    } else if (myPet instanceof MyMagmaCube) {
        ((MagmaCube) normalEntity).setSize(((MyMagmaCube) myPet).getSize());
    } else if (myPet instanceof MyOcelot) {
        ((Ocelot) normalEntity).setCatType(Ocelot.Type.WILD_OCELOT);
        ((Ocelot) normalEntity).setTamed(false);
    } else if (myPet instanceof MyPig) {
        ((Pig) normalEntity).setSaddle(((MyPig) myPet).hasSaddle());
    } else if (myPet instanceof MySheep) {
        ((Sheep) normalEntity).setSheared(((MySheep) myPet).isSheared());
        ((Sheep) normalEntity).setColor(((MySheep) myPet).getColor());
    } else if (myPet instanceof MyVillager) {
        MyVillager villagerPet = (MyVillager) myPet;
        Villager.Profession profession = Villager.Profession.values()[villagerPet.getProfession()];
        ((Villager) normalEntity).setProfession(profession);
        if (villagerPet.hasOriginalData()) {
            TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(normalEntity);
            for (String key : villagerPet.getOriginalData().getCompoundData().keySet()) {
                villagerTag.put(key, villagerPet.getOriginalData().get(key));
            }
            MyPetApi.getPlatformHelper().applyTagToEntity(villagerTag, normalEntity);
        }
    } else if (myPet instanceof MyWolf) {
        ((Wolf) normalEntity).setTamed(false);
    } else if (myPet instanceof MySlime) {
        ((Slime) normalEntity).setSize(((MySlime) myPet).getSize());
    } else if (myPet instanceof MyZombie) {
        ((Zombie) normalEntity).setVillager(((MyZombie) myPet).isVillager());
    } else if (myPet instanceof MySkeleton) {
        ((Skeleton) normalEntity).setSkeletonType(Skeleton.SkeletonType.values()[((MySkeleton) myPet).getType()]);
        if (((MySkeleton) myPet).isWither()) {
            normalEntity.getEquipment().setItemInHand(new ItemStack(Material.STONE_SWORD));
        } else {
            normalEntity.getEquipment().setItemInHand(new ItemStack(Material.BOW));
        }
    } else if (myPet instanceof MyPigZombie) {
        normalEntity.getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD));
    } else if (myPet instanceof MyHorse) {
        Horse.Variant type = Horse.Variant.values()[((MyHorse) myPet).getHorseType()];
        Horse.Style style = Horse.Style.values()[(((MyHorse) myPet).getVariant() >>> 8)];
        Horse.Color color = Horse.Color.values()[(((MyHorse) myPet).getVariant() & 0xFF)];
        ((Horse) normalEntity).setVariant(type);
        ((Horse) normalEntity).setColor(color);
        ((Horse) normalEntity).setStyle(style);
        ((Horse) normalEntity).setCarryingChest(((MyHorse) myPet).hasChest());
        if (((MyHorse) myPet).hasSaddle()) {
            ((Horse) normalEntity).getInventory().setSaddle(((MyHorse) myPet).getSaddle().clone());
        }
        if (((MyHorse) myPet).hasArmor()) {
            ((Horse) normalEntity).getInventory().setArmor(((MyHorse) myPet).getArmor().clone());
        }
        ((Horse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyRabbit) {
        ((Rabbit) normalEntity).setRabbitType(((MyRabbit) myPet).getVariant().getBukkitType());
    } else if (myPet instanceof MyGuardian) {
        ((Guardian) normalEntity).setElder(((MyGuardian) myPet).isElder());
    }
    if (myPet instanceof MyPetBaby && normalEntity instanceof Ageable) {
        if (((MyPetBaby) myPet).isBaby()) {
            ((Ageable) normalEntity).setBaby();
        } else {
            ((Ageable) normalEntity).setAdult();
        }
    }
}
Also used : TagCompound(de.keyle.knbt.TagCompound) MyPetBaby(de.Keyle.MyPet.api.entity.MyPetBaby) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

TagCompound (de.keyle.knbt.TagCompound)141 TagInt (de.keyle.knbt.TagInt)53 TagByte (de.keyle.knbt.TagByte)49 TagList (de.keyle.knbt.TagList)47 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)18 TagString (de.keyle.knbt.TagString)12 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 MaterialData (org.bukkit.material.MaterialData)9 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)8 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)5 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)3 TagShort (de.keyle.knbt.TagShort)3 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)3