Package net.glowstone.util.nbt

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


            buf.writeShort(stack.getTypeId());
            buf.writeByte(stack.getAmount());
            buf.writeShort(stack.getDurability());

            if (stack.hasItemMeta()) {
                CompoundTag tag = GlowItemFactory.instance().writeNbt(stack.getItemMeta());
                writeCompound(buf, tag);
            } else {
                writeCompound(buf, null);
            }
        }
View Full Code Here

            return false;
        }

        DataInputStream in = region.getChunkDataInputStream(regionX, regionZ);

        CompoundTag levelTag;
        try (NBTInputStream nbt = new NBTInputStream(in, false)) {
            CompoundTag root = nbt.readCompound();
            levelTag = root.getCompound("Level");
        }

        // read the vertical sections
        List<CompoundTag> sectionList = levelTag.getCompoundList("Sections");
        ChunkSection[] sections = new ChunkSection[16];
View Full Code Here

        int x = chunk.getX(), z = chunk.getZ();
        RegionFile region = cache.getRegionFile(dir, x, z);
        int regionX = x & (REGION_SIZE - 1);
        int regionZ = z & (REGION_SIZE - 1);

        CompoundTag levelTags = new CompoundTag();

        // core properties
        levelTags.putInt("xPos", chunk.getX());
        levelTags.putInt("zPos", chunk.getZ());
        levelTags.putBool("TerrainPopulated", chunk.isPopulated());
        levelTags.putLong("LastUpdate", 0);

        // chunk sections
        List<CompoundTag> sectionTags = new ArrayList<>();
        GlowChunkSnapshot snapshot = chunk.getChunkSnapshot(true, true, false);
        ChunkSection[] sections = snapshot.getRawSections();
        for (byte i = 0; i < sections.length; ++i) {
            ChunkSection sec = sections[i];
            if (sec == null) continue;

            CompoundTag sectionTag = new CompoundTag();
            sectionTag.putByte("Y", i);

            byte[] rawTypes = new byte[sec.types.length];
            NibbleArray extTypes = null;
            NibbleArray data = new NibbleArray(sec.types.length);
            for (int j = 0; j < sec.types.length; j++) {
                rawTypes[j] = (byte) ((sec.types[j] >> 4) & 0xFF);
                byte extType = (byte) (sec.types[j] >> 12);
                if (extType > 0) {
                    if (extTypes == null) {
                        extTypes = new NibbleArray(sec.types.length);
                    }
                    extTypes.set(j, extType);
                }
                data.set(j, (byte) (sec.types[j] & 0xF));
            }
            sectionTag.putByteArray("Blocks", rawTypes);
            if (extTypes != null) {
                sectionTag.putByteArray("Add", extTypes.getRawData());
            }
            sectionTag.putByteArray("Data", data.getRawData());
            sectionTag.putByteArray("BlockLight", sec.blockLight.getRawData());
            sectionTag.putByteArray("SkyLight", sec.skyLight.getRawData());

            sectionTags.add(sectionTag);
        }
        levelTags.putCompoundList("Sections", sectionTags);

        // height map and biomes
        levelTags.putIntArray("HeightMap", snapshot.getRawHeightmap());
        levelTags.putByteArray("Biomes", snapshot.getRawBiomes());

        // entities
        List<CompoundTag> entities = new ArrayList<>();
        for (GlowEntity entity : chunk.getRawEntities()) {
            if (!entity.shouldSave()) {
                continue;
            }
            try {
                CompoundTag tag = new CompoundTag();
                EntityStorage.save(entity, tag);
                entities.add(tag);
            } catch (Exception e) {
                GlowServer.logger.log(Level.WARNING, "Error saving " + entity + " in " + chunk, e);
            }
        }
        levelTags.putCompoundList("Entities", entities);

        // tile entities
        List<CompoundTag> tileEntities = new ArrayList<>();
        for (TileEntity entity : chunk.getRawTileEntities()) {
            try {
                CompoundTag tag = new CompoundTag();
                entity.saveNbt(tag);
                tileEntities.add(tag);
            } catch (Exception ex) {
                GlowServer.logger.log(Level.SEVERE, "Error saving tile entity at " + entity.getBlock(), ex);
            }
        }
        levelTags.putCompoundList("TileEntities", tileEntities);

        CompoundTag levelOut = new CompoundTag();
        levelOut.putCompound("Level", levelTags);

        try (NBTOutputStream nbt = new NBTOutputStream(region.getChunkDataOutputStream(regionX, regionZ), false)) {
            nbt.writeTag(levelOut);
        }
    }
View Full Code Here

            entity.setBedSpawnLocation(new Location(entity.getWorld(), x, y, z));
        }

        // abilities
        if (tag.isCompound("abilities")) {
            CompoundTag abilities = tag.getCompound("abilities");
            if (abilities.isFloat("walkSpeed")) {
                entity.setWalkSpeed(abilities.getFloat("walkSpeed") * 2f);
            }
            if (abilities.isFloat("flySpeed")) {
                entity.setFlySpeed(abilities.getFloat("flySpeed") * 2f);
            }
            if (abilities.isByte("mayfly")) {
                entity.setAllowFlight(abilities.getBool("mayfly"));
            }
            if (abilities.isByte("flying")) {
                entity.setFlying(abilities.getBool("flying"));
            }
        }

        // bukkit
        // cannot read firstPlayed, lastPlayed, or lastKnownName
