Search in sources :

Example 26 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.

the class ItemStackNBTConverter method compoundToVanillaCompound.

public static Tag compoundToVanillaCompound(TagBase tag) {
    switch(TagType.getTypeById(tag.getTagTypeId())) {
        case Int:
            return IntTag.valueOf(((TagInt) tag).getIntData());
        case Short:
            return ShortTag.valueOf(((TagShort) tag).getShortData());
        case String:
            return StringTag.valueOf(((TagString) tag).getStringData());
        case Byte:
            return ByteTag.valueOf(((TagByte) tag).getByteData());
        case Byte_Array:
            return new ByteArrayTag(((TagByteArray) tag).getByteArrayData());
        case Double:
            return DoubleTag.valueOf(((TagDouble) tag).getDoubleData());
        case Float:
            return FloatTag.valueOf(((TagFloat) tag).getFloatData());
        case Int_Array:
            return new IntArrayTag(((TagIntArray) tag).getIntArrayData());
        case Long:
            return LongTag.valueOf(((TagLong) tag).getLongData());
        case List:
            TagList TagList = (TagList) tag;
            ListTag tagList = new ListTag();
            for (TagBase tagInList : TagList.getReadOnlyList()) {
                tagList.add(compoundToVanillaCompound(tagInList));
            }
            return tagList;
        case Compound:
            TagCompound TagCompound = (TagCompound) tag;
            CompoundTag tagCompound = new CompoundTag();
            for (String name : TagCompound.getCompoundData().keySet()) {
                tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name)));
            }
            return tagCompound;
        case End:
            return null;
    }
    throw new IllegalArgumentException("Not a valid tag type");
}
Also used : IntArrayTag(net.minecraft.nbt.IntArrayTag) TagBase(de.keyle.knbt.TagBase) TagList(de.keyle.knbt.TagList) TagString(de.keyle.knbt.TagString) ListTag(net.minecraft.nbt.ListTag) TagCompound(de.keyle.knbt.TagCompound) CompoundTag(net.minecraft.nbt.CompoundTag) ByteArrayTag(net.minecraft.nbt.ByteArrayTag)

Example 27 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.

the class ItemStackNBTConverter method vanillaCompoundToCompound.

