MCStacker/mc2-1.16Pure.min.js

2 lines
511 KiB
JavaScript
Raw Normal View History

2020-08-26 21:23:00 +02:00
//Copyright 2020 Matt Godfrey, (http://mcstacker.net/) Please don't steal my code or I'll /summon tnt on your house.
class CachedNBT{constructor(){this.clear(),this.lastfilterUse=0}clear(){this.nbt={},this.meta={},this.dropChance={}}updateFilterLastUsed(){this.lastfilterUse=(new Date).getTime()}setMetaForNBT(e,t,a,o,n){this.meta[e]={data:t,fwClass:a,eventClass:o,stackPos:n}}getItemType(e){let t=this.nbt[e];if(void 0!=t&&"{}"!=t){var a=new CMDParser("").parseCompound(extractSegment("{","}",t.indexOf("{"),t));return void 0!=a.id?extractMinecraftID(a.id.val):-1}return-1}setNBT(e,t){this.lastfilterUse+2e3<(new Date).getTime()&&(t.length>0?0==t.indexOf(",Slot:")?this.nbt[e]="{"+t.substr(t.indexOf("b")+2)+"}":this.nbt[e]="{"+t.substr(1)+"}":this.nbt[e]="{}")}setBlockNBT(e,t){void 0!=t&&"{}"!=t&&""!=t&&this.lastfilterUse+2e3<(new Date).getTime()&&(this.nbt[e]=t)}getNBT(e){return this.nbt[e]}loadCachedItemNBT(e){let t=this.nbt[e];if(void 0!=t&&"{}"!=t)try{let n=new CMDParser("");var a=n.parseCompound(extractSegment("{","}",t.indexOf("{"),t)),o=$("#"+e).val();loadItemNBTIntoSlot(a,o,e,n)}catch(e){}}loadCachedEntityNBT(e){let t="e"+e,a=this.nbt[t];if(void 0!=a&&"{}"!=a)try{let t=new CMDParser(""),o=t.parseCompound(extractSegment("{","}",a.indexOf("{"),a));t.loadSummonCommand(o,e)}catch(e){}}loadCachedBlockNBT(e){let t=this.nbt[e];if(void 0!=t&&"{}"!=t&&""!=t)try{let e=new CMDParser(""),a=e.parseCompound(extractSegment("{","}",t.indexOf("{"),t));e.loadBlockDataCommand(a,$("#block").val())}catch(e){}}}class Settings{constructor(){this.readSettings(),$("#settings").draggable(),$("#settings").hide(),$("#closeSettingsBut").bind("click",function(){$("#settings").hide()}),$("#removeSlash").bind("change",function(){settings.removeSlash=$("#removeSlash").is(":checked"),settings.writeSettings(),generateCommand()}),$("#loadItemUI").bind("change",function(){settings.loadItemUI=$("#loadItemUI").is(":checked"),settings.writeSettings()}),$("#namespace").bind("keyup",function(){settings.namespace=$("#namespace").val(),settings.writeSettings(),generateCommand()}),$("#updateNamespace").bind("change",function(){settings.updateNamespace=$("#updateNamespace").is(":checked"),settings.writeSettings()}),$("#warnOnClose").bind("change",function(){settings.warnOnClose=$("#warnOnClose").is(":checked"),settings.writeSettings(),settings.warnOnClose?window.addEventListener("beforeunload",function(e){e.preventDefault(),e.returnValue="Have you saved your command?"}):window.removeEventListener("beforeunload",function(e){e.preventDefault(),e.returnValue="Have you saved your command?"})})}readSettings(){localStorage.namespace?this.namespace=localStorage.namespace:this.namespace="",localStorage.updateNamespace&&"true"==localStorage.updateNamespace?this.updateNamespace=!0:this.updateNamespace=!1,localStorage.removeSlash&&"true"==localStorage.removeSlash?this.removeSlash=!0:this.removeSlash=!1,localStorage.loadItemUI&&"true"==localStorage.loadItemUI?this.loadItemUI=!0:this.loadItemUI=!1,localStorage.warnOnClose&&"true"==localStorage.warnOnClose?(this.warnOnClose=!0,"true"==localStorage.warnOnClose&&window.addEventListener("beforeunload",function(e){e.preventDefault(),e.returnValue="Have you saved your command?"})):this.warnOnClose=!1,$("#namespace").val(this.namespace),$("#updateNamespace").attr("checked",this.updateNamespace),$("#loadItemUI").attr("checked",this.loadItemUI),$("#removeSlash").attr("checked",this.removeSlash),$("#warnOnClose").attr("checked",this.warnOnClose)}modifyNamespace(e){this.updateNamespace&&(this.namespace=e,$("#namespace").val(this.namespace),this.writeSettings())}writeSettings(){localStorage.loadItemUI=this.loadItemUI,localStorage.namespace=this.namespace,localStorage.updateNamespace=this.updateNamespace,localStorage.removeSlash=this.removeSlash,localStorage.warnOnClose=this.warnOnClose}}function showSettings(){$("#settings").css({top:mouse.y+200,left:mouse.x}),$("#settings").show()}function occurrences(e,t,a){if(e+="",(t+="").length<=0)return e.length+1;for(var o=0,n=0,s=a?1:t.length;(n=e.indexOf(t,n))>=0;)++o,n+=s;return o}class CMDParser{constructor(e){this.level=0,this.state="S",e=e.trim(),this.nbt=null,this.executeParts=[]}parseLootTableNBT(e,t,a){th