Search in sources :

Example 11 with NBTBase

use of net.minecraft.server.v1_16_R3.NBTBase in project MechanicsMain by WeaponMechanics.

the class NBT_1_9_R2 method visit.

private StringBuilder visit(NBTTagCompound nbt, int indents, int colorOffset) {
    String braceColor = "&" + BRACE_COLORS.charAt(indents % BRACE_COLORS.length());
    StringBuilder builder = new StringBuilder(braceColor).append('{');
    List<String> keys = new ArrayList<>(nbt.c());
    Collections.sort(keys);
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        NBTBase value = Objects.requireNonNull(nbt.get(key), "This is impossible");
        if (i != 0)
            builder.append('\n');
        builder.append(StringUtil.repeat("  ", indents));
        String color = "&" + VALUE_COLORS.charAt((i + colorOffset) % VALUE_COLORS.length());
        builder.append(color).append(key).append("&f&l: ").append(color);
        if (value instanceof NBTTagCompound)
            builder.append(visit((NBTTagCompound) value, indents + 1, colorOffset + i));
        else
            builder.append(value);
    }
    return builder.append(braceColor).append("}\n");
}
Also used : NBTBase(net.minecraft.server.v1_9_R2.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound)

Example 12 with NBTBase

use of net.minecraft.server.v1_16_R3.NBTBase in project PaperDev by Kamillaova.

the class CraftMetaItem method serialize.

@Overridden
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
    if (hasDisplayName()) {
        builder.put(NAME.BUKKIT, displayName);
    }
    if (hasLocalizedName()) {
        builder.put(LOCNAME.BUKKIT, locName);
    }
    if (hasLore()) {
        builder.put(LORE.BUKKIT, ImmutableList.copyOf(lore));
    }
    serializeEnchantments(enchantments, builder, ENCHANTMENTS);
    if (hasRepairCost()) {
        builder.put(REPAIR.BUKKIT, repairCost);
    }
    List<String> hideFlags = new ArrayList<String>();
    for (ItemFlag hideFlagEnum : getItemFlags()) {
        hideFlags.add(hideFlagEnum.name());
    }
    if (!hideFlags.isEmpty()) {
        builder.put(HIDEFLAGS.BUKKIT, hideFlags);
    }
    if (isUnbreakable()) {
        builder.put(UNBREAKABLE.BUKKIT, unbreakable);
    }
    final Map<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags);
    serializeInternal(internalTags);
    if (!internalTags.isEmpty()) {
        NBTTagCompound internal = new NBTTagCompound();
        for (Map.Entry<String, NBTBase> e : internalTags.entrySet()) {
            internal.set(e.getKey(), e.getValue());
        }
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            NBTCompressedStreamTools.a(internal, buf);
            builder.put("internal", Base64.encodeBase64String(buf.toByteArray()));
        } catch (IOException ex) {
            Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return builder;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NBTBase(net.minecraft.server.v1_12_R1.NBTBase) ItemFlag(org.bukkit.inventory.ItemFlag) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap) Overridden(org.bukkit.craftbukkit.v1_12_R1.Overridden)

Aggregations

ArrayList (java.util.ArrayList)11 NBTBase (net.minecraft.server.v1_12_R1.NBTBase)2 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)2 NBTBase (net.minecraft.server.v1_16_R3.NBTBase)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 NBTBase (net.minecraft.server.v1_10_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_11_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)1 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)1 NBTBase (net.minecraft.server.v1_13_R2.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_13_R2.NBTTagCompound)1 NBTBase (net.minecraft.server.v1_14_R1.NBTBase)1 NBTTagCompound (net.minecraft.server.v1_14_R1.NBTTagCompound)1