Search in sources :

Example 51 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class ArmorStandStore method save.

@Override
public void save(GlowArmorStand entity, CompoundTag tag) {
    super.save(entity, tag);
    tag.putCompoundList("Equipment", Arrays.asList(NbtSerialization.writeItem(entity.getItemInHand(), -1), NbtSerialization.writeItem(entity.getBoots(), -1), NbtSerialization.writeItem(entity.getLeggings(), -1), NbtSerialization.writeItem(entity.getChestplate(), -1), NbtSerialization.writeItem(entity.getHelmet(), -1)));
    tag.putBool("Marker", entity.isMarker());
    tag.putBool("Invisible", !entity.isVisible());
    tag.putBool("NoBasePlate", !entity.hasBasePlate());
    tag.putBool("NoGravity", !entity.hasGravity());
    tag.putBool("ShowArms", entity.hasArms());
    tag.putBool("Small", entity.isSmall());
    CompoundTag pose = new CompoundTag();
    pose.putList("Body", TagType.FLOAT, toFloatList(entity.getBodyPose()));
    pose.putList("LeftArm", TagType.FLOAT, toFloatList(entity.getLeftArmPose()));
    pose.putList("RightArm", TagType.FLOAT, toFloatList(entity.getRightArmPose()));
    pose.putList("LeftLeg", TagType.FLOAT, toFloatList(entity.getLeftLegPose()));
    pose.putList("RightLeg", TagType.FLOAT, toFloatList(entity.getRightLegPose()));
    pose.putList("Head", TagType.FLOAT, toFloatList(entity.getHeadPose()));
    tag.putCompound("Pose", pose);
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 52 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class StructureStore method load.

/**
     * Load structure data of the appropriate type from the given compound tag.
     *
     * @param structure The target structure.
     * @param compound  The structure's tag.
     */
public void load(T structure, CompoundTag compound) {
    if (compound.isIntArray("BB")) {
        int[] bb = compound.getIntArray("BB");
        if (bb.length == 6) {
            StructureBoundingBox boundingBox = new StructureBoundingBox(new Vector(bb[0], bb[1], bb[2]), new Vector(bb[3], bb[4], bb[5]));
            structure.setBoundingBox(boundingBox);
        }
    }
    if (compound.isList("Children", TagType.COMPOUND)) {
        for (CompoundTag tag : compound.getCompoundList("Children")) {
            structure.addPiece(StructurePieceStorage.loadStructurePiece(tag));
        }
    }
}
Also used : StructureBoundingBox(net.glowstone.generator.structures.util.StructureBoundingBox) Vector(org.bukkit.util.Vector) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 53 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class AnvilChunkIoService method write.

/**
     * Writes a chunk to its region file.
     *
     * @param chunk The {@link GlowChunk} to write from.
     * @throws IOException if an I/O error occurs.
     */
@Override
public void write(GlowChunk chunk) throws IOException {
    int x = chunk.getX(), z = chunk.getZ();
    RegionFile region = cache.getRegionFile(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);
        sec.optimize();
        sec.writeToNBT(sectionTag);
        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);
    // block entities
    List<CompoundTag> blockEntities = new ArrayList<>();
    for (BlockEntity entity : chunk.getRawBlockEntities()) {
        try {
            CompoundTag tag = new CompoundTag();
            entity.saveNbt(tag);
            blockEntities.add(tag);
        } catch (Exception ex) {
            GlowServer.logger.log(Level.SEVERE, "Error saving block entity at " + entity.getBlock(), ex);
        }
    }
    levelTags.putCompoundList("TileEntities", blockEntities);
    List<CompoundTag> tileTicks = new ArrayList<>();
    for (Location location : chunk.getWorld().getTickMap()) {
        if (location.getChunk().getX() == chunk.getX() && location.getChunk().getZ() == chunk.getZ()) {
            int tileX = location.getBlockX();
            int tileY = location.getBlockY();
            int tileZ = location.getBlockZ();
            String type = location.getBlock().getType().name().toLowerCase();
            if (type.startsWith("stationary_")) {
                type = type.replace("stationary_", "");
            } else if (type.equals("water") || type.equals("lava")) {
                type = "flowing_" + type;
            }
            CompoundTag tag = new CompoundTag();
            tag.putInt("x", tileX);
            tag.putInt("y", tileY);
            tag.putInt("z", tileZ);
            tag.putString("i", "minecraft:" + type);
            tileTicks.add(tag);
        }
    }
    levelTags.putCompoundList("TileTicks", tileTicks);
    CompoundTag levelOut = new CompoundTag();
    levelOut.putCompound("Level", levelTags);
    try (NBTOutputStream nbt = new NBTOutputStream(region.getChunkDataOutputStream(regionX, regionZ), false)) {
        nbt.writeTag(levelOut);
    }
}
Also used : ArrayList(java.util.ArrayList) NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream) IOException(java.io.IOException) GlowEntity(net.glowstone.entity.GlowEntity) ChunkSection(net.glowstone.chunk.ChunkSection) CompoundTag(net.glowstone.util.nbt.CompoundTag) GlowChunkSnapshot(net.glowstone.chunk.GlowChunkSnapshot) BlockEntity(net.glowstone.block.entity.BlockEntity) Location(org.bukkit.Location)