public static TagBase vanillaCompoundToCompound(Tag vanillaTag) {
    switch(vanillaTag.getId()) {
        case 1:
            return new TagByte(((ByteTag) vanillaTag).getAsByte());
        case 2:
            return new TagShort(((ShortTag) vanillaTag).getAsShort());
        case 3:
            return new TagInt(((IntTag) vanillaTag).getAsInt());
        case 4:
            return new TagLong(((LongTag) vanillaTag).getAsLong());
        case 5:
            return new TagFloat(((FloatTag) vanillaTag).getAsFloat());
        case 6:
            return new TagDouble(((DoubleTag) vanillaTag).getAsDouble());
        case 7:
            return new TagByteArray(((ByteArrayTag) vanillaTag).getAsByteArray());
        case 8:
            return new TagString(vanillaTag.getAsString());
        case 9:
            ListTag tagList = (ListTag) vanillaTag;
            List compoundList = new ArrayList();
            try {
                ArrayList list = (ArrayList) TAG_LIST_LIST.get(tagList);
                for (Object aList : list) {
                    compoundList.add(vanillaCompoundToCompound((Tag) aList));
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            return new TagList(compoundList);
        case 10:
            TagCompound compound = new TagCompound();
            CompoundTag tagCompound = ((CompoundTag) vanillaTag);
            Set<String> keys = tagCompound.getAllKeys();
            for (String tagName : keys) {
                compound.getCompoundData().put(tagName, vanillaCompoundToCompound(tagCompound.get(tagName)));
            }
            return compound;
        case 11:
            return new TagIntArray(((IntArrayTag) vanillaTag).getAsIntArray());
    }
    return null;
}
Also used : TagIntArray(de.keyle.knbt.TagIntArray) TagShort(de.keyle.knbt.TagShort) TagInt(de.keyle.knbt.TagInt) ArrayList(java.util.ArrayList) TagString(de.keyle.knbt.TagString) TagString(de.keyle.knbt.TagString) TagFloat(de.keyle.knbt.TagFloat) ListTag(net.minecraft.nbt.ListTag) TagCompound(de.keyle.knbt.TagCompound) TagDouble(de.keyle.knbt.TagDouble) TagByteArray(de.keyle.knbt.TagByteArray) TagLong(de.keyle.knbt.TagLong) TagList(de.keyle.knbt.TagList) ArrayList(java.util.ArrayList) TagList(de.keyle.knbt.TagList) List(java.util.List) DoubleTag(net.minecraft.nbt.DoubleTag) Tag(net.minecraft.nbt.Tag) StringTag(net.minecraft.nbt.StringTag) ByteTag(net.minecraft.nbt.ByteTag) IntTag(net.minecraft.nbt.IntTag) IntArrayTag(net.minecraft.nbt.IntArrayTag) FloatTag(net.minecraft.nbt.FloatTag) ByteArrayTag(net.minecraft.nbt.ByteArrayTag) LongTag(net.minecraft.nbt.LongTag) ShortTag(net.minecraft.nbt.ShortTag) CompoundTag(net.minecraft.nbt.CompoundTag) ListTag(net.minecraft.nbt.ListTag) TagByte(de.keyle.knbt.TagByte) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 28 with CompoundTag

use of net.minecraft.nbt.CompoundTag 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 MyGoat) {
        if (((MyGoat) myPet).isScreaming()) {
            ((Goat) normalEntity).setScreaming(true);
        }
    } else if (myPet instanceof MyEnderman) {
        if (((MyEnderman) myPet).hasBlock()) {
            ((Enderman) normalEntity).setCarriedMaterial(((MyEnderman) myPet).getBlock().getData());
        }
    } else if (myPet instanceof MyIronGolem) {
        ((IronGolem) normalEntity).setPlayerCreated(true);
    } else if (myPet instanceof MyMagmaCube) {
        ((MagmaCube) normalEntity).setSize(((MyMagmaCube) myPet).getSize());
    } 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 villagerEntity = ((Villager) normalEntity);
        Villager.Profession profession = Villager.Profession.values()[villagerPet.getProfession()];
        Villager.Type type = Villager.Type.values()[villagerPet.getType().ordinal()];
        villagerEntity.setVillagerType(type);
        villagerEntity.setProfession(profession);
        villagerEntity.setVillagerLevel(villagerPet.getVillagerLevel());
        if (villagerPet.hasOriginalData()) {
            TagCompound villagerTag = villagerPet.getOriginalData();
            net.minecraft.world.entity.npc.Villager entityVillager = ((CraftVillager) villagerEntity).getHandle();
            try {
                if (villagerTag.containsKey("Offers")) {
                    TagCompound offersTag = villagerTag.get("Offers");
                    CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(offersTag);
                    entityVillager.setOffers(new MerchantOffers(vanillaNBT));
                }
                if (villagerTag.containsKey("Inventory")) {
                    TagList inventoryTag = villagerTag.get("Inventory");
                    ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
                    for (int i = 0; i < vanillaNBT.size(); ++i) {
                        net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.of(vanillaNBT.getCompound(i));
                        ItemStack item = CraftItemStack.asCraftMirror(itemstack);
                        if (!itemstack.isEmpty()) {
                            Villager vill = ((Villager) Bukkit.getServer().getEntity(normalEntity.getUniqueId()));
                            vill.getInventory().addItem(item);
                        }
                    }
                }
                if (villagerTag.containsKey("FoodLevel")) {
                    byte foodLevel = villagerTag.getAs("FoodLevel", TagByte.class).getByteData();
                    // Field: foodLevel
                    ReflectionUtil.setFieldValue("cq", entityVillager, foodLevel);
                }
                if (villagerTag.containsKey("Gossips")) {
                    TagList inventoryTag = villagerTag.get("Gossips");
                    ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
                    // This might be useful for later/following versions
                    // ((GossipContainer) ReflectionUtil.getFieldValue(net.minecraft.world.entity.npc.Villager.class, entityVillager, "cr")) //Field: gossips
                    entityVillager.getGossips().update(new Dynamic<>(NbtOps.INSTANCE, vanillaNBT));
                }
                if (villagerTag.containsKey("LastRestock")) {
                    long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData();
                    // Field: lastRestockGameTime
                    ReflectionUtil.setFieldValue("cv", entityVillager, lastRestock);
                }
                if (villagerTag.containsKey("LastGossipDecay")) {
                    long lastGossipDecay = villagerTag.getAs("LastGossipDecay", TagLong.class).getLongData();
                    // Field: lastGossipDecayTime
                    ReflectionUtil.setFieldValue("ct", entityVillager, lastGossipDecay);
                }
                if (villagerTag.containsKey("RestocksToday")) {
                    int restocksToday = villagerTag.getAs("RestocksToday", TagInt.class).getIntData();
                    // Field: numberOfRestocksToday
                    ReflectionUtil.setFieldValue("cw", entityVillager, restocksToday);
                }
                // Field: AssignProfessionWhenSpawned
                ReflectionUtil.setFieldValue("cy", entityVillager, true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (villagerTag.containsKey("Xp")) {
                int xp = villagerTag.getAs("Xp", TagInt.class).getIntData();
                entityVillager.setVillagerXp(xp);
            }
        }
    } else if (myPet instanceof MySlime) {
        ((Slime) normalEntity).setSize(((MySlime) myPet).getSize());
    } else if (myPet instanceof MyZombieVillager) {
        Villager.Profession profession = Villager.Profession.values()[((MyZombieVillager) myPet).getProfession()];
        net.minecraft.world.entity.monster.ZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle();
        nmsEntity.setVillagerData(nmsEntity.getVillagerData().setType(Registry.VILLAGER_TYPE.get(new ResourceLocation(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))).setLevel(((MyZombieVillager) myPet).getTradingLevel()).setProfession(Registry.VILLAGER_PROFESSION.get(new ResourceLocation(profession.name().toLowerCase(Locale.ROOT)))));
    } else if (myPet instanceof MyWitherSkeleton) {
        normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD));
    } else if (myPet instanceof MySkeleton) {
        normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
    } else if (myPet instanceof MyHorse) {
        Horse.Style style = Horse.Style.values()[(((MyHorse) myPet).getVariant() >>> 8)];
        Horse.Color color = Horse.Color.values()[(((MyHorse) myPet).getVariant() & 0xFF)];
        ((Horse) normalEntity).setColor(color);
        ((Horse) normalEntity).setStyle(style);
        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 MySkeletonHorse) {
        ((SkeletonHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyZombieHorse) {
        ((ZombieHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyLlama) {
        ((Llama) normalEntity).setColor(Llama.Color.values()[Math.max(0, Math.min(3, ((MyLlama) myPet).getVariant()))]);
        ((Llama) normalEntity).setCarryingChest(((MyLlama) myPet).hasChest());
        if (((MyLlama) myPet).hasDecor()) {
            ((Llama) normalEntity).getInventory().setDecor(((MyLlama) myPet).getDecor());
        }
        ((Llama) normalEntity).setOwner(myPet.getOwner().getPlayer());
    } else if (myPet instanceof MyRabbit) {
        ((Rabbit) normalEntity).setRabbitType(((MyRabbit) myPet).getVariant().getBukkitType());
    } else if (myPet instanceof MyParrot) {
        ((Parrot) normalEntity).setVariant(Parrot.Variant.values()[((MyParrot) myPet).getVariant()]);
    } else if (myPet instanceof MyAxolotl) {
        ((Axolotl) normalEntity).setVariant(Axolotl.Variant.values()[((MyAxolotl) myPet).getVariant()]);
    } else if (myPet instanceof MyTropicalFish) {
        ((CraftTropicalFish) normalEntity).getHandle().setVariant(((MyTropicalFish) myPet).getVariant());
    } else if (myPet instanceof MyPufferfish) {
        ((PufferFish) normalEntity).setPuffState(((MyPufferfish) myPet).getPuffState().ordinal());
    } else if (myPet instanceof MyPhantom) {
        ((Phantom) normalEntity).setSize(((MyPhantom) myPet).getSize());
    } else if (myPet instanceof MyCat) {
        ((Cat) normalEntity).setCatType(((MyCat) myPet).getCatType());
        ((Cat) normalEntity).setCollarColor(((MyCat) myPet).getCollarColor());
    } else if (myPet instanceof MyMooshroom) {
        ((MushroomCow) normalEntity).setVariant(MushroomCow.Variant.values()[((MyMooshroom) myPet).getType().ordinal()]);
    } else if (myPet instanceof MyPanda) {
        ((Panda) normalEntity).setMainGene(((MyPanda) myPet).getMainGene());
        ((Panda) normalEntity).setHiddenGene(((MyPanda) myPet).getHiddenGene());
    } else if (myPet instanceof WanderingTrader) {
        MyWanderingTrader traderPet = (MyWanderingTrader) myPet;
        if (traderPet.hasOriginalData()) {
            TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(normalEntity);
            for (String key : traderPet.getOriginalData().getCompoundData().keySet()) {
                villagerTag.put(key, traderPet.getOriginalData().get(key));
            }
            MyPetApi.getPlatformHelper().applyTagToEntity(villagerTag, normalEntity);
        }
    } else if (myPet instanceof MyBee) {
        ((Bee) normalEntity).setHasNectar(((MyBee) myPet).hasNectar());
        ((Bee) normalEntity).setHasStung(((MyBee) myPet).hasStung());
    }
    if (myPet instanceof MyPetBaby && normalEntity instanceof Ageable) {
        if (((MyPetBaby) myPet).isBaby()) {
            ((Ageable) normalEntity).setBaby();
        } else {
            ((Ageable) normalEntity).setAdult();
        }
    }
}
Also used : MyZombieHorse(de.Keyle.MyPet.api.entity.types.MyZombieHorse) MyTropicalFish(de.Keyle.MyPet.api.entity.types.MyTropicalFish) MyWitherSkeleton(de.Keyle.MyPet.api.entity.types.MyWitherSkeleton) MyEnderman(de.Keyle.MyPet.api.entity.types.MyEnderman) MyCreeper(de.Keyle.MyPet.api.entity.types.MyCreeper) CraftTropicalFish(org.bukkit.craftbukkit.v1_18_R1.entity.CraftTropicalFish) MyMagmaCube(de.Keyle.MyPet.api.entity.types.MyMagmaCube) MySheep(de.Keyle.MyPet.api.entity.types.MySheep) MyWanderingTrader(de.Keyle.MyPet.api.entity.types.MyWanderingTrader) MyHorse(de.Keyle.MyPet.api.entity.types.MyHorse) AbstractHorse(org.bukkit.entity.AbstractHorse) MyHorse(de.Keyle.MyPet.api.entity.types.MyHorse) ChestedHorse(org.bukkit.entity.ChestedHorse) Horse(org.bukkit.entity.Horse) MySkeletonHorse(de.Keyle.MyPet.api.entity.types.MySkeletonHorse) ZombieHorse(org.bukkit.entity.ZombieHorse) MyZombieHorse(de.Keyle.MyPet.api.entity.types.MyZombieHorse) SkeletonHorse(org.bukkit.entity.SkeletonHorse) MyZombieVillager(de.Keyle.MyPet.api.entity.types.MyZombieVillager) MyVillager(de.Keyle.MyPet.api.entity.types.MyVillager) ZombieVillager(org.bukkit.entity.ZombieVillager) Villager(org.bukkit.entity.Villager) CraftVillager(org.bukkit.craftbukkit.v1_18_R1.entity.CraftVillager) WanderingTrader(org.bukkit.entity.WanderingTrader) MyWanderingTrader(de.Keyle.MyPet.api.entity.types.MyWanderingTrader) MyParrot(de.Keyle.MyPet.api.entity.types.MyParrot) MySkeleton(de.Keyle.MyPet.api.entity.types.MySkeleton) MyCat(de.Keyle.MyPet.api.entity.types.MyCat) MyPanda(de.Keyle.MyPet.api.entity.types.MyPanda) MySlime(de.Keyle.MyPet.api.entity.types.MySlime) MySkeletonHorse(de.Keyle.MyPet.api.entity.types.MySkeletonHorse) MyMooshroom(de.Keyle.MyPet.api.entity.types.MyMooshroom) Panda(org.bukkit.entity.Panda) MyPanda(de.Keyle.MyPet.api.entity.types.MyPanda) ZombieHorse(org.bukkit.entity.ZombieHorse) MyZombieHorse(de.Keyle.MyPet.api.entity.types.MyZombieHorse) MyPufferfish(de.Keyle.MyPet.api.entity.types.MyPufferfish) Enderman(org.bukkit.entity.Enderman) MyEnderman(de.Keyle.MyPet.api.entity.types.MyEnderman) MyGoat(de.Keyle.MyPet.api.entity.types.MyGoat) MyIronGolem(de.Keyle.MyPet.api.entity.types.MyIronGolem) Cat(org.bukkit.entity.Cat) MyCat(de.Keyle.MyPet.api.entity.types.MyCat) MyZombieVillager(de.Keyle.MyPet.api.entity.types.MyZombieVillager) ZombieVillager(org.bukkit.entity.ZombieVillager) MyAxolotl(de.Keyle.MyPet.api.entity.types.MyAxolotl) Axolotl(org.bukkit.entity.Axolotl) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Dynamic(com.mojang.serialization.Dynamic) MyCreeper(de.Keyle.MyPet.api.entity.types.MyCreeper) Creeper(org.bukkit.entity.Creeper) MyRabbit(de.Keyle.MyPet.api.entity.types.MyRabbit) Rabbit(org.bukkit.entity.Rabbit) Ageable(org.bukkit.entity.Ageable) TagCompound(de.keyle.knbt.TagCompound) MyLlama(de.Keyle.MyPet.api.entity.types.MyLlama) MyZombieVillager(de.Keyle.MyPet.api.entity.types.MyZombieVillager) MyPig(de.Keyle.MyPet.api.entity.types.MyPig) ResourceLocation(net.minecraft.resources.ResourceLocation) TagList(de.keyle.knbt.TagList) MyPhantom(de.Keyle.MyPet.api.entity.types.MyPhantom) MagmaCube(org.bukkit.entity.MagmaCube) MyMagmaCube(de.Keyle.MyPet.api.entity.types.MyMagmaCube) CompoundTag(net.minecraft.nbt.CompoundTag) MyVillager(de.Keyle.MyPet.api.entity.types.MyVillager) MyBee(de.Keyle.MyPet.api.entity.types.MyBee) MyBee(de.Keyle.MyPet.api.entity.types.MyBee) Bee(org.bukkit.entity.Bee) PufferFish(org.bukkit.entity.PufferFish) MyAxolotl(de.Keyle.MyPet.api.entity.types.MyAxolotl) Slime(org.bukkit.entity.Slime) MySlime(de.Keyle.MyPet.api.entity.types.MySlime) ListTag(net.minecraft.nbt.ListTag) MyLlama(de.Keyle.MyPet.api.entity.types.MyLlama) Llama(org.bukkit.entity.Llama) MerchantOffers(net.minecraft.world.item.trading.MerchantOffers) MyRabbit(de.Keyle.MyPet.api.entity.types.MyRabbit) MyPetBaby(de.Keyle.MyPet.api.entity.MyPetBaby) MySheep(de.Keyle.MyPet.api.entity.types.MySheep) Sheep(org.bukkit.entity.Sheep)

Example 29 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    // TODO Check if this works properly
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount()));
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.STONE));
    }
    if (is.getTag() == null) {
        is.setTag(new CompoundTag());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // add enchantment glowing
    if (icon.isGlowing()) {
        TagCompound enchTag = new TagCompound();
        enchTag.put("id", new TagString("minecraft:feather_falling"));
        enchTag.put("lvl", new TagShort(1));
        TagList enchList = new TagList();
        enchList.addTag(enchTag);
        is.getTag().put("Enchantments", ItemStackNBTConverter.compoundToVanillaCompound(enchList));
    } else {
        is.getTag().remove("Enchantments");
    }
    // hide item attributes like attack damage
    is.getTag().putInt("HideFlags", 63);
    // Prepare display tag
    CompoundTag display;
    if (is.getTag().contains("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new CompoundTag();
        is.getTag().put("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.putString("Name", "{\"text\":\"" + icon.getTitle() + "\"}");
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        ListTag loreTag = new ListTag();
        display.put("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            Component cm = CraftChatMessage.fromStringOrNull(loreLine);
            loreTag.add(StringTag.valueOf(Component.Serializer.toJson(cm)));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        CompoundTag vanillaTag = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.getAllKeys()) {
            is.getTag().put(key, vanillaTag.get(key));
        }
    }
    if (icon.getTags() != null) {
        CompoundTag vanillaTag = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
        for (String key : vanillaTag.getAllKeys()) {
            is.getTag().put(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : TagShort(de.keyle.knbt.TagShort) TagString(de.keyle.knbt.TagString) TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound) ListTag(net.minecraft.nbt.ListTag) InvocationTargetException(java.lang.reflect.InvocationTargetException) TagList(de.keyle.knbt.TagList) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 30 with CompoundTag

use of net.minecraft.nbt.CompoundTag in project MyPet by xXKeyleXx.

the class PlatformHelper method entityToTag.

@Override
public TagCompound entityToTag(Entity bukkitEntity) {
    net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    CompoundTag vanillaNBT = new CompoundTag();
    if (entity instanceof net.minecraft.world.entity.LivingEntity) {
        ((net.minecraft.world.entity.LivingEntity) entity).addAdditionalSaveData(vanillaNBT);
    } else {
        Method b = ReflectionUtil.getMethod(entity.getClass(), "b", CompoundTag.class);
        try {
            b.invoke(entity, vanillaNBT);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return (TagCompound) ItemStackNBTConverter.vanillaCompoundToCompound(vanillaNBT);
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Method(java.lang.reflect.Method) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) CraftLivingEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity) org.bukkit.entity(org.bukkit.entity) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

CompoundTag (net.minecraft.nbt.CompoundTag)31 ListTag (net.minecraft.nbt.ListTag)14 TagCompound (de.keyle.knbt.TagCompound)12 TagList (de.keyle.knbt.TagList)8 TagString (de.keyle.knbt.TagString)6 TagShort (de.keyle.knbt.TagShort)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ByteArrayTag (net.minecraft.nbt.ByteArrayTag)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 ItemStack (org.bukkit.inventory.ItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)3 Dynamic (com.mojang.serialization.Dynamic)2 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)2 MyAxolotl (de.Keyle.MyPet.api.entity.types.MyAxolotl)2 MyBee (de.Keyle.MyPet.api.entity.types.MyBee)2 MyCat (de.Keyle.MyPet.api.entity.types.MyCat)2 MyCreeper (de.Keyle.MyPet.api.entity.types.MyCreeper)2 MyEnderman (de.Keyle.MyPet.api.entity.types.MyEnderman)2 MyGoat (de.Keyle.MyPet.api.entity.types.MyGoat)2 MyHorse (de.Keyle.MyPet.api.entity.types.MyHorse)2