Search in sources :

Example 76 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project dynmap by webbukkit.

the class MapChunkCache116_3 method loadChunk.

// Load generic chunk from unloaded chunk
protected GenericChunk loadChunk(DynmapChunk chunk) {
    CraftWorld cw = (CraftWorld) w;
    NBTTagCompound nbt = null;
    ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
    GenericChunk gc = null;
    try {
        nbt = cw.getHandle().getChunkProvider().playerChunkMap.read(cc);
    } catch (IOException iox) {
    }
    if (nbt != null) {
        gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
    }
    return gc;
}
Also used : ChunkCoordIntPair(net.minecraft.server.v1_16_R2.ChunkCoordIntPair) GenericChunk(org.dynmap.common.chunk.GenericChunk) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) IOException(java.io.IOException) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld)

Example 77 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project dynmap by webbukkit.

the class MapChunkCache116 method loadChunk.

// Load generic chunk from unloaded chunk
protected GenericChunk loadChunk(DynmapChunk chunk) {
    CraftWorld cw = (CraftWorld) w;
    NBTTagCompound nbt = null;
    ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
    GenericChunk gc = null;
    try {
        nbt = cw.getHandle().getChunkProvider().playerChunkMap.read(cc);
    } catch (IOException iox) {
    }
    if (nbt != null) {
        gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
    }
    return gc;
}
Also used : ChunkCoordIntPair(net.minecraft.server.v1_16_R1.ChunkCoordIntPair) GenericChunk(org.dynmap.common.chunk.GenericChunk) NBTTagCompound(net.minecraft.server.v1_16_R1.NBTTagCompound) IOException(java.io.IOException) CraftWorld(org.bukkit.craftbukkit.v1_16_R1.CraftWorld)

Example 78 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project dynmap by webbukkit.

the class MapChunkCache114_1 method loadChunk.

// Load generic chunk from unloaded chunk
protected GenericChunk loadChunk(DynmapChunk chunk) {
    CraftWorld cw = (CraftWorld) w;
    NBTTagCompound nbt = null;
    ChunkCoordIntPair cc = new ChunkCoordIntPair(chunk.x, chunk.z);
    GenericChunk gc = null;
    try {
        nbt = cw.getHandle().getChunkProvider().playerChunkMap.read(cc);
    } catch (IOException iox) {
    }
    if (nbt != null) {
        gc = parseChunkFromNBT(new NBT.NBTCompound(nbt));
    }
    return gc;
}
Also used : ChunkCoordIntPair(net.minecraft.server.v1_14_R1.ChunkCoordIntPair) GenericChunk(org.dynmap.common.chunk.GenericChunk) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound) IOException(java.io.IOException) CraftWorld(org.bukkit.craftbukkit.v1_14_R1.CraftWorld)

Example 79 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project MechanicsMain by WeaponMechanics.

the class NBT_1_10_R1 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_10_R1.NBTBase) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound)

Example 80 with NBTTagCompound

use of net.minecraft.server.v1_14_R1.NBTTagCompound in project MechanicsMain by WeaponMechanics.

the class NBT_1_10_R1 method setAttribute.

@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
    net.minecraft.server.v1_10_R1.ItemStack nmsItem = getNMSStack(bukkitItem);
    if (nmsItem.getTag() == null) {
        nmsItem.setTag(new NBTTagCompound());
    }
    NBTTagCompound compound = nmsItem.getTag();
    if (compound.hasKey("AttributeModifiers")) {
        NBTTagList list = (NBTTagList) compound.get("AttributeModifiers");
        // NBT lists don't have an indexOf method, so we need to loop
        // through each attribute, and determine if it is one we want to
        // modify. We want to modify an attribute if the attribute was
        // set using MechanicsCore, and it's attribute type matches the
        // parameter attribute type.
        boolean isModifiedAttribute = false;
        for (int i = 0; i < list.size(); i++) {
            // 10 is the id for nbt lists
            if (list.get(i).getTypeId() != 10) {
                continue;
            }
            NBTTagCompound nbt = list.get(i);
            String name = nbt.getString("Name");
            String attributeName = nbt.getString("AttributeName");
            // There is no offhand, or slot argument in 1_8_8.
            if (!"MechanicsCoreAttribute".equals(name) || !attribute.getMinecraftName().equals(attributeName)) {
                continue;
            }
            // Since this attribute already exists, we only need to modify
            // the existing value. No need to set the name/uuid
            nbt.setDouble("Amount", value);
            isModifiedAttribute = true;
            break;
        }
        if (!isModifiedAttribute) {
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setString("AttributeName", attribute.getMinecraftName());
            nbt.setString("Name", "MechanicsCoreAttribute");
            nbt.setDouble("Amount", value);
            // 0 == add
            nbt.setInt("Operation", 0);
            nbt.setLong("UUIDLeast", attribute.getUUID().getLeastSignificantBits());
            nbt.setLong("UUIDMost", attribute.getUUID().getMostSignificantBits());
            if (slot != null) {
                nbt.setString("Slot", slot.getSlotName());
            }
        }
    }
    bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem));
}
Also used : NBTTagList(net.minecraft.server.v1_10_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) Nonnull(javax.annotation.Nonnull)

Aggregations

NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)69 ItemStack (org.bukkit.inventory.ItemStack)60 Map (java.util.Map)41 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)39 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)38 ArrayList (java.util.ArrayList)37 ItemMeta (org.bukkit.inventory.meta.ItemMeta)35 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)33 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)30 ListTag (com.wasteofplastic.org.jnbt.ListTag)30 StringTag (com.wasteofplastic.org.jnbt.StringTag)30 Tag (com.wasteofplastic.org.jnbt.Tag)30 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)24 Nullable (javax.annotation.Nullable)21 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)21 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)20 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)20 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)20 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)19 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)18