blockbench icon indicating copy to clipboard operation
blockbench copied to clipboard

Allow Textures to be created outside of a Project

Open SnaveSutit opened this issue 3 months ago • 1 comments

Animated Java needs to create a texture that isn't related to any specific project, however, the Texture constructor includes this line:

Project.materials[this.uuid] = mat;

which causes an Error if Project isn't a ModelProject if I attempt to make the Texture before a Project has actually been loaded.

My PR is very simple:

if (!data.standalone) {
  if (!Project) throw new Error('Attempted to create a Texture without a Project. If this is intentional, set the standalone option to true.');
  Project.materials[this.uuid] = mat;
};

Add an option to TextureOptions to avoid adding to a project, while still throwing an error otherwise, but using that Error to intentionally inform the plugin developer.

My current work-around solution is this extremely hacky bit of code:


const OLD_PROJECT = Project
// @ts-ignore
Project = { materials: {} }
export const TRANSPARENT_TEXTURE = new Texture(
{
  id: `${PACKAGE.name}:transparent_texture`,
    name: 'Transparent',
  },
  '797174ae-5c58-4a83-a630-eefd51007c80'
)
Project = OLD_PROJECT

SnaveSutit avatar Apr 27 '24 17:04 SnaveSutit

Deploy Preview for blockbench-dev ready!

Name Link
Latest commit c991aaed9f54006dbe68456ccc945c720e6061d5
Latest deploy log https://app.netlify.com/sites/blockbench-dev/deploys/662d3bec5231bc00081996da
Deploy Preview https://deploy-preview-2303--blockbench-dev.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Apr 27 '24 17:04 netlify[bot]

Closed due to discussion with Jannis on Discord image

SnaveSutit avatar Apr 29 '24 12:04 SnaveSutit