use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class NbtWorldMetadataService method writeWorldData.
@Override
public void writeWorldData() throws IOException {
File uuidFile = new File(dir, "uid.dat");
try (DataOutputStream out = new DataOutputStream(new FileOutputStream(uuidFile))) {
UUID uuid = world.getUID();
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());
out.putString("generatorName", world.getWorldType().getName().toLowerCase());
// Spawn location
Location loc = world.getSpawnLocation();
out.putInt("SpawnX", loc.getBlockX());
out.putInt("SpawnY", loc.getBlockY());
out.putInt("SpawnZ", loc.getBlockZ());
// World border
out.putDouble("BorderCenterX", world.getWorldBorder().getCenter().getX());
out.putDouble("BorderCenterZ", world.getWorldBorder().getCenter().getZ());
out.putDouble("BorderSize", world.getWorldBorder().getSize());
out.putDouble("BorderSizeLerpTarget", ((GlowWorldBorder) world.getWorldBorder()).futureSize);
out.putLong("BorderSizeLerpTime", ((GlowWorldBorder) world.getWorldBorder()).time);
out.putDouble("BorderSafeZone", world.getWorldBorder().getDamageBuffer());
out.putDouble("BorderWarningTime", world.getWorldBorder().getWarningTime());
out.putDouble("BorderWarningBlocks", world.getWorldBorder().getWarningDistance());
out.putDouble("BorderDamagePerBlock", world.getWorldBorder().getDamageAmount());
// 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);
}
}
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);
}
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));
}
}
}
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);
}
}
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);
*/
}
}
Aggregations