Examples of CompoundTag


Examples of com.sk89q.jnbt.CompoundTag

        nbtStream.close();
        if (!rootTag.getName().equals("Schematic")) {
            throw new DataException("Tag \"Schematic\" does not exist or is not first");
        }

        CompoundTag schematicTag = (CompoundTag) rootTag.getTag();

        // Check
        Map<String, Tag> schematic = schematicTag.getValue();
        if (!schematic.containsKey("Blocks")) {
            throw new DataException("Schematic file is missing a \"Blocks\" tag");
        }

        // Get information
        short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
        short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
        short height = getChildTag(schematic, "Height", ShortTag.class).getValue();

        try {
            int originX = getChildTag(schematic, "WEOriginX", IntTag.class).getValue();
            int originY = getChildTag(schematic, "WEOriginY", IntTag.class).getValue();
            int originZ = getChildTag(schematic, "WEOriginZ", IntTag.class).getValue();
            origin = new Vector(originX, originY, originZ);
        } catch (DataException e) {
            // No origin data
        }

        try {
            int offsetX = getChildTag(schematic, "WEOffsetX", IntTag.class).getValue();
            int offsetY = getChildTag(schematic, "WEOffsetY", IntTag.class).getValue();
            int offsetZ = getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue();
            offset = new Vector(offsetX, offsetY, offsetZ);
        } catch (DataException e) {
            // No offset data
        }

        // Check type of Schematic
        String materials = getChildTag(schematic, "Materials", StringTag.class).getValue();
        if (!materials.equals("Alpha")) {
            throw new DataException("Schematic file is not an Alpha schematic");
        }

        // Get blocks
        byte[] blockId = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
        byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
        byte[] addId = new byte[0];
        short[] blocks = new short[blockId.length]; // Have to later combine IDs

        // We support 4096 block IDs using the same method as vanilla Minecraft, where
        // the highest 4 bits are stored in a separate byte array.
        if (schematic.containsKey("AddBlocks")) {
            addId = getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
        }

        // Combine the AddBlocks data with the first 8-bit block ID
        for (int index = 0; index < blockId.length; index++) {
            if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index
                blocks[index] = (short) (blockId[index] & 0xFF);
            } else {
                if ((index & 1) == 0) {
                    blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
                } else {
                    blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
                }
            }
        }

        // Need to pull out tile entities
        List<Tag> tileEntities = getChildTag(schematic, "TileEntities", ListTag.class)
                .getValue();
        Map<BlockVector, Map<String, Tag>> tileEntitiesMap =
                new HashMap<BlockVector, Map<String, Tag>>();

        for (Tag tag : tileEntities) {
            if (!(tag instanceof CompoundTag)) continue;
            CompoundTag t = (CompoundTag) tag;

            int x = 0;
            int y = 0;
            int z = 0;

            Map<String, Tag> values = new HashMap<String, Tag>();

            for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) {
                if (entry.getKey().equals("x")) {
                    if (entry.getValue() instanceof IntTag) {
                        x = ((IntTag) entry.getValue()).getValue();
                    }
                } else if (entry.getKey().equals("y")) {
                    if (entry.getValue() instanceof IntTag) {
                        y = ((IntTag) entry.getValue()).getValue();
                    }
                } else if (entry.getKey().equals("z")) {
                    if (entry.getValue() instanceof IntTag) {
                        z = ((IntTag) entry.getValue()).getValue();
                    }
                }

                values.put(entry.getKey(), entry.getValue());
            }

            BlockVector vec = new BlockVector(x, y, z);
            tileEntitiesMap.put(vec, values);
        }

        Vector size = new Vector(width, height, length);
        CuboidClipboard clipboard = new CuboidClipboard(size);
        clipboard.setOrigin(origin);
        clipboard.setOffset(offset);

        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    int index = y * width * length + z * width + x;
                    BlockVector pt = new BlockVector(x, y, z);
                    BaseBlock block = getBlockForId(blocks[index], blockData[index]);

                    if (tileEntitiesMap.containsKey(pt)) {
                        block.setNbtData(new CompoundTag(tileEntitiesMap.get(pt)));
                    }
                    clipboard.setBlock(pt, block);
                }
            }
        }
View Full Code Here

Examples of com.sk89q.jnbt.CompoundTag

                    blocks[index] = (byte) block.getType();
                    blockData[index] = (byte) block.getData();

                    // Get the list of key/values from the block
                    CompoundTag rawTag = block.getNbtData();
                    if (rawTag != null) {
                        Map<String, Tag> values = new HashMap<String, Tag>();
                        for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
                            values.put(entry.getKey(), entry.getValue());
                        }

                        values.put("id", new StringTag(block.getNbtId()));
                        values.put("x", new IntTag(x));
                        values.put("y", new IntTag(y));
                        values.put("z", new IntTag(z));

                        CompoundTag tileEntityTag = new CompoundTag(values);
                        tileEntities.add(tileEntityTag);
                    }
                }
            }
        }

        schematic.put("Blocks", new ByteArrayTag(blocks));
        schematic.put("Data", new ByteArrayTag(blockData));
        schematic.put("Entities", new ListTag(CompoundTag.class, new ArrayList<Tag>()));
        schematic.put("TileEntities", new ListTag(CompoundTag.class, tileEntities));
        if (addBlocks != null) {
            schematic.put("AddBlocks", new ByteArrayTag(addBlocks));
        }

        // Build and output
        CompoundTag schematicTag = new CompoundTag(schematic);
        NBTOutputStream stream = new NBTOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
        stream.writeNamedTag("Schematic", schematicTag);
        stream.close();
    }