View Full Code Here

            tag.putInt("SpawnY", bed.getBlockY());
            tag.putInt("SpawnZ", bed.getBlockZ());
        }

        // abilities
        CompoundTag abilities = new CompoundTag();
        abilities.putFloat("walkSpeed", entity.getWalkSpeed() / 2f);
        abilities.putFloat("flySpeed", entity.getFlySpeed() / 2f);
        abilities.putBool("mayfly", entity.getAllowFlight());
        abilities.putBool("flying", entity.isFlying());
        // for now, base these on the game mode value
        abilities.putBool("invulnerable", entity.getGameMode() == GameMode.CREATIVE);
        abilities.putBool("mayBuild", entity.getGameMode() != GameMode.ADVENTURE);
        abilities.putBool("instabuild", entity.getGameMode() == GameMode.CREATIVE);
        tag.putCompound("abilities", abilities);

        // bukkit
        CompoundTag bukkit = new CompoundTag();
        bukkit.putLong("firstPlayed", entity.getFirstPlayed() == 0 ? entity.getJoinTime() : entity.getFirstPlayed());
        bukkit.putLong("lastPlayed", entity.getJoinTime());
        bukkit.putString("lastKnownName", entity.getName());
        tag.putCompound("bukkit", bukkit);
    }
View Full Code Here

        tag.putShort("Health", (int) entity.getHealth());
        tag.putShort("AttackTime", entity.getNoDamageTicks());

        List<CompoundTag> effects = new LinkedList<>();
        for (PotionEffect effect : entity.getActivePotionEffects()) {
            CompoundTag effectTag = new CompoundTag();
            effectTag.putByte("Id", effect.getType().getId());
            effectTag.putByte("Amplifier", effect.getAmplifier());
            effectTag.putInt("Duration", effect.getDuration());
            effectTag.putBool("Ambient", effect.isAmbient());
            effectTag.putBool("ShowParticles", true);
            effects.add(effectTag);
        }
        tag.putCompoundList("ActiveEffects", effects);

        EntityEquipment equip = entity.getEquipment();
View Full Code Here

public final class UpdateEntityNBTCodec implements Codec<UpdateEntityNBTMessage> {

    @Override
    public UpdateEntityNBTMessage decode(ByteBuf buffer) throws IOException {
        int entityId = ByteBufUtils.readVarInt(buffer);
        CompoundTag tag = GlowBufUtils.readCompound(buffer);
        return new UpdateEntityNBTMessage(entityId, tag);
    }
View Full Code Here

    @Override
    public UpdateBlockEntityMessage decode(ByteBuf buffer) throws IOException {
        BlockVector pos = GlowBufUtils.readBlockPosition(buffer);
        int action = buffer.readByte();
        CompoundTag nbt = GlowBufUtils.readCompound(buffer);
        return new UpdateBlockEntityMessage(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), action, nbt);
    }
View Full Code Here

            out.writeLong(uuid.getMostSignificantBits());
            out.writeLong(uuid.getLeastSignificantBits());
        }

        // start with unknown tags from reading
        CompoundTag out = new CompoundTag();
        if (unknownTags != null) {
            out.getValue().putAll(unknownTags.getValue());
        }

        // Seed and core information
        out.putString("LevelName", world.getName());
        out.putInt("version", 19133);
        out.putLong("LastPlayed", Calendar.getInstance().getTimeInMillis());
        out.putLong("RandomSeed", world.getSeed());

        // Normal level data
        out.putLong("Time", world.getFullTime());
        out.putLong("DayTime", world.getTime());
        out.putBool("thundering", world.isThundering());
        out.putBool("raining", world.hasStorm());
        out.putInt("thunderTime", world.getThunderDuration());
        out.putInt("rainTime", world.getWeatherDuration());

        // Spawn location
        Location loc = world.getSpawnLocation();
        out.putInt("SpawnX", loc.getBlockX());
        out.putInt("SpawnY", loc.getBlockY());
        out.putInt("SpawnZ", loc.getBlockZ());

        // Game rules
        CompoundTag gameRules = new CompoundTag();
        String[] gameRuleKeys = world.getGameRules();
        for (String key : gameRuleKeys) {
            gameRules.putString(key, world.getGameRuleValue(key));
        }
        out.putCompound("GameRules", gameRules);

        // Not sure how to calculate this, so ignoring for now
        out.putLong("SizeOnDisk", 0);

        CompoundTag root = new CompoundTag();
        root.putCompound("Data", out);
        try (NBTOutputStream nbtOut = new NBTOutputStream(new FileOutputStream(new File(dir, "level.dat")))) {
            nbtOut.writeTag(root);
        } catch (IOException e) {
            handleWorldException("level.dat", e);
        }
View Full Code Here

TOP

Related Classes of net.glowstone.util.nbt.CompoundTag

Copyright © 2018 www.massapicom. 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.