UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

1 lines 5.21 kB
"use strict";(self.webpackChunkmctools_app=self.webpackChunkmctools_app||[]).push([[734],{16734:(e,s,t)=>{t.d(s,{default:()=>n});var r=t(74848),a=t(96540),o=t(30541),i=t(60982),l=t(40267),c=t(14466);class n extends a.Component{_volumeEditorRef;constructor(e){super(e),this._volumeEditorRef=(0,a.createRef)(),this.state={isLoaded:!1,structure:void 0,loadingMessage:"Initializing...",loadAttempt:0},this._handleRetry=this._handleRetry.bind(this)}_handleRetry(){this.setState(e=>({isLoaded:!1,structure:void 0,errorMessage:void 0,loadingMessage:"Retrying...",loadAttempt:e.loadAttempt+1}),()=>{this._loadStructure()})}async componentDidMount(){this._getStructureUrlFromProps()?void 0!==this.props.skipVanillaResources&&await this._loadStructure():this.setState({isLoaded:!0,errorMessage:"No structure loaded. Open one from the project sidebar.",loadingMessage:void 0})}componentDidUpdate(e){const s=void 0===e.skipVanillaResources&&void 0!==this.props.skipVanillaResources,t=e.structureUrl!==this.props.structureUrl;(s||t)&&this._loadStructure()}_getStructureUrlFromProps(){if(this.props.structureUrl)return this.props.structureUrl;const e=new URLSearchParams(window.location.search);return e.get("structure")||e.get("struct")||void 0}_getCameraPositionFromProps(){if(void 0!==this.props.cameraX&&void 0!==this.props.cameraY&&void 0!==this.props.cameraZ)return{x:this.props.cameraX,y:this.props.cameraY,z:this.props.cameraZ};const e=new URLSearchParams(window.location.search),s=e.get("cameraX"),t=e.get("cameraY"),r=e.get("cameraZ");return null!==s&&null!==t&&null!==r?{x:parseFloat(s),y:parseFloat(t),z:parseFloat(r)}:{}}async _loadStructure(){this.setState({loadingMessage:"Loading vanilla catalog..."}),!1===this.props.skipVanillaResources&&(await l.A.loadVanillaCatalog(),await l.A.loadVanillaResourceDefinitions());const e=this._getStructureUrlFromProps();if(e){this.setState({loadingMessage:`Loading structure from ${e}...`});try{const s=await fetch(e);if(!s.ok)throw new Error(`Failed to fetch structure: ${s.status} ${s.statusText}`);const t=await s.arrayBuffer(),r=new Uint8Array(t),a=new i.A;if(await a.loadFromNbtBytes(r),!a.cube)return void this.setState({isLoaded:!0,errorMessage:"This structure file doesn't contain any block data.",loadingMessage:void 0});this.setState({isLoaded:!0,structure:a,loadingMessage:void 0})}catch(e){c.Ay.verbose("Error loading structure: "+e),this.setState({isLoaded:!0,errorMessage:"This structure file couldn't be loaded. It may be corrupted or saved in an unsupported format.",loadingMessage:void 0})}}else this.setState({isLoaded:!0,errorMessage:"No structure loaded. Open one from the project sidebar."})}render(){const{heightOffset:e,skipVanillaResources:s,hideChrome:t}=this.props,{isLoaded:a,structure:i,errorMessage:l,loadingMessage:c}=this.state,n=`calc(100vh - ${e}px)`;if(!a||c)return(0,r.jsx)("div",{className:"sv-container",style:{height:n},children:(0,r.jsxs)("div",{className:"sv-loading",children:[(0,r.jsx)("div",{className:"sv-spinner"}),(0,r.jsx)("span",{children:c||"Loading..."})]})});if(l)return(0,r.jsx)("div",{className:"sv-container",style:{height:n},children:(0,r.jsx)("div",{className:"sv-error",children:(0,r.jsxs)("div",{className:"sv-error-content",children:[(0,r.jsx)("div",{className:"sv-error-icon",children:"⚠"}),(0,r.jsx)("div",{className:"sv-error-message",children:l}),(0,r.jsxs)("div",{className:"sv-error-actions",children:[(0,r.jsx)("button",{className:"sv-error-button",onClick:this._handleRetry,children:"Retry"}),(0,r.jsx)("button",{className:"sv-render-banner-dismiss",onClick:()=>window.history.back(),children:"Go Back"})]})]})})});if(!i||!i.cube)return(0,r.jsx)("div",{className:"sv-container",style:{height:n},children:(0,r.jsx)("div",{className:"sv-error",children:"No structure data available"})});const d=i.cube,h=`${d.maxX} × ${d.maxY} × ${d.maxZ}`,u=this._getCameraPositionFromProps();return t?(0,r.jsx)("div",{className:"sv-container sv-no-chrome",style:{height:n},children:(0,r.jsx)("div",{className:"sv-viewport sv-viewport-full",children:(0,r.jsx)(o.Ay,{ref:this._volumeEditorRef,blockVolume:i.cube,entities:i.entities,viewMode:o.Yh.Structure,heightOffset:e,skipVanillaResources:s,showToolbar:this.props.showEditorTools??!1,showRightPanel:this.props.showEditorTools??!1,hideChrome:!this.props.showEditorTools,cameraX:u.x,cameraY:u.y,cameraZ:u.z},this.state.loadAttempt)})}):(0,r.jsxs)("div",{className:"sv-container",style:{height:n},children:[(0,r.jsxs)("div",{className:"sv-toolbar",children:[(0,r.jsxs)("span",{className:"sv-info",children:["Structure: ",h," blocks"]}),(0,r.jsx)("button",{className:"sv-toolbar-button",onClick:this._handleRetry,title:"Reload textures and re-render","aria-label":"Reload structure",children:"Reload"})]}),(0,r.jsx)("div",{className:"sv-viewport",children:(0,r.jsx)(o.Ay,{ref:this._volumeEditorRef,blockVolume:i.cube,entities:i.entities,viewMode:o.Yh.Structure,heightOffset:e+40,skipVanillaResources:s,showToolbar:this.props.showEditorTools??!1,showRightPanel:this.props.showEditorTools??!1,cameraX:u.x,cameraY:u.y,cameraZ:u.z},this.state.loadAttempt)}),(0,r.jsx)("canvas",{className:"sv-canvas","data-testid":"structure-viewer-canvas",style:{display:"none"}})]})}}}}]);