mcpack
Version:
Helper to manage Minecraft datapacks
1 lines • 8.28 kB
JavaScript
!function(n){var e={};function t(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,i){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:i})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(i,o,function(e){return n[e]}.bind(null,o));return i},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=3)}([function(n,e){n.exports=require("path")},function(n,e){n.exports=require("fs")},function(n,e){n.exports=require("commander")},function(n,e,t){"use strict";t.r(e);var i=t(2),o=t.n(i),a=t(0),c=t.n(a),r=t(1),s=t.n(r);function l(n,e){let t="[31m";"info"===n&&(t="[36m"),console.log(`${t}[${n}][0m ${e}`)}function d(n,e){let t="";return t=null===n?"null":void 0===n?"undefined":Object.prototype.toString.call(n).slice(8,-1).toLowerCase(),e?t===e:t}function u(n){return n.replace(/([\\/:*¿?'"<>|])/gi,"").replace(/([\t\r\n])/gi," ")}function f(n,e){let t=c.a.dirname(n);if(s.a.existsSync(t))return e.verbose&&l("info",`Already exists folder: ${t}`),!0;f(t,e),e.verbose&&l("info",`Creating ${t}`),s.a.mkdirSync(t)}function p(n,e,t){f(n,{verbose:!1}),s.a.writeFileSync(n,e,{encoding:"utf8"}),t.verbose&&l("info",`Added ${n}`)}function m(n){return`{\n "values": [\n ${n.join(",\n ")}\n ]\n}`}function k(n){return`{\n "display": {\n "icon": {\n "item": "${n.display.icon}"\n },\n "title": {\n "text": "${n.display.title.text}",\n "color": "${n.display.title.color}",\n "bold": ${!!n.display.title.bold},\n "italic": ${!!n.display.title.italic}\n },\n "description": {\n "text": "${n.display.desc.text}",\n "color": "${n.display.desc.color}",\n "bold": ${!!n.display.desc.bold},\n "italic": ${!!n.display.desc.italic}\n },${d(n.display.background,"string")?`\n "background": "${n.display.background}",`:""}\n "show_toast": ${!!n.display.toast},\n "announce_to_chat": ${!!n.display.announce},\n "frame": "${n.display.frame}"\n },${d(n.parent,"string")?`\n "parent": "${n.parent}",`:""}\n "criteria": {\n "tick": {\n "trigger": "${n.trigger}"\n }\n }\n}`}function y(n,e,t,i,o,a){const r=c.a.join(n,"/main/"),s=c.a.join(r,"/advancements/main/"),d=c.a.join(r,"/functions/"),u=c.a.join(r,"/tags/functions/"),f=function(n,e,t){return{root:k({display:{icon:"minecraft:chest",title:{text:"Vanilla Tweaks",color:"gold",bold:!0},desc:{text:"All currently installed datapacks",color:"white",italic:!0},background:"minecraft:textures/block/black_concrete.png",frame:"challenge"},trigger:"minecraft:tick"}),datapack:k({display:{icon:n,title:{text:e,color:"white"},desc:{text:t,color:"green",italic:!0},frame:"goal"},parent:"main:main/root",trigger:"minecraft:tick"})}}(i,e,o),y={init:"# Desc: Creates required global scores\n#\n# Called by: #main:init\n\nscoreboard objectives add hc_tick dummy\nscoreboard objectives add hc_uninstall dummy\n",tick:"# Desc: Controls all function to run on the server. Make funtions run much less\n#\n# Called by: #minecraft:tick\n\nscoreboard players add #hc_tick hc_tick 1\n\n# Every tick\nfunction #main:tick\n\n# Every 1 second\nexecute if score #hc_tick hc_tick matches 1 run function #main:second\nexecute if score #hc_tick hc_tick matches 21 run function #main:second\nexecute if score #hc_tick hc_tick matches 41 run function #main:second\nexecute if score #hc_tick hc_tick matches 61 run function #main:second\nexecute if score #hc_tick hc_tick matches 81 run function #main:second\n\nexecute if score #hc_tick hc_tick matches 100.. run scoreboard players set #hc_tick hc_tick 0\n",uninstall_message:'# Desc: Main uninstall message. Will only be displayed once.\n#\n# Called by: #main:uninstall\n\nscoreboard players add @s hc_uninstall 1\ntellraw @s[scores={hc_uninstall=1}] ["",{"text":"All ","color":"red"},{"text":"datapacks ","color":"yellow"},{"text":"removed. \\nTo complete the process, remove all ","color":"red"},{"text":"unwanted datapacks ","color":"yellow"},{"text":"from your ","color":"red"},{"text":"datapacks ","color":"yellow"},{"text":"folder. ","color":"red"},{"text":"/reload ","color":"yellow"},{"text":"after.","color":"red"}]\n\nscoreboard objectives remove hc_tick\nscoreboard objectives remove hc_uninstall\n'},b=function(n){return{init:m(['"main:init"',`"${n}:init"`]),tick:m([`"${n}:tick"`]),uninstall:m(['"main:uninstall_message"',`"${n}:uninstall"`])}}(t);a.verbose&&l("info",`Creating ${r}`),a.verbose&&l("info",`Creating ${s}`),p(c.a.join(s,`/${t}.json`),f.datapack,a),p(c.a.join(s,"/root.json"),f.root,a),a.verbose&&l("info",`Succesfully created ${s}`),a.verbose&&l("info",`Creating ${d}`),p(c.a.join(d,"/init.mcfunction"),y.init,a),p(c.a.join(d,"/tick.mcfunction"),y.tick,a),p(c.a.join(d,"/uninstall_message.mcfunction"),y.uninstall_message,a),a.verbose&&l("info",`Succesfully created ${d}`),a.verbose&&l("info",`Creating ${u}`),p(c.a.join(u,"/init.json"),b.init,a),p(c.a.join(u,"/tick.json"),b.tick,a),p(c.a.join(u,"/uninstall.json"),b.uninstall,a),a.verbose&&l("info",`Succesfully created ${u}`),a.verbose&&l("info",`Succesfully created ${r}`)}o.a.version("1.0.3").option("--v, --verbose","output extra debugging info",!1).option("--f, --force","force the procediment",!1),o.a.command("init <name>").option("-v, --dpVersion <version>","defines a datapack version",/^(([0-9]+\.)*[0-9]+)$/g,"0.1.0").option("-d, --dpDescription <description>","defines a datapack description","This datapack doesn't have description.").option("-i, --dpIcon <icon>","defines a datpack icon",/^(minecraft:[a-z_]+)$/g,"minecraft:dirt").option("-a, --dpAlias <alias>","alias for datapack functions folder",/^([a-z_]+)$/g).option("-f, --pack_format <pack_format>","defines de datapack format",/^(3|4|5)$/g,"4").description("start a new DataPack").action((function(n,e){const t={verbose:!!o.a.verbose},{dpVersion:i,dpDescription:a,dpIcon:r,dpAlias:k,pack_format:b}=e,g=c.a.join(process.cwd(),`./${u(n).toLowerCase()} v${i}/`),$=c.a.join(g,"/data/"),v=d(k,"string")?k:u(n).replace(" ","_").toLowerCase();if(f(c.a.join(g,"/any"),{verbose:!1})){if(!o.a.force)return void l("warn",[`There's an existing data pack with the path: ${g}`," Retry by changing the name or version of the new datapack"," Or if you are sure of what you are doing, retry using the force flag (--f)",""].join("\n"));t.verbose&&l("info",`Removing ${g}`),s.a.rmdirSync(g,{recursive:!0})}t.verbose&&l("info",`Creating ${g}`),p(c.a.join(g,"/pack.mcmeta"),`{\n "pack": {\n "pack_format": ${b},\n "description": "${n}"\n }\n}`,t),y($,n,v,r,a,t),function(n,e){const t=c.a.join(n,"/minecraft/tags/functions/"),i=m(['"#main:init"']),o=m(['"main:tick"']);e.verbose&&l("info",`Creating ${t}`),p(c.a.join(t,"/load.json"),i,e),p(c.a.join(t,"/tick.json"),o,e),e.verbose&&l("info",`Succesfully created ${t}`)}($,t),function(n,e,t){const i=c.a.join(n,`/${e}/functions/`),o=function(n){return{init:`# Creates all scores required by the datapack\n#\n# Datapack alias: ${n}\n`,tick:`# Controls everything to do with the datapack\n#\n# Datapack alias: ${n}\n`,uninstall:`# Removes all scores required by the datapack\n#\n# Datapack alias: ${n}\n`}}(e);t.verbose&&l("info",`Creating ${i}`),p(c.a.join(i,"/init.mcfunction"),o.init,t),p(c.a.join(i,"/tick.mcfunction"),o.tick,t),p(c.a.join(i,"/uninstall.mcfunction"),o.uninstall,t),t.verbose&&l("info",`Succesfully created ${i}`)}($,v,t),t.verbose&&l("info",`Succesfully created ${g}`),console.log(`\nThe datapack ${n} was succesfully created on folder ${g}\n`)})).on("--help",()=>["Examples: "," $ init awesome_datapack"," $ init awesome_datapack 1.3.2 -a aw"," $ init awesome_datapack 1.3.2 -i minecraft:podzol",' $ init awesome_datapack 1.3.2 -d "An awesome datapack"',""].join("\n")),o.a.parse(process.argv)}]);