bedrock-development
Version:
APIs for creating and editing files related to Minecraft Bedrock development.
166 lines (165 loc) • 8.43 kB
JavaScript
import { Directories } from "../../file_manager.js";
import { currentFormatVersion } from "../../utils.js";
import { MinecraftDataType } from "../minecraft.js";
export class ClientAttachable extends MinecraftDataType {
static get DirectoryPath() {
return Directories.RESOURCE_PATH + 'attachables/';
}
constructor(filepath, template) {
super(filepath, template);
this.format_version = template.format_version;
this["minecraft:attachable"] = template["minecraft:attachable"];
}
static createFromTemplate(nameData) {
return new ClientAttachable(this.createFilePath(nameData), {
format_version: currentFormatVersion,
"minecraft:attachable": {
description: {
identifier: nameData.fullname,
materials: {
default: "entity_alphatest",
enchanted: "entity_alphatest_glint",
},
textures: {
default: `textures/${Directories.ADDON_PATH}attachables/${nameData.shortname}`,
enchanted: "textures/misc/enchanted_item_glint",
},
geometry: {
default: `geometry.${nameData.namespace}.player.${nameData.shortname}`,
},
scripts: {
pre_animation: [
"v.is_first_person = c.is_first_person;",
]
},
render_controllers: [
"controller.render.item_default"
]
}
}
});
}
addInitializeVariable(...variables) {
var _a, _b;
this["minecraft:attachable"].description.scripts = (_a = this["minecraft:attachable"].description.scripts) !== null && _a !== void 0 ? _a : {};
this["minecraft:attachable"].description.scripts.initialize = (_b = this["minecraft:attachable"].description.scripts.initialize) !== null && _b !== void 0 ? _b : [];
variables.forEach(variable => {
var _a, _b;
if (!((_a = this["minecraft:attachable"].description.scripts.initialize) === null || _a === void 0 ? void 0 : _a.includes(variable))) {
(_b = this["minecraft:attachable"].description.scripts.initialize) === null || _b === void 0 ? void 0 : _b.push(variable);
}
});
}
addPreAnimationVariable(...variables) {
var _a, _b;
this["minecraft:attachable"].description.scripts = (_a = this["minecraft:attachable"].description.scripts) !== null && _a !== void 0 ? _a : {};
this["minecraft:attachable"].description.scripts.pre_animation = (_b = this["minecraft:attachable"].description.scripts.pre_animation) !== null && _b !== void 0 ? _b : [];
variables.forEach(variable => {
var _a, _b;
if (!((_a = this["minecraft:attachable"].description.scripts.initialize) === null || _a === void 0 ? void 0 : _a.includes(variable))) {
(_b = this["minecraft:attachable"].description.scripts.initialize) === null || _b === void 0 ? void 0 : _b.push(variable);
}
});
}
addMaterials(...materials) {
var _a;
this["minecraft:attachable"].description.materials = (_a = this["minecraft:attachable"].description.materials) !== null && _a !== void 0 ? _a : {};
materials.forEach(material => {
this["minecraft:attachable"].description.materials[material.name] = material.reference;
});
}
addGeometry(...geometry) {
var _a;
this["minecraft:attachable"].description.geometry = (_a = this["minecraft:attachable"].description.geometry) !== null && _a !== void 0 ? _a : {};
geometry.forEach(geometry => {
this["minecraft:attachable"].description.geometry[geometry.name] = geometry.reference;
});
}
addRenderController(...render_controllers) {
var _a;
this["minecraft:attachable"].description.render_controllers = (_a = this["minecraft:attachable"].description.render_controllers) !== null && _a !== void 0 ? _a : [];
render_controllers.forEach(render_controller => {
var _a, _b;
if (!((_a = this["minecraft:attachable"].description.render_controllers) === null || _a === void 0 ? void 0 : _a.includes(render_controller))) {
(_b = this["minecraft:attachable"].description.render_controllers) === null || _b === void 0 ? void 0 : _b.push(render_controller);
}
});
}
addAnimation(...animations) {
var _a;
this["minecraft:attachable"].description.animations = (_a = this["minecraft:attachable"].description.animations) !== null && _a !== void 0 ? _a : {};
animations.forEach(animation => {
this["minecraft:attachable"].description.animations[animation.name] = animation.reference;
});
}
addAnimateScript(...animations) {
var _a, _b;
this["minecraft:attachable"].description.scripts = (_a = this["minecraft:attachable"].description.scripts) !== null && _a !== void 0 ? _a : {};
this["minecraft:attachable"].description.scripts.animate = (_b = this["minecraft:attachable"].description.scripts.animate) !== null && _b !== void 0 ? _b : [];
animations.forEach(animation => {
var _a, _b;
if (!((_a = this["minecraft:attachable"].description.scripts.animate) === null || _a === void 0 ? void 0 : _a.includes(animation))) {
(_b = this["minecraft:attachable"].description.scripts.animate) === null || _b === void 0 ? void 0 : _b.push(animation);
}
});
}
}
class ClientAttachableArmor extends ClientAttachable {
static get DirectoryPath() {
return Directories.RESOURCE_PATH + 'attachables/player/';
}
static createFromTemplate(nameData) {
return new ClientAttachable(this.createFilePath(nameData), {
format_version: currentFormatVersion,
"minecraft:attachable": {
description: {
identifier: nameData.fullname,
materials: {
default: "armor",
enchanted: "armor_enchanted",
},
textures: {
default: `textures/${Directories.ADDON_PATH}models/armor/${nameData.shortname.replace(`_${this.armorType}`, "")}`,
enchanted: "textures/misc/enchanted_item_glint",
},
geometry: {
default: `geometry.${nameData.namespace}.player.${nameData.shortname.replace(`_${this.armorType}`, "")}.armor.${this.armorType}`,
},
scripts: {
initialize: [
"variable.is_first_person = 0.0;"
],
pre_animation: [
"v.is_first_person = c.owning_entity->v.is_first_person;",
"v.is_paperdoll = c.owning_entity->v.is_paperdoll;"
],
parent_setup: `variable.${this.armorType}_layer_visible = 0.0;`,
},
render_controllers: [
"controller.render.armor"
]
}
}
});
}
addOwnerFilter(shortname, owner) {
const originalIdentifier = this["minecraft:attachable"].description.identifier;
this["minecraft:attachable"].description.identifier += `.${shortname}`;
this["minecraft:attachable"].description.item = {
[originalIdentifier]: `query.owner_identifier == '${owner}'`,
};
}
}
ClientAttachableArmor.armorType = "";
export class ClientAttachableArmorHelmet extends ClientAttachableArmor {
}
ClientAttachableArmorHelmet.armorType = "helmet";
export class ClientAttachableArmorChestplate extends ClientAttachableArmor {
}
ClientAttachableArmorChestplate.armorType = "chestplate";
export class ClientAttachableArmorLeggings extends ClientAttachableArmor {
}
ClientAttachableArmorLeggings.armorType = "leggings";
export class ClientAttachableArmorBoots extends ClientAttachableArmor {
}
ClientAttachableArmorBoots.armorType = "boots";