use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class NbtWorldMetadataService method readWorldData.
@Override
public WorldFinalValues readWorldData() {
// determine UUID of world
UUID uid = null;
File uuidFile = new File(dir, "uid.dat");
if (uuidFile.exists()) {
try (DataInputStream in = new DataInputStream(new FileInputStream(uuidFile))) {
uid = new UUID(in.readLong(), in.readLong());
} catch (IOException e) {
handleWorldException("uid.dat", e);
}
}
if (uid == null) {
uid = UUID.randomUUID();
}
// read in world information
CompoundTag level = new CompoundTag();
File levelFile = new File(dir, "level.dat");
if (levelFile.exists()) {
try (NBTInputStream in = new NBTInputStream(new FileInputStream(levelFile))) {
level = in.readCompound();
if (level.isCompound("Data")) {
level = level.getCompound("Data");
} else {
server.getLogger().warning("Loading world \"" + world.getName() + "\": reading from root, not Data");
}
} catch (IOException e) {
handleWorldException("level.dat", e);
}
}
// seed
long seed = 0L;
if (level.isLong("RandomSeed")) {
seed = level.getLong("RandomSeed");
level.remove("RandomSeed");
}
// time of day and weather status
if (level.isByte("thundering")) {
world.setThundering(level.getBool("thundering"));
level.remove("thundering");
}
if (level.isByte("raining")) {
world.setStorm(level.getBool("raining"));
level.remove("raining");
}
if (level.isInt("thunderTime")) {
world.setThunderDuration(level.getInt("thunderTime"));
level.remove("thunderTime");
}
if (level.isInt("rainTime")) {
world.setWeatherDuration(level.getInt("rainTime"));
level.remove("rainTime");
}
if (level.isLong("Time")) {
world.setFullTime(level.getLong("Time"));
level.remove("Time");
}
if (level.isLong("DayTime")) {
world.setTime(level.getLong("DayTime"));
level.remove("DayTime");
}
if (level.isString("generatorName")) {
world.setWorldType(WorldType.getByName(level.getString("generatorName")));
level.remove("generatorName");
}
// spawn position
if (level.isInt("SpawnX") && level.isInt("SpawnY") && level.isInt("SpawnZ")) {
world.setSpawnLocation(level.getInt("SpawnX"), level.getInt("SpawnY"), level.getInt("SpawnZ"));
level.remove("SpawnX");
level.remove("SpawnY");
level.remove("SpawnZ");
}
// game rules
if (level.isCompound("GameRules")) {
CompoundTag gameRules = level.getCompound("GameRules");
gameRules.getValue().keySet().stream().filter(gameRules::isString).forEach(key -> world.setGameRuleValue(key, gameRules.getString(key)));
level.remove("GameRules");
}
// world border
Location borderCenter = new Location(world, 0, 0, 0);
if (level.isDouble("BorderCenterX")) {
borderCenter.setX(level.getDouble("BorderCenterX"));
level.remove("BorderCenterX");
}
if (level.isDouble("BorderCenterZ")) {
borderCenter.setZ(level.getDouble("BorderCenterZ"));
level.remove("BorderCenterZ");
}
world.getWorldBorder().setCenter(borderCenter);
if (level.isDouble("BorderSize")) {
world.getWorldBorder().setSize(level.getDouble("BorderSize"));
level.remove("BorderSize");
}
if (level.isDouble("BorderSizeLerpTarget") && level.isLong("BorderSizeLerpTime")) {
world.getWorldBorder().setSize(level.getDouble("BorderSizeLerpTarget"), level.getLong("BorderSizeLerpTime"));
level.remove("BorderSizeLerpTarget");
level.remove("BorderSizeLerpTime");
}
if (level.isDouble("BorderSafeZone")) {
world.getWorldBorder().setDamageBuffer(level.getDouble("BorderSafeZone"));
level.remove("BorderSafeZone");
}
if (level.isDouble("BorderWarningTime")) {
world.getWorldBorder().setWarningTime((int) level.getDouble("BorderWarningTime"));
level.remove("BorderWarningTime");
}
if (level.isDouble("BorderWarningBlocks")) {
world.getWorldBorder().setWarningDistance((int) level.getDouble("BorderWarningBlocks"));
level.remove("BorderWarningBlocks");
}
if (level.isDouble("BorderDamagePerBlock")) {
world.getWorldBorder().setDamageAmount(level.getDouble("BorderDamagePerBlock"));
level.remove("BorderDamagePerBlock");
}
// strip single-player Player tag if it exists
if (level.isCompound("Player")) {
server.getLogger().warning("World \"" + world.getName() + "\": removing single-player Player tag");
level.remove("Player");
}
// save unknown tags for later
unknownTags = level;
return new WorldFinalValues(seed, uid);
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class StructureStore method save.
/**
* Save information about this structure to the given tag.
*
* @param structure The structure to save.
* @param compound The target tag.
*/
public void save(T structure, CompoundTag compound) {
StructureBoundingBox boundingBox = structure.getBoundingBox();
int[] bb = new int[6];
bb[0] = boundingBox.getMin().getBlockX();
bb[1] = boundingBox.getMin().getBlockY();
bb[2] = boundingBox.getMin().getBlockZ();
bb[3] = boundingBox.getMax().getBlockX();
bb[4] = boundingBox.getMax().getBlockY();
bb[5] = boundingBox.getMax().getBlockZ();
compound.putIntArray("BB", bb);
List<CompoundTag> children = new ArrayList<>();
for (GlowStructurePiece piece : structure.getPieces()) {
CompoundTag tag = new CompoundTag();
StructurePieceStorage.saveStructurePiece(piece, tag);
children.add(tag);
}
compound.putCompoundList("Children", children);
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class GlowBufUtils method readSlot.
/**
* Read an item stack from the buffer.
*
* @param buf The buffer.
* @param network Mark network source.
* @return The stack read, or null.
*/
public static ItemStack readSlot(ByteBuf buf, boolean network) {
short type = buf.readShort();
if (type == -1) {
return InventoryUtil.createEmptyStack();
}
int amount = buf.readUnsignedByte();
short durability = buf.readShort();
Material material = Material.getMaterial(type);
if (material == null) {
return InventoryUtil.createEmptyStack();
}
CompoundTag tag = readCompound(buf, network);
ItemStack stack = new ItemStack(material, amount, durability);
stack.setItemMeta(GlowItemFactory.instance().readNbt(material, tag));
return stack;
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class GlowBufUtils method writeSlot.
/**
* Write an item stack to the buffer.
*
* @param buf The buffer.
* @param stack The stack to write, or null.
*/
public static void writeSlot(ByteBuf buf, ItemStack stack) {
if (InventoryUtil.isEmpty(stack)) {
buf.writeShort(-1);
} else {
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);
}
}
}
use of net.glowstone.util.nbt.CompoundTag in project Glowstone by GlowstoneMC.
the class HumanEntityStore method load.
// documented at http://minecraft.gamepedia.com/Player.dat_Format
// player data that does not correspond to HumanEntity is in PlayerStore
@Override
public void load(T entity, CompoundTag tag) {
super.load(entity, tag);
if (tag.isInt("XpSeed")) {
entity.setXpSeed(tag.getInt("XpSeed"));
}
if (tag.isInt("playerGameType")) {
GlowServer server = (GlowServer) Bukkit.getServer();
if (!server.getConfig().getBoolean(ServerConfig.Key.FORCE_GAMEMODE)) {
GameMode mode = GameMode.getByValue(tag.getInt("playerGameType"));
if (mode != null) {
entity.setGameMode(mode);
}
} else {
entity.setGameMode(server.getDefaultGameMode());
}
}
if (tag.isInt("SelectedItemSlot")) {
entity.getInventory().setHeldItemSlot(tag.getInt("SelectedItemSlot"));
}
if (tag.isList("Inventory", TagType.COMPOUND)) {
PlayerInventory inventory = entity.getInventory();
List<CompoundTag> items = tag.getCompoundList("Inventory");
inventory.setStorageContents(NbtSerialization.readInventory(items, 0, inventory.getSize() - 5));
inventory.setArmorContents(NbtSerialization.readInventory(items, 100, 4));
inventory.setExtraContents(NbtSerialization.readInventory(items, -106, 1));
}
if (tag.isList("EnderItems", TagType.COMPOUND)) {
Inventory inventory = entity.getEnderChest();
List<CompoundTag> items = tag.getCompoundList("EnderItems");
inventory.setContents(NbtSerialization.readInventory(items, 0, inventory.getSize()));
}
}
Aggregations