UNPKG

bedrock-development

Version:

APIs for creating and editing files related to Minecraft Bedrock development.

31 lines (30 loc) 1.03 kB
import { Directories } from "../../file_manager.js"; import { MinecraftDataType } from "../minecraft.js"; export class ClientBlocks extends MinecraftDataType { static get DirectoryPath() { return Directories.RESOURCE_PATH; } constructor(filepath, template) { super(filepath, template); Object.getOwnPropertyNames(template).forEach(prop => { this[prop] = template[prop]; }); } static createFilePath() { return this.DirectoryPath + "blocks.json"; } static createFromTemplate() { return new ClientBlocks(this.createFilePath(), {}); } static fileWithAddedBlock(name, block) { const blocks = ClientBlocks.fromPathOrTemplate(ClientBlocks, ClientBlocks.createFilePath()); blocks.addBlock(name, block); return blocks.toFile(); } toFile() { return { filePath: this.filePath, fileContents: this.serialize(), handleExisting: 'overwrite' }; } addBlock(name, block) { this[name] = block; } }