Example 54 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class NbtScoreboardIoReader method registerDisplaySlots.

private static void registerDisplaySlots(CompoundTag root, GlowScoreboard scoreboard) {
    if (root.containsKey("DisplaySlots")) {
        CompoundTag data = root.getCompound("DisplaySlots");
        String list = getOrNull("slot_0", data);
        String sidebar = getOrNull("slot_1", data);
        String belowName = getOrNull("slot_2", data);
        if (list != null) {
            scoreboard.getObjective(list).setDisplaySlot(DisplaySlot.PLAYER_LIST);
        }
        if (sidebar != null) {
            scoreboard.getObjective(sidebar).setDisplaySlot(DisplaySlot.SIDEBAR);
        }
        if (belowName != null) {
            scoreboard.getObjective(belowName).setDisplaySlot(DisplaySlot.BELOW_NAME);
        }
    /* TODO: anything need to be done with team slots?
            String teamBlack = getOrNull("slot_3", data);
            String teamDarkBlue = getOrNull("slot_4", data);
            String teamDarkGreen = getOrNull("slot_5", data);
            String teamDarkAqua = getOrNull("slot_6", data);
            String teamDarkRed = getOrNull("slot_7", data);
            String teamDarkPurple = getOrNull("slot_8", data);
            String teamGold = getOrNull("slot_9", data);
            String teamGray = getOrNull("slot_10", data);
            String teamDarkGray = getOrNull("slot_11", data);
            String teamBlue = getOrNull("slot_12", data);
            String teamGreen = getOrNull("slot_13", data);
            String teamAqua = getOrNull("slot_14", data);
            String teamRed = getOrNull("slot_15", data);
            String teamLightPurple = getOrNull("slot_16", data);
            String teamYellow = getOrNull("slot_17", data);
            String teamWhite = getOrNull("slot_18", data);
            */
    }
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 55 with CompoundTag

use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.

the class NbtScoreboardIoReader method readMainScoreboard.

public static GlowScoreboard readMainScoreboard(File path) throws IOException {
    CompoundTag root;
    try (NBTInputStream nbt = new NBTInputStream(getDataInputStream(path), true)) {
        root = nbt.readCompound().getCompound("data");
    }
    GlowScoreboard scoreboard = new GlowScoreboard();
    registerObjectives(root, scoreboard);
    registerScores(root, scoreboard);
    registerTeams(root, scoreboard);
    registerDisplaySlots(root, scoreboard);
    return scoreboard;
}
Also used : NBTInputStream(net.glowstone.util.nbt.NBTInputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

CompoundTag (net.glowstone.util.nbt.CompoundTag)58 ArrayList (java.util.ArrayList)9 NBTInputStream (net.glowstone.util.nbt.NBTInputStream)7 Location (org.bukkit.Location)7 IOException (java.io.IOException)6 NBTOutputStream (net.glowstone.util.nbt.NBTOutputStream)5 File (java.io.File)4 FileInputStream (java.io.FileInputStream)3 BlockEntity (net.glowstone.block.entity.BlockEntity)3 GlowEntity (net.glowstone.entity.GlowEntity)3 ByteBuf (io.netty.buffer.ByteBuf)2 FileOutputStream (java.io.FileOutputStream)2 UUID (java.util.UUID)2 ChunkSection (net.glowstone.chunk.ChunkSection)2 AttributeManager (net.glowstone.entity.AttributeManager)2 Modifier (net.glowstone.entity.AttributeManager.Modifier)2 GlowStructure (net.glowstone.generator.structures.GlowStructure)2 StructureBoundingBox (net.glowstone.generator.structures.util.StructureBoundingBox)2 MojangsonParseException (net.glowstone.util.mojangson.ex.MojangsonParseException)2 Material (org.bukkit.Material)2