View Full Code Here

Examples of com.sk89q.jnbt.CompoundTag

        for (Tag rawSectionTag : sections) {
            if (!(rawSectionTag instanceof CompoundTag)) {
                continue;
            }
           
            CompoundTag sectionTag = (CompoundTag) rawSectionTag;
            if (!sectionTag.getValue().containsKey("Y")) {
                continue; // Empty section.
            }
           
            int y = NBTUtils.getChildTag(sectionTag.getValue(), "Y", ByteTag.class).getValue();
            if (y < 0 || y >= 16) {
                continue;
            }

            blocks[y] = NBTUtils.getChildTag(sectionTag.getValue(),
                    "Blocks", ByteArrayTag.class).getValue();
            data[y] = NBTUtils.getChildTag(sectionTag.getValue(), "Data",
                    ByteArrayTag.class).getValue();

            // 4096 ID block support
            if (sectionTag.getValue().containsKey("Add")) {
                blocksAdd[y] = NBTUtils.getChildTag(sectionTag.getValue(),
                        "Add", ByteArrayTag.class).getValue();
            }
        }

        int sectionsize = 16 * 16 * 16;
 
View Full Code Here

Examples of com.sk89q.jnbt.CompoundTag

            if (!(tag instanceof CompoundTag)) {
                throw new InvalidFormatException(
                        "CompoundTag expected in TileEntities");
            }

            CompoundTag t = (CompoundTag) tag;

            int x = 0;
            int y = 0;
            int z = 0;

            Map<String, Tag> values = new HashMap<String, Tag>();

            for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) {
                if (entry.getKey().equals("x")) {
                    if (entry.getValue() instanceof IntTag) {
                        x = ((IntTag) entry.getValue()).getValue();
                    }
                } else if (entry.getKey().equals("y")) {
View Full Code Here

Examples of com.sk89q.jnbt.CompoundTag

        Map<String, Tag> values = tileEntities.get(new BlockVector(position));
        if (values == null) {
            return null;
        }

        return new CompoundTag(values);
    }
View Full Code Here

Examples of com.sk89q.jnbt.CompoundTag

            block = new NoteBlock(data);
        } else {*/
            block = new BaseBlock(id, data);
        //}

        CompoundTag tileEntity = getBlockTileEntity(position);
        if (tileEntity != null) {
            ((TileEntityBlock) block).setNbtData(tileEntity);
        }

        return block;
View Full Code Here

Examples of net.canarymod.api.nbt.CompoundTag

            return null;
        }
        ListTag<CompoundTag> stored_enchantments = book.getDataTag().getListTag("StoredEnchantments");
        Enchantment[] enchantments = new Enchantment[stored_enchantments.size()];
        for (int index = 0; index < stored_enchantments.size(); index++) {
            CompoundTag stored_enchantment = stored_enchantments.get(index);
            enchantments[index] = Canary.factory().getItemFactory().newEnchantment(stored_enchantment.getShort("id"), stored_enchantment.getShort("lvl"));
        }
        return enchantments;
    }
View Full Code Here

Examples of net.glowstone.util.nbt.CompoundTag

        Material material = Material.getMaterial(type);
        if (material == null) {
            return null;
        }

        CompoundTag tag = readCompound(buf);
        ItemStack stack = new ItemStack(material, amount, durability);
        stack.setItemMeta(GlowItemFactory.instance().readNbt(material, tag));
        return stack;
    }
View Full Code Here

Examples of net.lightstone.util.nbt.CompoundTag

    DataInputStream in = region.getChunkDataInputStream(regionX, regionZ);
    Chunk chunk = new Chunk(x, z);

    NBTInputStream nbt = new NBTInputStream(in, false);
    CompoundTag tag = (CompoundTag) nbt.readTag();
    Map<String, Tag> levelTags = ((CompoundTag) tag.getValue().get("Level")).getValue();

    byte[] tileData = ((ByteArrayTag) levelTags.get("Blocks")).getValue();
    chunk.setTypes(tileData);

    byte[] skyLightData = ((ByteArrayTag) levelTags.get("SkyLight")).getValue();
View Full Code Here

Examples of net.lightstone.util.nbt.CompoundTag

   * Writes a chunk to a McRegion file.
   * WARNING! The files written by this method probably won't load in the Notchian server. Make backups.
   */
  @Override
  public void write(int x, int z, Chunk chunk) throws IOException {
    CompoundTag levelTag = chunkToTag(chunk);
    RegionFile region = cache.getRegionFile(dir, x, z);
    int regionX = x & (REGION_SIZE - 1);
    int regionZ = z & (REGION_SIZE - 1);

    DataOutputStream out = region.getChunkDataOutputStream(regionX, regionZ);
    try {
      NBTOutputStream nbtOut = new NBTOutputStream(out, false);

      Map<String, Tag> tagMap = new HashMap<String, Tag>(1);
      tagMap.put("Level", levelTag);

      CompoundTag tag = new CompoundTag("", tagMap);
      nbtOut.writeTag(tag);
    } finally {
      out.close();
    }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.