mc-assets 0.2.28 → 0.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ export declare class ItemsRenderer {
14
14
  type: string;
15
15
  /** @deprecated */
16
16
  path: string;
17
- };
17
+ } | undefined;
18
18
  tryGetFullBlock(blockName: string, properties?: Record<string, string | boolean>): {
19
19
  top: {
20
20
  slice: [number, number, number, number];
@@ -35,7 +35,7 @@ export declare class ItemsRenderer {
35
35
  path: string;
36
36
  };
37
37
  } | undefined;
38
- getItemTexture(itemName: string, properties?: Record<string, string | boolean>): {
38
+ getItemTexture(itemNameOrModel: string, properties?: Record<string, string | boolean>, exactItemResolve?: boolean): {
39
39
  slice: [number, number, number, number];
40
40
  type: string;
41
41
  /** @deprecated */
@@ -19,6 +19,8 @@ export class ItemsRenderer {
19
19
  const type = texture.includes('items/') ? 'items' : (texture.includes('block/') || texture.includes('blocks/')) ? 'blocks' : 'items';
20
20
  const atlasParser = type === 'blocks' ? this.blocksAtlasParser : this.itemsAtlasParser;
21
21
  const textureInfo = atlasParser.getTextureInfo(texture.replace('block/', '').replace('blocks/', '').replace('item/', '').replace('items/', ''), this.version);
22
+ if (!textureInfo)
23
+ return;
22
24
  const atlas = atlasParser.atlas[textureInfo.imageType];
23
25
  return {
24
26
  slice: [
@@ -51,32 +53,43 @@ export class ItemsRenderer {
51
53
  const rightTexture = elem.faces.north?.texture ?? elem.faces.right?.texture ?? elem.faces.side?.texture;
52
54
  if (!topTexture || !leftTexture || !rightTexture)
53
55
  return;
56
+ const topTextureResolved = this.resolveTexture(topTexture);
57
+ if (!topTextureResolved)
58
+ throw new Error(`Missing texture for ${blockName} top texture`);
59
+ const leftTextureResolved = this.resolveTexture(leftTexture);
60
+ if (!leftTextureResolved)
61
+ throw new Error(`Missing texture for ${blockName} left texture`);
62
+ const rightTextureResolved = this.resolveTexture(rightTexture);
63
+ if (!rightTextureResolved)
64
+ throw new Error(`Missing texture for ${blockName} right texture`);
54
65
  return {
55
- top: this.resolveTexture(topTexture),
56
- left: this.resolveTexture(leftTexture),
57
- right: this.resolveTexture(rightTexture),
66
+ top: topTextureResolved,
67
+ left: leftTextureResolved,
68
+ right: rightTextureResolved,
58
69
  };
59
70
  }
60
- getItemTexture(itemName, properties = {}) {
71
+ getItemTexture(itemNameOrModel, properties = {}, exactItemResolve = false) {
72
+ itemNameOrModel = itemNameOrModel.replace(/^minecraft:/, '');
61
73
  let model;
62
- if (itemName.includes('/')) {
63
- model = this.modelsStore.get(this.version, itemName);
74
+ if (itemNameOrModel.includes('/') || exactItemResolve) {
75
+ model = this.modelsStore.get(this.version, itemNameOrModel);
64
76
  }
65
77
  else {
66
- model = this.modelsStore.get(this.version, `item/${itemName}`);
78
+ model = this.modelsStore.get(this.version, `item/${itemNameOrModel}`);
67
79
  if (!model || model.parent?.includes('block/')) {
68
- return this.tryGetFullBlock(itemName, properties);
80
+ return this.tryGetFullBlock(itemNameOrModel, properties);
69
81
  }
70
82
  }
71
83
  if (!model)
72
84
  return;
73
- const texture = itemName.includes('block/') ?
85
+ const texture = itemNameOrModel.includes('block/') ?
74
86
  // first defined block texture
75
87
  Object.values(model.textures ?? {})[0] :
76
88
  model.textures?.layer0; // classic item texture
77
89
  if (!texture)
78
90
  return;
79
- return this.resolveTexture(texture);
91
+ return (texture.startsWith('invsprite_') ? this.resolveTexture(texture.replace('invsprite_', '')) : undefined)
92
+ ?? this.resolveTexture(texture);
80
93
  // const {resolvedModel} = this.assetsParser.getResolvedModelByModelName('item/' + itemName, itemName) ?? {}
81
94
  // resolvedModel?.textures['layer0']
82
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mc-assets",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
4
4
  "author": "Vitaly Turovsky <vital2580@icloud.com>",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  "@xmcl/core": "^2.13.0",
16
16
  "@xmcl/installer": "^5.4.0",
17
17
  "@zardoy/tsconfig": "^1.5.1",
18
- "canvas": "^2.11.2",
18
+ "canvas": "^3.1.0",
19
19
  "filesize": "^10.1.4",
20
20
  "imagemin": "^9.0.0",
21
21
  "imagemin-optipng": "^8.0.0",