Examples of CompoundTag


Examples of com.iCo6.util.nbt.CompoundTag

    }

    private ItemStack[] readInventory(String name) {
        try {
            NBTInputStream in = new NBTInputStream(new FileInputStream(new File(dataDir, name + ".dat")));
            CompoundTag tag = (CompoundTag) in.readTag();
            in.close();

            ListTag inventory = (ListTag) tag.getValue().get("Inventory");

            ItemStack[] stacks = new ItemStack[40];
            for (int i = 0; i < inventory.getValue().size(); ++i) {
                CompoundTag item = (CompoundTag) inventory.getValue().get(i);
                byte count = ((ByteTag) item.getValue().get("Count")).getValue();
                byte slot = ((ByteTag) item.getValue().get("Slot")).getValue();
                short damage = ((ShortTag) item.getValue().get("Damage")).getValue();
                short id = ((ShortTag) item.getValue().get("id")).getValue();

                stacks[slot] = new ItemStack(id, count, damage);
            }
            return stacks;
        } catch (IOException ex) {
View Full Code Here

Examples of com.iCo6.util.nbt.CompoundTag

    }

    private void writeInventory(String name, ItemStack[] stacks) {
        try {
            NBTInputStream in = new NBTInputStream(new FileInputStream(new File(dataDir, name + ".dat")));
            CompoundTag tag = (CompoundTag) in.readTag();
            in.close();

            ArrayList tagList = new ArrayList<Tag>();

            for (int i = 0; i < stacks.length; ++i) {
                if (stacks[i] == null) continue;

                ByteTag count = new ByteTag("Count", (byte) stacks[i].getAmount());
                ByteTag slot = new ByteTag("Slot", (byte) i);
                ShortTag damage = new ShortTag("Damage", stacks[i].getDurability());
                ShortTag id = new ShortTag("id", (short) stacks[i].getTypeId());

                HashMap<String, Tag> tagMap = new HashMap<String, Tag>();
                tagMap.put("Count", count);
                tagMap.put("Slot", slot);
                tagMap.put("Damage", damage);
                tagMap.put("id", id);

                tagList.add(new CompoundTag("", tagMap));
            }

            ListTag inventory = new ListTag("Inventory", CompoundTag.class, tagList);

            HashMap<String, Tag> tagCompound = new HashMap<String, Tag>(tag.getValue());
            tagCompound.put("Inventory", inventory);
            tag = new CompoundTag("Player", tagCompound);

            NBTOutputStream out = new NBTOutputStream(new FileOutputStream(new File(dataDir, name + ".dat")));
            out.writeTag(tag);
            out.close();
        } catch (IOException ex) {
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

        if(dis == null)
            return null;

        // decompress chunk
        CompoundTag tag = NbtIo.read(dis);
        Chunk chunk = Chunk.loadChunk(tag);
        dis.close();
       
        return chunk;
    }
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

        if(dis == null)
            return null;

        // decompress chunk
        CompoundTag tag = NbtIo.read(dis);
        ManagedChunk chunk = ManagedChunk.loadChunk(tag, manager);
        dis.close();
       
        if(x != chunk.getX() || z != chunk.getZ())
            chunk.fixPosition(x, z);
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

    }
   
    @SuppressWarnings("unchecked")
    public static ManagedChunk loadChunk(CompoundTag tag, ChunkManager manager)
    {
        CompoundTag level = (CompoundTag) tag.get("Level");

        ListTag<CompoundTag> sections = (ListTag<CompoundTag>) level.get("Sections");
        IntArrayTag heightmap = (IntArrayTag) level.get("HeightMap");
        ByteArrayTag biome = (ByteArrayTag) level.get("Biomes");
        IntTag xPos = (IntTag) level.get("xPos");
        IntTag zPos = (IntTag) level.get("zPos");
       
        ManagedChunk chunk;
        chunk = new ManagedChunk(xPos.data, zPos.data, heightmap.data, biome.data, manager);
        // TODO: create ManagedSection to catch Section changes?
        // TODO: alternatively, hide sections from interface
        chunk.loadSections(sections);

        EntityFactory factory = manager.getEntityFactory();
       
        Tag tagEntities = level.get("Entities");  
        if(tagEntities != null)
        {
            ListTag<CompoundTag> list = (ListTag<CompoundTag>)tagEntities;           
            for(int i=0; i<list.size(); i++)
                chunk.entities.add(factory.createEntity(list.get(i)));
        }
       
        Tag tagTileEntities = level.get("TileEntities");
        if(tagEntities != null)
        {
            ListTag<CompoundTag> list = (ListTag<CompoundTag>)tagTileEntities;           
            for(int i=0; i<list.size(); i++)
                chunk.tileEntities.add(factory.createTileEntity(list.get(i)));
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

        this.x = x;
        this.z = z;
       
        if(this.tag != null)
        {
            CompoundTag level = this.tag.getCompound("Level");
           
            if(level != null)
            {
                level.put("xPos", new IntTag("xPos", x));
                level.put("zPos", new IntTag("zPos", z));
            }
        }
    }
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

        for(Section sec : sections)
            if(sec != null)
                list.add(sec.createTag());
       
        CompoundTag level = (CompoundTag)tag.get("Level");
        level.put("Sections", list);
       
        ListTag<CompoundTag> tagEntities = new ListTag<CompoundTag>("Entities");
        for(Entity e : entities)
            tagEntities.add(e.getTag());

        ListTag<CompoundTag> tagTileEntities = new ListTag<CompoundTag>("TileEntities");
        for(TileEntity e : tileEntities)
            tagTileEntities.add(e.getTag());
       
        level.put("Entities", tagEntities);
        level.put("TileEntities", tagTileEntities);

        return tag;
    }
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

        return tag;
    }
   
    private CompoundTag createChunkTag()
    {
        CompoundTag level = new CompoundTag("Level");
        level.put("Biomes", new ByteArrayTag("Biomes", biomes));
        level.put("HeightMap", new IntArrayTag("HeightMap", heightmap));
        level.put("LastUpdate", new LongTag("LastUpdate", 0));
        level.put("xPos", new IntTag("xPos", x));
        level.put("zPos", new IntTag("zPos", z));
        level.put("TerrainPopulated", new ByteTag("TerrainPopulated", (byte)1));

        CompoundTag root = new CompoundTag("");
        root.put("Level", level);
        return root;
    }
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

    }
   
    public CompoundTag getTag()
    {
        if(tag == null)
            tag = new CompoundTag("Schematic");

        ShortTag tagW = new ShortTag("Width", (short)width);
        ShortTag tagH = new ShortTag("Height", (short)height);
        ShortTag tagL = new ShortTag("Length", (short)length);
        StringTag tagMat = new StringTag("Materials", "Alpha");
View Full Code Here

Examples of com.mojang.nbt.CompoundTag

            return new TileEntityImpl(tag);
    }
   
    public EntityImpl createXPOrb(int x, int y, int z, int value)
    {
        CompoundTag root = createEntityRoot(x, y, z, "XPOrb");
        root.put("Health", new ShortTag("Health", (short)5));
        root.put("Age", new ShortTag("Age", (short)0));
        root.put("Value", new ShortTag("Value", (short)value));
        return new EntityImpl(root);
    }
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.