@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
1,199 lines • 58 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_SPAWN_COORD = exports.TOPMOST_BLOCK = exports.PlayerPermissionsLevel = exports.Difficulty = exports.Generator = exports.GameType = void 0;
const NbtBinary_1 = require("./NbtBinary");
const NbtBinaryTag_1 = require("./NbtBinaryTag");
const Log_1 = require("../core/Log");
const DataUtilities_1 = require("../core/DataUtilities");
const Utilities_1 = require("../core/Utilities");
var GameType;
(function (GameType) {
GameType[GameType["survival"] = 0] = "survival";
GameType[GameType["creative"] = 1] = "creative";
GameType[GameType["adventure"] = 2] = "adventure";
})(GameType = exports.GameType || (exports.GameType = {}));
var Generator;
(function (Generator) {
Generator[Generator["old"] = 0] = "old";
Generator[Generator["infinite"] = 1] = "infinite";
Generator[Generator["flat"] = 2] = "flat";
})(Generator = exports.Generator || (exports.Generator = {}));
var Difficulty;
(function (Difficulty) {
Difficulty[Difficulty["peaceful"] = 0] = "peaceful";
Difficulty[Difficulty["easy"] = 1] = "easy";
Difficulty[Difficulty["normal"] = 2] = "normal";
Difficulty[Difficulty["hard"] = 3] = "hard";
})(Difficulty = exports.Difficulty || (exports.Difficulty = {}));
var PlayerPermissionsLevel;
(function (PlayerPermissionsLevel) {
PlayerPermissionsLevel[PlayerPermissionsLevel["visitor"] = 0] = "visitor";
PlayerPermissionsLevel[PlayerPermissionsLevel["member"] = 1] = "member";
PlayerPermissionsLevel[PlayerPermissionsLevel["operator"] = 2] = "operator";
PlayerPermissionsLevel[PlayerPermissionsLevel["custom"] = 3] = "custom";
})(PlayerPermissionsLevel = exports.PlayerPermissionsLevel || (exports.PlayerPermissionsLevel = {}));
exports.TOPMOST_BLOCK = 32767;
exports.DEFAULT_SPAWN_COORD = -2147483648;
class WorldLevelDat {
createNbt() {
const nbt = new NbtBinary_1.default();
nbt.context = this.context;
return nbt;
}
_pushError(message, contextIn) {
this.isInErrorState = true;
if (this.errorMessages === undefined) {
this.errorMessages = [];
}
Log_1.default.error(message + (contextIn ? " " + contextIn : ""));
this.errorMessages.push({
message: message,
context: contextIn,
});
}
loadFromNbtBytes(bytes, context) {
this.isInErrorState = false;
this.errorMessages = undefined;
const tag = new NbtBinary_1.default();
tag.context = this.context;
const fileType = DataUtilities_1.default.getUnsignedInteger(bytes[0], bytes[1], bytes[2], bytes[3], true);
const restOfLength = DataUtilities_1.default.getUnsignedInteger(bytes[4], bytes[5], bytes[6], bytes[7], true);
if (fileType < 4 || fileType === 7 || fileType > 10) {
/* 10 has been recently observed? */
this._pushError("Unexpected world level dat type (" + fileType + ")", context);
return;
}
// some type 8 maps have restOfLength === bytes.length - 16 (?)
if (restOfLength !== bytes.length - 8 && restOfLength !== bytes.length - 16) {
this._pushError("Unexpected world level dat length.", context);
}
tag.fromBinary(bytes, true, false, 8);
this.nbt = tag;
this.loadFromNbt(tag);
Utilities_1.default.appendErrors(this, tag, context);
}
ensureNbt() {
if (this.nbt !== undefined) {
return;
}
const tag = new NbtBinary_1.default();
tag.context = this.context;
tag.ensureSingleRoot();
this.nbt = tag;
}
getBytes() {
this.ensureNbt();
if (this.nbt !== undefined) {
const bytes = this.nbt.toBinary();
if (bytes !== undefined) {
const fullBytes = new Uint8Array(bytes.length + 8);
for (let i = 0; i < bytes.length; i++) {
fullBytes[i + 8] = bytes[i];
}
DataUtilities_1.default.writeUnsignedInteger(fullBytes, 0, 10, true);
DataUtilities_1.default.writeUnsignedInteger(fullBytes, 4, bytes.length, true);
return fullBytes;
}
}
Log_1.default.fail("Could not create MC level bytes for updating.");
return undefined;
}
persist() {
this.ensureNbt();
if (this.nbt !== undefined) {
this._saveToNbt(this.nbt);
}
}
ensureDefaults() {
if (this.biomeOverride === undefined) {
this.biomeOverride = "";
}
if (this.centerMapsToOrigin === undefined) {
this.centerMapsToOrigin = false;
}
if (this.confirmedPlatformLockedContent === undefined) {
this.confirmedPlatformLockedContent = false;
}
if (this.savedWithToggledExperiments === undefined) {
this.savedWithToggledExperiments = false;
}
if (this.experimentsEverUsed === undefined) {
this.experimentsEverUsed = false;
}
if (this.difficulty === undefined) {
this.difficulty = Difficulty.easy;
}
if (this.forceGameType === undefined) {
this.forceGameType = false;
}
if (this.experimentsEverUsed === undefined) {
this.experimentsEverUsed = false;
}
if (this.savedWithToggledExperiments === undefined) {
this.savedWithToggledExperiments = false;
}
if (this.isCreatedInEditor === undefined) {
this.isCreatedInEditor = false;
}
if (this.isExportedFromEditor === undefined) {
this.isExportedFromEditor = false;
}
if (this.flatWorldLayers === undefined) {
this.flatWorldLayers = {
biome_id: 1,
block_layers: [
{ block_name: "minecraft:bedrock", count: 1 },
{ block_name: "minecraft:dirt", count: 2 },
{ block_name: "minecraft:grass", count: 1 },
],
encoding_version: 6,
structure_options: null,
world_version: "version.post_1_18",
};
}
if (this.forceGameType === undefined) {
this.forceGameType = false;
}
if (this.gameType === undefined) {
this.gameType = GameType.creative;
}
if (this.generator === undefined) {
this.generator = Generator.infinite;
}
if (this.inventoryVersion === undefined) {
this.inventoryVersion = "1.20.0";
}
if (this.lanBroadcast === undefined) {
this.lanBroadcast = true;
}
if (this.lanBroadcastIntent === undefined) {
this.lanBroadcastIntent = true;
}
if (this.lastPlayed === undefined) {
const newDate = new Date();
this.lastPlayed = BigInt(Math.floor(newDate.getTime() / 1000));
}
if (this.limitedWorldOriginX === undefined) {
this.limitedWorldOriginX = 0;
}
if (this.limitedWorldOriginY === undefined) {
this.limitedWorldOriginY = exports.TOPMOST_BLOCK;
}
if (this.limitedWorldOriginZ === undefined) {
this.limitedWorldOriginZ = 0;
}
if (this.minimumCompatibleClientVersion === undefined) {
this.minimumCompatibleClientVersion = [1, 20, 0, 0, 0];
}
if (this.multiplayerGame === undefined) {
this.multiplayerGame = true;
}
if (this.multiplayerGameIntent === undefined) {
this.multiplayerGameIntent = true;
}
if (this.netherScale === undefined) {
this.netherScale = 8;
}
if (this.networkVersion === undefined) {
this.networkVersion = 588;
}
if (this.platform === undefined) {
this.platform = 2;
}
if (this.platformBroadcastIntent === undefined) {
this.platformBroadcastIntent = 2;
}
if (this.randomSeed === undefined) {
this.randomSeed = "3025905974105939481";
}
if (this.spawnV1Villagers === undefined) {
this.spawnV1Villagers = false;
}
if (this.spawnX === undefined) {
this.spawnX = 0;
}
if (this.spawnY === undefined) {
this.spawnY = exports.TOPMOST_BLOCK;
}
if (this.spawnZ === undefined) {
this.spawnZ = 0;
}
if (this.storageVersion === undefined) {
this.storageVersion = 10;
}
if (this.time === undefined) {
this.time = BigInt(1);
}
if (this.worldVersion === undefined) {
this.worldVersion = 1;
}
if (this.xblBroadcastIntent === undefined) {
this.xblBroadcastIntent = 2;
}
if (this.baseGameVersion === undefined) {
this.baseGameVersion = "*";
}
if (this.bonusChestEnabled === undefined) {
this.bonusChestEnabled = false;
}
if (this.bonusChestSpawned === undefined) {
this.bonusChestSpawned = false;
}
if (this.commandBlockOutput === undefined) {
this.commandBlockOutput = true;
}
if (this.commandBlocksEnabled === undefined) {
this.commandBlocksEnabled = true;
}
if (this.commandsEnabled === undefined) {
this.commandsEnabled = true;
}
if (this.cheatsEnabled === undefined) {
this.cheatsEnabled = true;
}
if (this.currentTick === undefined) {
this.currentTick = BigInt(1);
}
if (this.doDaylightCycle === undefined) {
this.doDaylightCycle = true;
}
if (this.daylightCycle === undefined) {
this.daylightCycle = 0;
}
if (this.doEntityDrops === undefined) {
this.doEntityDrops = true;
}
if (this.doFireTick === undefined) {
this.doFireTick = true;
}
if (this.doImmediateRespawn === undefined) {
this.doImmediateRespawn = false;
}
if (this.doInsomnia === undefined) {
this.doInsomnia = true;
}
if (this.doMobLoot === undefined) {
this.doMobLoot = true;
}
if (this.doMobSpawning === undefined) {
this.doMobSpawning = true;
}
if (this.doTileDrops === undefined) {
this.doTileDrops = true;
}
if (this.doWeatherCycle === undefined) {
this.doWeatherCycle = true;
}
if (this.drowningDamage === undefined) {
this.drowningDamage = true;
}
if (this.eduOffer === undefined) {
this.eduOffer = 0;
}
if (this.educationFeaturesEnabled === undefined) {
this.educationFeaturesEnabled = false;
}
if (this.fallDamage === undefined) {
this.fallDamage = true;
}
if (this.fireDamage === undefined) {
this.fireDamage = true;
}
if (this.freezeDamage === undefined) {
this.freezeDamage = true;
}
if (this.functionCommandLimit === undefined) {
this.functionCommandLimit = 10000;
}
if (this.hasBeenLoadedInCreative === undefined) {
this.hasBeenLoadedInCreative = true;
}
if (this.hasLockedBehaviorPack === undefined) {
this.hasLockedBehaviorPack = false;
}
if (this.hasLockedResourcePack === undefined) {
this.hasLockedResourcePack = false;
}
if (this.immutableWorld === undefined) {
this.immutableWorld = false;
}
if (this.isFromLockedTemplate === undefined) {
this.isFromLockedTemplate = false;
}
if (this.isRandomSeedAllowed === undefined) {
this.isRandomSeedAllowed = false;
}
if (this.isFromWorldTemplate === undefined) {
this.isFromWorldTemplate = false;
}
if (this.isSingleUseWorld === undefined) {
this.isSingleUseWorld = false;
}
if (this.isWorldTemplateOptionLocked === undefined) {
this.isWorldTemplateOptionLocked = false;
}
if (this.keepInventory === undefined) {
this.keepInventory = false;
}
if (this.lastOpenedWithVersion === undefined) {
this.lastOpenedWithVersion = [1, 20, 0, 0, 1];
}
if (this.lightningTime === undefined) {
this.lightningTime = 124600;
}
if (this.lightningLevel === undefined) {
this.lightningLevel = 0;
}
if (this.limitedWorldDepth === undefined) {
this.limitedWorldDepth = 16;
}
if (this.limitedWorldWidth === undefined) {
this.limitedWorldWidth = 16;
}
if (this.maxCommandChainLength === undefined) {
this.maxCommandChainLength = 65535;
}
if (this.mobGriefing === undefined) {
this.mobGriefing = true;
}
if (this.naturalRegeneration === undefined) {
this.naturalRegeneration = true;
}
if (this.permissionsLevel === undefined) {
this.permissionsLevel = PlayerPermissionsLevel.visitor;
}
if (this.playerPermissionsLevel === undefined) {
this.playerPermissionsLevel = PlayerPermissionsLevel.member;
}
if (this.prid === undefined) {
this.prid = "";
}
if (this.pvp === undefined) {
this.pvp = true;
}
if (this.rainLevel === undefined) {
this.rainLevel = 0;
}
if (this.rainTime === undefined) {
this.rainTime = 94841;
}
if (this.randomTickSpeed === undefined) {
this.randomTickSpeed = 1;
}
if (this.requiresCopiedPackRemovalCheck === undefined) {
this.requiresCopiedPackRemovalCheck = false;
}
if (this.respawnBlocksExplode === undefined) {
this.respawnBlocksExplode = true;
}
if (this.sendCommandFeedback === undefined) {
this.sendCommandFeedback = true;
}
if (this.serverChunkTickRange === undefined) {
this.serverChunkTickRange = 4;
}
if (this.showBorderEffect === undefined) {
this.showBorderEffect = true;
}
if (this.showCoordinates === undefined) {
this.showCoordinates = false;
}
if (this.showDeathMessages === undefined) {
this.showDeathMessages = true;
}
if (this.showTags === undefined) {
this.showTags = true;
}
if (this.spawnMobs === undefined) {
this.spawnMobs = true;
}
if (this.spawnRadius === undefined) {
this.spawnRadius = 5;
}
if (this.startWithMapEnabled === undefined) {
this.startWithMapEnabled = false;
}
if (this.texturePacksRequired === undefined) {
this.texturePacksRequired = false;
}
if (this.tntExplodes === undefined) {
this.tntExplodes = true;
}
if (this.useMsaGamertagsOnly === undefined) {
this.useMsaGamertagsOnly = false;
}
if (this.worldStartCount === undefined) {
this.worldStartCount = BigInt(4294967294);
}
if (this.attackMobs === undefined) {
this.attackMobs = true;
}
if (this.attackPlayers === undefined) {
this.attackPlayers = true;
}
if (this.build === undefined) {
this.build = true;
}
if (this.doorsAndSwitches === undefined) {
this.doorsAndSwitches = true;
}
if (this.flySpeed === undefined) {
this.flySpeed = 0.5;
}
if (this.flying === undefined) {
this.flying = false;
}
if (this.instaBuild === undefined) {
this.instaBuild = false;
}
if (this.invulnerable === undefined) {
this.invulnerable = false;
}
if (this.lightning === undefined) {
this.lightning = false;
}
if (this.mayFly === undefined) {
this.mayFly = false;
}
if (this.mine === undefined) {
this.mine = true;
}
if (this.op === undefined) {
this.op = false;
}
if (this.openContainers === undefined) {
this.openContainers = true;
}
if (this.teleport === undefined) {
this.teleport = true;
}
if (this.walkSpeed === undefined) {
this.walkSpeed = 0.1;
}
}
applyFromWorldSettings(settings) {
if (settings.generator !== undefined) {
this.generator = settings.generator;
}
if (settings.gameType !== undefined) {
this.gameType = settings.gameType;
}
if (settings.difficulty !== undefined) {
this.difficulty = settings.difficulty;
}
if (settings.commandsEnabled !== undefined) {
this.commandsEnabled = settings.commandsEnabled;
}
if (settings.cheatsEnabled !== undefined) {
this.cheatsEnabled = settings.cheatsEnabled;
}
if (settings.randomSeed !== undefined) {
this.randomSeed = settings.randomSeed;
}
if (settings.name !== undefined) {
this.levelName = settings.name;
}
if (settings.lastPlayed !== undefined) {
this.lastPlayed = BigInt(settings.lastPlayed);
}
if (settings.isEditor) {
this.isCreatedInEditor = true;
this.editorWorldType = 1;
}
else if (settings.isEditor === false) {
this.isCreatedInEditor = false;
this.editorWorldType = undefined;
}
if (settings.betaApisExperiment === true) {
this.betaApisExperiment = settings.betaApisExperiment;
}
else if (settings.betaApisExperiment === false) {
this.betaApisExperiment = false;
}
if (settings.deferredTechnicalPreviewExperiment === true) {
this.deferredTechnicalPreviewExperiment = settings.deferredTechnicalPreviewExperiment;
}
else if (settings.deferredTechnicalPreviewExperiment === false) {
this.deferredTechnicalPreviewExperiment = false;
}
}
_saveToNbt(binary) {
const root = binary.ensureSingleRoot();
if (root == null) {
return;
}
if (this.biomeOverride !== undefined) {
root.ensureTag("BiomeOverride", NbtBinaryTag_1.NbtTagType.string).value = this.biomeOverride;
}
if (this.centerMapsToOrigin !== undefined) {
root.ensureTag("CenterMapsToOrigin", NbtBinaryTag_1.NbtTagType.byte).value = this.centerMapsToOrigin;
}
if (this.confirmedPlatformLockedContent !== undefined) {
root.ensureTag("ConfirmedPlatformLockedContent", NbtBinaryTag_1.NbtTagType.byte).value = this.confirmedPlatformLockedContent;
}
if (this.difficulty !== undefined) {
root.ensureTag("Difficulty", NbtBinaryTag_1.NbtTagType.int).value = this.difficulty;
}
if (this.flatWorldLayers !== undefined) {
root.ensureTag("FlatWorldLayers", NbtBinaryTag_1.NbtTagType.string).value = JSON.stringify(this.flatWorldLayers).trim();
}
if (this.forceGameType !== undefined) {
root.ensureTag("ForceGameType", NbtBinaryTag_1.NbtTagType.byte).value = this.forceGameType;
}
if (this.gameType !== undefined) {
root.ensureTag("GameType", NbtBinaryTag_1.NbtTagType.int).value = this.gameType;
}
if (this.generator !== undefined) {
root.ensureTag("Generator", NbtBinaryTag_1.NbtTagType.int).value = this.generator;
}
if (this.inventoryVersion !== undefined) {
root.ensureTag("InventoryVersion", NbtBinaryTag_1.NbtTagType.string).value = this.inventoryVersion;
}
if (this.lanBroadcast !== undefined) {
root.ensureTag("LANBroadcast", NbtBinaryTag_1.NbtTagType.byte).value = this.lanBroadcast;
}
if (this.lanBroadcastIntent !== undefined) {
root.ensureTag("LANBroadcastIntent", NbtBinaryTag_1.NbtTagType.byte).value = this.lanBroadcastIntent;
}
if (this.lastPlayed !== undefined) {
root.ensureTag("LastPlayed", NbtBinaryTag_1.NbtTagType.long).value = this.lastPlayed;
}
if (this.levelName !== undefined) {
root.ensureTag("LevelName", NbtBinaryTag_1.NbtTagType.string).value = this.levelName;
}
if (this.limitedWorldOriginX !== undefined) {
root.ensureTag("LimitedWorldOriginX", NbtBinaryTag_1.NbtTagType.int).value = this.limitedWorldOriginX;
}
if (this.limitedWorldOriginY !== undefined) {
root.ensureTag("LimitedWorldOriginY", NbtBinaryTag_1.NbtTagType.int).value = this.limitedWorldOriginY;
}
if (this.limitedWorldOriginZ !== undefined) {
root.ensureTag("LimitedWorldOriginZ", NbtBinaryTag_1.NbtTagType.int).value = this.limitedWorldOriginZ;
}
if (this.minimumCompatibleClientVersion && this.minimumCompatibleClientVersion.length > 0) {
const tag = root.ensureTag("MinimumCompatibleClientVersion", NbtBinaryTag_1.NbtTagType.list);
tag.setListFromArray(this.minimumCompatibleClientVersion);
}
if (this.multiplayerGame !== undefined) {
root.ensureTag("MultiplayerGame", NbtBinaryTag_1.NbtTagType.byte).value = this.multiplayerGame;
}
if (this.multiplayerGameIntent !== undefined) {
root.ensureTag("MultiplayerGameIntent", NbtBinaryTag_1.NbtTagType.byte).value = this.multiplayerGameIntent;
}
if (this.netherScale !== undefined) {
root.ensureTag("NetherScale", NbtBinaryTag_1.NbtTagType.int).value = this.netherScale;
}
if (this.networkVersion !== undefined) {
root.ensureTag("NetworkVersion", NbtBinaryTag_1.NbtTagType.int).value = this.networkVersion;
}
if (this.platform !== undefined) {
root.ensureTag("Platform", NbtBinaryTag_1.NbtTagType.int).value = this.platform;
}
if (this.platformBroadcastIntent !== undefined) {
root.ensureTag("PlatformBroadcastIntent", NbtBinaryTag_1.NbtTagType.int).value = this.platformBroadcastIntent;
}
if (this.randomSeed !== undefined) {
try {
const seedBig = BigInt(this.randomSeed);
root.ensureTag("RandomSeed", NbtBinaryTag_1.NbtTagType.long).value = seedBig;
}
catch (e) {
Log_1.default.debugAlert("Could not set seed: " + this.randomSeed);
}
}
if (this.spawnV1Villagers !== undefined) {
root.ensureTag("SpawnV1Villagers", NbtBinaryTag_1.NbtTagType.byte).value = this.spawnV1Villagers;
}
if (this.spawnX !== undefined) {
root.ensureTag("SpawnX", NbtBinaryTag_1.NbtTagType.int).value = this.spawnX;
}
if (this.spawnY !== undefined) {
root.ensureTag("SpawnY", NbtBinaryTag_1.NbtTagType.int).value = this.spawnY;
}
if (this.spawnZ !== undefined) {
root.ensureTag("SpawnZ", NbtBinaryTag_1.NbtTagType.int).value = this.spawnZ;
}
if (this.storageVersion !== undefined) {
root.ensureTag("StorageVersion", NbtBinaryTag_1.NbtTagType.int).value = this.storageVersion;
}
if (this.time !== undefined) {
root.ensureTag("Time", NbtBinaryTag_1.NbtTagType.long).value = this.time;
}
if (this.worldVersion !== undefined) {
root.ensureTag("WorldVersion", NbtBinaryTag_1.NbtTagType.int).value = this.worldVersion;
}
if (this.xblBroadcastIntent !== undefined) {
root.ensureTag("XBLBroadcastIntent", NbtBinaryTag_1.NbtTagType.int).value = this.xblBroadcastIntent;
}
const abilitiesTag = root.ensureTag("abilities", NbtBinaryTag_1.NbtTagType.compound);
if (this.attackMobs !== undefined) {
abilitiesTag.ensureTag("attackmobs", NbtBinaryTag_1.NbtTagType.byte).value = this.attackMobs;
}
if (this.attackPlayers !== undefined) {
abilitiesTag.ensureTag("attackplayers", NbtBinaryTag_1.NbtTagType.byte).value = this.attackPlayers;
}
if (this.build !== undefined) {
abilitiesTag.ensureTag("build", NbtBinaryTag_1.NbtTagType.byte).value = this.build;
}
if (this.doorsAndSwitches !== undefined) {
abilitiesTag.ensureTag("doorsandswitches", NbtBinaryTag_1.NbtTagType.byte).value = this.doorsAndSwitches;
}
if (this.flySpeed !== undefined) {
abilitiesTag.ensureTag("flySpeed", NbtBinaryTag_1.NbtTagType.float).value = this.flySpeed;
}
if (this.flying !== undefined) {
abilitiesTag.ensureTag("flying", NbtBinaryTag_1.NbtTagType.byte).value = this.flying;
}
if (this.instaBuild !== undefined) {
abilitiesTag.ensureTag("instabuild", NbtBinaryTag_1.NbtTagType.byte).value = this.instaBuild;
}
if (this.invulnerable !== undefined) {
abilitiesTag.ensureTag("invulnerable", NbtBinaryTag_1.NbtTagType.byte).value = this.invulnerable;
}
if (this.lightning !== undefined) {
abilitiesTag.ensureTag("lightning", NbtBinaryTag_1.NbtTagType.byte).value = this.lightning;
}
if (this.mayFly !== undefined) {
abilitiesTag.ensureTag("mayfly", NbtBinaryTag_1.NbtTagType.byte).value = this.mayFly;
}
if (this.mine !== undefined) {
abilitiesTag.ensureTag("mine", NbtBinaryTag_1.NbtTagType.byte).value = this.mine;
}
if (this.op !== undefined) {
abilitiesTag.ensureTag("op", NbtBinaryTag_1.NbtTagType.byte).value = this.op;
}
if (this.openContainers !== undefined) {
abilitiesTag.ensureTag("opencontainers", NbtBinaryTag_1.NbtTagType.byte).value = this.openContainers;
}
if (this.teleport !== undefined) {
abilitiesTag.ensureTag("teleport", NbtBinaryTag_1.NbtTagType.byte).value = this.teleport;
}
if (this.walkSpeed !== undefined) {
abilitiesTag.ensureTag("walkSpeed", NbtBinaryTag_1.NbtTagType.float).value = this.walkSpeed;
}
if (this.baseGameVersion !== undefined) {
root.ensureTag("baseGameVersion", NbtBinaryTag_1.NbtTagType.string).value = this.baseGameVersion;
}
if (this.bonusChestEnabled !== undefined) {
root.ensureTag("bonusChestEnabled", NbtBinaryTag_1.NbtTagType.byte).value = this.bonusChestEnabled;
}
if (this.bonusChestSpawned !== undefined) {
root.ensureTag("bonusChestSpawned", NbtBinaryTag_1.NbtTagType.byte).value = this.bonusChestSpawned;
}
if (this.cheatsEnabled !== undefined) {
root.ensureTag("cheatsEnabled", NbtBinaryTag_1.NbtTagType.byte).value = this.cheatsEnabled;
}
if (this.commandBlockOutput !== undefined) {
root.ensureTag("commandblockoutput", NbtBinaryTag_1.NbtTagType.byte).value = this.commandBlockOutput;
}
if (this.commandBlocksEnabled !== undefined) {
root.ensureTag("commandblocksenabled", NbtBinaryTag_1.NbtTagType.byte).value = this.commandBlocksEnabled;
}
if (this.commandsEnabled !== undefined) {
root.ensureTag("commandsEnabled", NbtBinaryTag_1.NbtTagType.byte).value = this.commandsEnabled;
}
if (this.currentTick !== undefined) {
root.ensureTag("currentTick", NbtBinaryTag_1.NbtTagType.long).value = this.currentTick;
}
if (this.daylightCycle !== undefined) {
root.ensureTag("daylightCycle", NbtBinaryTag_1.NbtTagType.int).value = this.daylightCycle;
}
if (this.doDaylightCycle !== undefined) {
root.ensureTag("dodaylightcycle", NbtBinaryTag_1.NbtTagType.byte).value = this.doDaylightCycle;
}
if (this.doEntityDrops !== undefined) {
root.ensureTag("doentitydrops", NbtBinaryTag_1.NbtTagType.byte).value = this.doEntityDrops;
}
if (this.doFireTick !== undefined) {
root.ensureTag("dofiretick", NbtBinaryTag_1.NbtTagType.byte).value = this.doFireTick;
}
if (this.doImmediateRespawn !== undefined) {
root.ensureTag("doimmediaterespawn", NbtBinaryTag_1.NbtTagType.byte).value = this.doImmediateRespawn;
}
if (this.doInsomnia !== undefined) {
root.ensureTag("doinsomnia", NbtBinaryTag_1.NbtTagType.byte).value = this.doInsomnia;
}
if (this.doMobLoot !== undefined) {
root.ensureTag("domobloot", NbtBinaryTag_1.NbtTagType.byte).value = this.doMobLoot;
}
if (this.doMobSpawning !== undefined) {
root.ensureTag("domobspawning", NbtBinaryTag_1.NbtTagType.byte).value = this.doMobSpawning;
}
if (this.doTileDrops !== undefined) {
root.ensureTag("dotiledrops", NbtBinaryTag_1.NbtTagType.byte).value = this.doTileDrops;
}
if (this.doWeatherCycle !== undefined) {
root.ensureTag("doweathercycle", NbtBinaryTag_1.NbtTagType.byte).value = this.doWeatherCycle;
}
if (this.drowningDamage !== undefined) {
root.ensureTag("drowningdamage", NbtBinaryTag_1.NbtTagType.byte).value = this.drowningDamage;
}
if (this.eduOffer !== undefined) {
root.ensureTag("eduOffer", NbtBinaryTag_1.NbtTagType.int).value = this.eduOffer;
}
if (this.educationFeaturesEnabled !== undefined) {
root.ensureTag("educationFeaturesEnabled", NbtBinaryTag_1.NbtTagType.byte).value = this.educationFeaturesEnabled;
}
if (this.betaApisExperiment ||
this.dataDrivenItemsExperiment ||
this.deferredTechnicalPreviewExperiment ||
this.savedWithToggledExperiments ||
this.experimentsEverUsed) {
const experimentsTag = root.ensureTag("experiments", NbtBinaryTag_1.NbtTagType.compound);
if (this.betaApisExperiment) {
experimentsTag.ensureTag("gametest", NbtBinaryTag_1.NbtTagType.byte).value = 1;
}
else {
experimentsTag.removeTag("gametest");
}
if (this.dataDrivenItemsExperiment) {
experimentsTag.ensureTag("data_driven_items", NbtBinaryTag_1.NbtTagType.byte).value = 1;
}
else {
experimentsTag.removeTag("data_driven_items");
}
if (this.deferredTechnicalPreviewExperiment) {
experimentsTag.ensureTag("deferred_technical_preview", NbtBinaryTag_1.NbtTagType.byte).value = 1;
}
else {
experimentsTag.removeTag("deferred_technical_preview");
}
if (this.savedWithToggledExperiments !== undefined) {
experimentsTag.ensureTag("saved_with_toggled_experiments", NbtBinaryTag_1.NbtTagType.byte).value =
this.savedWithToggledExperiments;
}
if (this.experimentsEverUsed !== undefined) {
experimentsTag.ensureTag("experiments_ever_used", NbtBinaryTag_1.NbtTagType.byte).value = this.experimentsEverUsed;
}
}
if (this.fallDamage !== undefined) {
root.ensureTag("falldamage", NbtBinaryTag_1.NbtTagType.byte).value = this.fallDamage;
}
if (this.fireDamage !== undefined) {
root.ensureTag("firedamage", NbtBinaryTag_1.NbtTagType.byte).value = this.fireDamage;
}
if (this.freezeDamage !== undefined) {
root.ensureTag("freezedamage", NbtBinaryTag_1.NbtTagType.byte).value = this.freezeDamage;
}
if (this.functionCommandLimit !== undefined) {
root.ensureTag("functioncommandlimit", NbtBinaryTag_1.NbtTagType.int).value = this.functionCommandLimit;
}
if (this.hasBeenLoadedInCreative !== undefined) {
root.ensureTag("hasBeenLoadedInCreative", NbtBinaryTag_1.NbtTagType.byte).value = this.hasBeenLoadedInCreative;
}
if (this.hasLockedBehaviorPack !== undefined) {
root.ensureTag("hasLockedBehaviorPack", NbtBinaryTag_1.NbtTagType.byte).value = this.hasLockedBehaviorPack;
}
if (this.hasLockedResourcePack !== undefined) {
root.ensureTag("hasLockedResourcePack", NbtBinaryTag_1.NbtTagType.byte).value = this.hasLockedResourcePack;
}
if (this.immutableWorld !== undefined) {
root.ensureTag("immutableWorld", NbtBinaryTag_1.NbtTagType.byte).value = this.immutableWorld;
}
if (this.isCreatedInEditor !== undefined) {
root.ensureTag("isCreatedInEditor", NbtBinaryTag_1.NbtTagType.byte).value = this.isCreatedInEditor;
}
if (this.editorWorldType !== undefined) {
root.ensureTag("editorWorldType", NbtBinaryTag_1.NbtTagType.byte).value = this.editorWorldType;
}
if (this.isExportedFromEditor !== undefined) {
root.ensureTag("isExportedFromEditor", NbtBinaryTag_1.NbtTagType.byte).value = this.isExportedFromEditor;
}
if (this.isFromLockedTemplate !== undefined) {
root.ensureTag("isFromLockedTemplate", NbtBinaryTag_1.NbtTagType.byte).value = this.isFromLockedTemplate;
}
if (this.isFromWorldTemplate !== undefined) {
root.ensureTag("isFromWorldTemplate", NbtBinaryTag_1.NbtTagType.byte).value = this.isFromWorldTemplate;
}
if (this.isRandomSeedAllowed !== undefined) {
root.ensureTag("isRandomSeedAllowed", NbtBinaryTag_1.NbtTagType.byte).value = this.isRandomSeedAllowed;
}
if (this.isSingleUseWorld !== undefined) {
root.ensureTag("isSingleUseWorld", NbtBinaryTag_1.NbtTagType.byte).value = this.isSingleUseWorld;
}
if (this.isWorldTemplateOptionLocked !== undefined) {
root.ensureTag("isWorldTemplateOptionLocked", NbtBinaryTag_1.NbtTagType.byte).value = this.isWorldTemplateOptionLocked;
}
if (this.keepInventory !== undefined) {
root.ensureTag("keepinventory", NbtBinaryTag_1.NbtTagType.byte).value = this.keepInventory;
}
if (this.lastOpenedWithVersion && this.lastOpenedWithVersion.length > 0) {
const tag = root.ensureTag("lastOpenedWithVersion", NbtBinaryTag_1.NbtTagType.list);
tag.setListFromArray(this.lastOpenedWithVersion);
}
if (this.lightningLevel !== undefined) {
root.ensureTag("lightningLevel", NbtBinaryTag_1.NbtTagType.float).value = this.lightningLevel;
}
if (this.lightningTime !== undefined) {
root.ensureTag("lightningTime", NbtBinaryTag_1.NbtTagType.int).value = this.lightningTime;
}
if (this.limitedWorldDepth !== undefined) {
root.ensureTag("limitedWorldDepth", NbtBinaryTag_1.NbtTagType.int).value = this.limitedWorldDepth;
}
if (this.limitedWorldWidth !== undefined) {
root.ensureTag("limitedWorldWidth", NbtBinaryTag_1.NbtTagType.int).value = this.limitedWorldWidth;
}
if (this.maxCommandChainLength !== undefined) {
root.ensureTag("maxcommandchainlength", NbtBinaryTag_1.NbtTagType.int).value = this.maxCommandChainLength;
}
if (this.mobGriefing !== undefined) {
root.ensureTag("mobgriefing", NbtBinaryTag_1.NbtTagType.byte).value = this.mobGriefing;
}
if (this.naturalRegeneration !== undefined) {
root.ensureTag("naturalregeneration", NbtBinaryTag_1.NbtTagType.byte).value = this.naturalRegeneration;
}
if (this.permissionsLevel !== undefined) {
root.ensureTag("permissionsLevel", NbtBinaryTag_1.NbtTagType.int).value = this.permissionsLevel;
}
if (this.playerPermissionsLevel !== undefined) {
root.ensureTag("playerPermissionsLevel", NbtBinaryTag_1.NbtTagType.int).value = this.playerPermissionsLevel;
}
if (this.prid !== undefined) {
root.ensureTag("prid", NbtBinaryTag_1.NbtTagType.string).value = this.prid;
}
if (this.pvp !== undefined) {
root.ensureTag("pvp", NbtBinaryTag_1.NbtTagType.byte).value = this.pvp;
}
if (this.rainLevel !== undefined) {
root.ensureTag("rainLevel", NbtBinaryTag_1.NbtTagType.float).value = this.rainLevel;
}
if (this.rainTime !== undefined) {
root.ensureTag("rainTime", NbtBinaryTag_1.NbtTagType.int).value = this.rainTime;
}
if (this.randomTickSpeed !== undefined) {
root.ensureTag("randomtickspeed", NbtBinaryTag_1.NbtTagType.int).value = this.randomTickSpeed;
}
if (this.requiresCopiedPackRemovalCheck !== undefined) {
root.ensureTag("requiresCopiedPackRemovalCheck", NbtBinaryTag_1.NbtTagType.byte).value = this.requiresCopiedPackRemovalCheck;
}
if (this.respawnBlocksExplode !== undefined) {
root.ensureTag("respawnblocksexplode", NbtBinaryTag_1.NbtTagType.byte).value = this.respawnBlocksExplode;
}
if (this.sendCommandFeedback !== undefined) {
root.ensureTag("sendcommandfeedback", NbtBinaryTag_1.NbtTagType.byte).value = this.sendCommandFeedback;
}
if (this.serverChunkTickRange !== undefined) {
root.ensureTag("serverChunkTickRange", NbtBinaryTag_1.NbtTagType.int).value = this.serverChunkTickRange;
}
if (this.showBorderEffect !== undefined) {
root.ensureTag("showbordereffect", NbtBinaryTag_1.NbtTagType.byte).value = this.showBorderEffect;
}
if (this.showCoordinates !== undefined) {
root.ensureTag("showcoordinates", NbtBinaryTag_1.NbtTagType.byte).value = this.showCoordinates;
}
if (this.showDeathMessages !== undefined) {
root.ensureTag("showdeathmessages", NbtBinaryTag_1.NbtTagType.byte).value = this.showDeathMessages;
}
if (this.showTags !== undefined) {
root.ensureTag("showtags", NbtBinaryTag_1.NbtTagType.byte).value = this.showTags;
}
if (this.spawnMobs !== undefined) {
root.ensureTag("spawnMobs", NbtBinaryTag_1.NbtTagType.byte).value = this.spawnMobs;
}
if (this.spawnRadius !== undefined) {
root.ensureTag("spawnradius", NbtBinaryTag_1.NbtTagType.int).value = this.spawnRadius;
}
if (this.startWithMapEnabled !== undefined) {
root.ensureTag("startWithMapEnabled", NbtBinaryTag_1.NbtTagType.byte).value = this.startWithMapEnabled;
}
if (this.texturePacksRequired !== undefined) {
root.ensureTag("texturePacksRequired", NbtBinaryTag_1.NbtTagType.byte).value = this.texturePacksRequired;
}
if (this.tntExplodes !== undefined) {
root.ensureTag("tntexplodes", NbtBinaryTag_1.NbtTagType.byte).value = this.tntExplodes;
}
if (this.useMsaGamertagsOnly !== undefined) {
root.ensureTag("useMsaGamertagsOnly", NbtBinaryTag_1.NbtTagType.byte).value = this.useMsaGamertagsOnly;
}
if (this.worldStartCount !== undefined) {
root.ensureTag("worldStartCount", NbtBinaryTag_1.NbtTagType.long).value = this.worldStartCount;
}
// const worldPoliciesTag = root.ensureTag("world_policies", NbtTagType.compound);
}
loadFromNbt(binary) {
this.nbt = binary;
if (binary.singleRoot == null) {
return;
}
const root = binary.singleRoot;
let tag = root.find("LevelName");
if (tag !== null) {
this.levelName = tag.valueAsString;
}
tag = root.find("SpawnX");
if (tag !== null) {
this.spawnX = tag.valueAsInt;
}
tag = root.find("SpawnY");
if (tag !== null) {
this.spawnY = tag.valueAsInt;
}
tag = root.find("SpawnZ");
if (tag !== null) {
this.spawnZ = tag.valueAsInt;
}
tag = root.find("editorWorldType");
if (tag !== null) {
this.editorWorldType = tag.valueAsInt;
}
tag = root.find("GameType");
if (tag !== null) {
this.gameType = tag.valueAsInt;
}
tag = root.find("Generator");
if (tag !== null) {
this.generator = tag.valueAsInt;
}
tag = root.find("commandsEnabled");
if (tag !== null) {
this.commandsEnabled = tag.valueAsBoolean;
}
tag = root.find("cheatsEnabled");
if (tag !== null) {
this.cheatsEnabled = tag.valueAsBoolean;
}
tag = root.find("commandsblocksenabled");
if (tag !== null) {
this.commandBlocksEnabled = tag.valueAsBoolean;
}
tag = root.find("experimentalgameplay");
if (tag !== null) {
this.experimentalGameplay = tag.valueAsBoolean;
}
tag = root.find("BiomeOverride");
if (tag !== null) {
this.biomeOverride = tag.valueAsString;
}
tag = root.find("CenterMapsToOrigin");
if (tag !== null) {
this.centerMapsToOrigin = tag.valueAsBoolean;
}
tag = root.find("ConfirmedPlatformLockedComponent");
if (tag !== null) {
this.confirmedPlatformLockedContent = tag.valueAsBoolean;
}
tag = root.find("Difficulty");
if (tag !== null) {
this.difficulty = tag.valueAsInt;
}
tag = root.find("FlatWorldLayers");
if (tag !== null) {
this.flatWorldLayers = tag.valueAsJSONObject;
}
tag = root.find("ForceGameType");
if (tag !== null) {
this.forceGameType = tag.valueAsBoolean;
}
tag = root.find("InventoryVersion");
if (tag !== null) {
this.inventoryVersion = tag.valueAsString;
}
tag = root.find("LANBroadcast");
if (tag !== null) {
this.lanBroadcast = tag.valueAsBoolean;
}
tag = root.find("LANBroadcastIntent");
if (tag !== null) {
this.lanBroadcastIntent = tag.valueAsBoolean;
}
tag = root.find("LastPlayed");
if (tag !== null) {
this.lastPlayed = tag.valueAsBigInt;
}
tag = root.find("LimitedWorldOriginX");
if (tag !== null) {
this.limitedWorldOriginX = tag.valueAsInt;
}
tag = root.find("LimitedWorldOriginY");
if (tag !== null) {
this.limitedWorldOriginY = tag.valueAsInt;
}
tag = root.find("LimitedWorldOriginZ");
if (tag !== null) {
this.limitedWorldOriginZ = tag.valueAsInt;
}
tag = root.find("MinimumCompatibleClientVersion");
if (tag !== null) {
this.minimumCompatibleClientVersion = tag.valueAsNumericArray;
}
tag = root.find("lastOpenedWithVersion");
if (tag !== null) {
this.lastOpenedWithVersion = tag.valueAsNumericArray;
}
tag = root.find("MultiplayerGame");
if (tag !== null) {
this.multiplayerGame = tag.valueAsBoolean;
}
tag = root.find("MultiplayerGameIntent");
if (tag !== null) {
this.multiplayerGameIntent = tag.valueAsBoolean;
}
tag = root.find("NetherScale");
if (tag !== null) {
this.netherScale = tag.valueAsInt;
}
tag = root.find("NetworkVersion");
if (tag !== null) {
this.networkVersion = tag.valueAsInt;
}
tag = root.find("Platform");
if (tag !== null) {
this.platform = tag.valueAsInt;
}
tag = root.find("PlatformBroadcastIntent");
if (tag !== null) {
this.platformBroadcastIntent = tag.valueAsInt;
}
tag = root.find("RandomSeed");
if (tag !== null) {
this.randomSeed = tag.valueAsBigInt.toString();
}
tag = root.find("SpawnV1Villagers");
if (tag !== null) {
this.spawnV1Villagers = tag.valueAsBoolean;
}
tag = root.find("StorageVersion");
if (tag !== null) {
this.storageVersion = tag.valueAsInt;
}
tag = root.find("Time");
if (tag !== null) {
this.time = tag.valueAsBigInt;
}
tag = root.find("WorldVersion");
if (tag !== null) {
this.worldVersion = tag.valueAsInt;
}
tag = root.find("XBLBroadcastIntent");
if (tag !== null) {
this.xblBroadcastIntent = tag.valueAsInt;
}
tag = root.find("baseGameVersion");
if (tag !== null) {
this.baseGameVersion = tag.valueAsString;
}
tag = root.find("bonusChestEnabled");
if (tag !== null) {
this.bonusChestEnabled = tag.valueAsBoolean;
}
tag = root.find("bonusChestSpawned");
if (tag !== null) {
this.bonusChestSpawned = tag.valueAsBoolean;
}
tag = root.find("commandblockoutput");
if (tag !== null) {
this.commandBlockOutput = tag.valueAsBoolean;
}
tag = root.find("MultiplayerGame");
if (tag !== null) {
this.multiplayerGame = tag.valueAsBoolean;
}
tag = root.find("currentTick");
if (tag !== null) {
this.currentTick = tag.valueAsBigInt;
}
tag = root.find("dodaylightcycle");
if (tag !== null) {
this.doDaylightCycle = tag.valueAsBoolean;
}
tag = root.find("daylightCycle");
if (tag !== null) {
this.daylightCycle = tag.valueAsInt;
}
tag = root.find("doentitydrops");
if (tag !== null) {
this.doEntityDrops = tag.valueAsBoolean;
}
tag = root.find("dofiretick");
if (tag !== null) {
this.doFireTick = tag.valueAsBoolean;
}
tag = root.find("doimmediaterespawn");
if (tag !== null) {
this.doImmediateRespawn = tag.valueAsBoolean;
}
tag = root.find("doinsomnia");
if (tag !== null) {
this.doInsomnia = tag.valueAsBoolean;
}
tag = root.find("domobloot");
if (tag !== null) {
this.doMobLoot = tag.valueAsBoolean;
}
tag = root.find("domobspawning");
if (tag !== null) {
this.doMobSpawning = tag.valueAsBoolean;
}
tag = root.find("dotiledrops");
if (tag !== null) {
this.doTileDrops = tag.valueAsBoolean;
}
tag = root.find("doweathercycle");
if (tag !== null) {
this.doWeatherCycle = tag.valueAsBoolean;
}
tag = root.find("drowningdamage");
if (tag !== null) {
this.drowningDamage = tag.valueAsBoolean;
}
tag = root.find("eduOffer");
if (tag !== null) {
this.eduOffer = tag.valueAsInt;
}
tag = root.find("educationFeaturesEnabled");
if (tag !== null) {
this.educationFeaturesEnabled = tag.valueAsBoolean;
}
tag = root.find("falldamage");
if (tag !== null) {
this.fallDamage = tag.valueAsBoolean;
}
tag = root.find("freezedamage");
if (tag !== null) {
this.freezeDamage = tag.valueAsBoolean;
}
tag = root.find("functioncommandlimit");
if (tag !== null) {
this.functionCommandLimit = tag.valueAsInt;
}
tag = root.find("hasBeenLoadedInCreative");
if (tag !== null) {
this.hasBeenLoadedInCreative = tag.valueAsBoolean;
}
tag = root.find("hasLockedBehaviorPack");
if (tag !== null) {
this.hasLockedBehaviorPack = tag.valueAsBoolean;
}
tag = root.find("hasLockedResourcePack");
if (tag !== null) {
this.hasLockedResourcePack = tag.valueAsBoolean;
}
tag = root.find("immutableWorld");
if (tag !== null) {
this.immutableWorld = tag.valueAsBoolean;
}
tag = root.find("isFromLockedTemplate");
if (tag !== null) {
this.isFromLockedTemplate = tag.valueAsBoolean;
}
tag = root.find("isRandomSeedAllowed");
if (tag !== null) {
this.isRandomSeedAllowed = tag.valueAsBoolean;
}
tag = root.find("isCreatedInEditor");
if (tag !== null) {
this.isCreatedInEditor = tag.valueAsBoolean;
}
tag = root.find("isExportedFromEditor");
if (tag !== null) {
this.isExportedFromEditor = tag.valueAsBoolean;
}
tag = root.find("isFromWorldTemplate");
if (tag !== null) {
this.isFromWorldTemplate = tag.valueAsBoolean;
}
tag = root.find("isSingleUseWorld");
if (tag !== null) {
this.isSingleUseWorld = tag.value