use of net.minecraft.nbt.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class ImprovedOfflinePlayerImpl method setInventory.
@Override
public void setInventory(org.bukkit.inventory.PlayerInventory inventory) {
CraftInventoryPlayer inv = (CraftInventoryPlayer) inventory;
net.minecraft.nbt.CompoundTag nbtTagCompound = ((CompoundTagImpl) compound).toNMSTag();
nbtTagCompound.put("Inventory", inv.getInventory().save(new ListTag()));
this.compound = CompoundTagImpl.fromNMSTag(nbtTagCompound);
if (this.autosave) {
savePlayerData();
}
}
use of net.minecraft.nbt.ListTag 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");
}
use of net.minecraft.nbt.ListTag 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;
}
use of net.minecraft.nbt.ListTag 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;
}
use of net.minecraft.nbt.ListTag in project SpongeCommon by SpongePowered.
the class BookItemStackData method set.
private static <V> boolean set(final ItemStack holder, final List<V> value, final Function<V, String> predicate) {
final ListTag list = value.stream().map(predicate).collect(NBTCollectors.toStringTagList());
holder.addTagElement(Constants.Item.Book.ITEM_BOOK_PAGES, list);
final CompoundTag compound = holder.getOrCreateTag();
if (!compound.contains(Constants.Item.Book.ITEM_BOOK_TITLE)) {
compound.putString(Constants.Item.Book.ITEM_BOOK_TITLE, Constants.Item.Book.INVALID_TITLE);
}
if (!compound.contains(Constants.Item.Book.ITEM_BOOK_AUTHOR)) {
compound.putString(Constants.Item.Book.ITEM_BOOK_AUTHOR, Constants.Item.Book.INVALID_TITLE);
}
compound.putBoolean(Constants.Item.Book.ITEM_BOOK_RESOLVED, true);
return false;
}
Aggregations