mc-assets 0.1.7 → 0.2.0
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.
- package/README.MD +90 -76
- package/dist/assetsParser.d.ts +23 -31
- package/dist/assetsParser.js +78 -58
- package/dist/blockStatesModels.json +8321 -0
- package/dist/itemsRenderer.js +3 -2
- package/dist/types.d.ts +3 -3
- package/dist/worldBlockProvider.d.ts +5 -3
- package/dist/worldBlockProvider.js +49 -45
- package/package.json +4 -2
package/dist/itemsRenderer.js
CHANGED
|
@@ -35,11 +35,12 @@ export class ItemsRenderer {
|
|
|
35
35
|
tryGetFullBlock(blockName, properties = {}) {
|
|
36
36
|
if (!this.blocksAtlasParser)
|
|
37
37
|
return;
|
|
38
|
-
const
|
|
38
|
+
const resolvedModelParts = this.assetsParser.getResolvedModelFirst({
|
|
39
39
|
name: blockName,
|
|
40
40
|
properties,
|
|
41
41
|
}, true);
|
|
42
|
-
|
|
42
|
+
const resolvedModel = resolvedModelParts?.[0];
|
|
43
|
+
if (resolvedModel?.elements?.length !== 1)
|
|
43
44
|
return;
|
|
44
45
|
const elem = resolvedModel.elements[0];
|
|
45
46
|
if (elem.from[0] !== 0 || elem.from[1] !== 0 || elem.from[2] !== 0)
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
type ModelBasic = {
|
|
2
2
|
model: string;
|
|
3
3
|
x?: number;
|
|
4
|
+
z?: number;
|
|
4
5
|
y?: number;
|
|
5
6
|
uvlock?: boolean;
|
|
7
|
+
/** only for array models */
|
|
8
|
+
weight?: number;
|
|
6
9
|
};
|
|
7
10
|
export type BlockApplyModel = ModelBasic | (ModelBasic & {
|
|
8
11
|
weight: any;
|
|
@@ -51,9 +54,6 @@ export type BlockModel = {
|
|
|
51
54
|
};
|
|
52
55
|
}[];
|
|
53
56
|
ambientocclusion?: boolean;
|
|
54
|
-
x?: number;
|
|
55
|
-
y?: number;
|
|
56
|
-
z?: number;
|
|
57
57
|
ao?: boolean;
|
|
58
58
|
};
|
|
59
59
|
type DisplayPresentation = {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { QueriedBlock } from './assetsParser';
|
|
2
2
|
export default function worldBlockProvider(blockstatesModels: any, blocksAtlas: any, version: string): {
|
|
3
|
-
|
|
3
|
+
getAllResolvedModels0_1(block: Omit<QueriedBlock, "stateId">, fallbackVariant?: boolean): {
|
|
4
|
+
ao?: boolean;
|
|
4
5
|
x?: number;
|
|
5
6
|
y?: number;
|
|
6
7
|
z?: number;
|
|
7
|
-
|
|
8
|
+
uvlock?: boolean;
|
|
9
|
+
weight?: number;
|
|
8
10
|
elements: {
|
|
9
11
|
faces: {
|
|
10
12
|
[k: string]: {
|
|
@@ -31,7 +33,7 @@ export default function worldBlockProvider(blockstatesModels: any, blocksAtlas:
|
|
|
31
33
|
rescale?: boolean;
|
|
32
34
|
};
|
|
33
35
|
}[] | undefined;
|
|
34
|
-
};
|
|
36
|
+
}[][];
|
|
35
37
|
getTextureInfo(textureName: string): {
|
|
36
38
|
su: number;
|
|
37
39
|
sv: number;
|
|
@@ -7,54 +7,58 @@ export default function worldBlockProvider(blockstatesModels, blocksAtlas, versi
|
|
|
7
7
|
const assetsParser = new AssetsParser(version, blockStatesStore, blockModelsStore);
|
|
8
8
|
const atlasParser = new AtlasParser(blocksAtlas, 'latest', 'legacy');
|
|
9
9
|
return {
|
|
10
|
-
|
|
11
|
-
const
|
|
10
|
+
getAllResolvedModels0_1(block, fallbackVariant = false) {
|
|
11
|
+
const modelsParts = assetsParser.getAllResolvedModels(block, fallbackVariant) ?? [];
|
|
12
12
|
const interestedFaces = ['north', 'east', 'south', 'west', 'up', 'down'];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
elements: elements?.map((elem) => {
|
|
13
|
+
return modelsParts.map(modelVariants => {
|
|
14
|
+
return modelVariants.map(model => {
|
|
15
|
+
const { elements, textures, ...rest } = model;
|
|
17
16
|
return {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
17
|
+
// todo validate elements
|
|
18
|
+
elements: elements?.map((elem) => {
|
|
19
|
+
return {
|
|
20
|
+
...elem,
|
|
21
|
+
faces: Object.fromEntries(Object.entries(elem.faces).map(([faceName, face]) => {
|
|
22
|
+
const texture = face.texture;
|
|
23
|
+
if (!texture)
|
|
24
|
+
throw new Error(`Missing resolved texture ${texture} for face ${faceName} of ${block.name}`);
|
|
25
|
+
const finalTexture = this.getTextureInfo(texture);
|
|
26
|
+
if (!finalTexture)
|
|
27
|
+
throw new Error(`Missing texture data ${texture} for ${block.name}`);
|
|
28
|
+
const _from = elem.from;
|
|
29
|
+
const _to = elem.to;
|
|
30
|
+
// taken from https://github.com/DragonDev1906/Minecraft-Overviewer/
|
|
31
|
+
const COORDINATE_MAX = 16;
|
|
32
|
+
const uv = (face.uv || {
|
|
33
|
+
// default UVs
|
|
34
|
+
// format: [u1, v1, u2, v2] (u = x, v = y)
|
|
35
|
+
north: [_to[0], COORDINATE_MAX - _to[1], _from[0], COORDINATE_MAX - _from[1]],
|
|
36
|
+
east: [_from[2], COORDINATE_MAX - _to[1], _to[2], COORDINATE_MAX - _from[1]],
|
|
37
|
+
south: [_from[0], COORDINATE_MAX - _to[1], _to[0], COORDINATE_MAX - _from[1]],
|
|
38
|
+
west: [_from[2], COORDINATE_MAX - _to[1], _to[2], COORDINATE_MAX - _from[1]],
|
|
39
|
+
up: [_from[0], _from[2], _to[0], _to[2]],
|
|
40
|
+
down: [_to[0], _from[2], _from[0], _to[2]]
|
|
41
|
+
}[faceName]);
|
|
42
|
+
const su = (uv[2] - uv[0]) / COORDINATE_MAX * finalTexture.su;
|
|
43
|
+
const sv = (uv[3] - uv[1]) / COORDINATE_MAX * finalTexture.sv;
|
|
44
|
+
return [faceName, {
|
|
45
|
+
...face,
|
|
46
|
+
texture: {
|
|
47
|
+
u: finalTexture.u + uv[0] / 16 * finalTexture.su,
|
|
48
|
+
v: finalTexture.v + uv[1] / 16 * finalTexture.sv,
|
|
49
|
+
su,
|
|
50
|
+
sv,
|
|
51
|
+
tileIndex: finalTexture.tileIndex,
|
|
52
|
+
debugName: texture,
|
|
53
|
+
},
|
|
54
|
+
}];
|
|
55
|
+
}))
|
|
56
|
+
};
|
|
57
|
+
}),
|
|
58
|
+
...rest
|
|
54
59
|
};
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
};
|
|
60
|
+
});
|
|
61
|
+
});
|
|
58
62
|
},
|
|
59
63
|
getTextureInfo(textureName) {
|
|
60
64
|
return atlasParser.getTextureInfo(textureName.replace('block/', ''), version);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mc-assets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"author": "Vitaly Turovsky <vital2580@icloud.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -48,7 +48,9 @@
|
|
|
48
48
|
"minecraft items",
|
|
49
49
|
"minecraft colors",
|
|
50
50
|
"minecraft parser",
|
|
51
|
-
"minecraft extracter"
|
|
51
|
+
"minecraft extracter",
|
|
52
|
+
"minecraft block model parser",
|
|
53
|
+
"minecraft block entity"
|
|
52
54
|
],
|
|
53
55
|
"repository": "https://github.com/zardoy/mc-assets",
|
|
54
56
|
"scripts": {
|