mc-assets 0.1.5 → 0.1.7
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 +170 -5
- package/dist/atlasCreator.d.ts +1 -0
- package/dist/atlasCreator.js +13 -9
- package/dist/atlasParser.js +5 -18
- package/dist/blockStatesModels.json +12228 -422
- package/dist/blocksAtlasLatest.png +0 -0
- package/dist/blocksAtlases.json +390 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +18 -0
- package/package.json +3 -2
package/README.MD
CHANGED
|
@@ -16,8 +16,8 @@ npm i mc-assets
|
|
|
16
16
|
- **Version Accurate** - Includes all released versions starting from 1.7.10.
|
|
17
17
|
- **Memory Efficient** - Small installation size, for the fastest download & loading time.
|
|
18
18
|
- **Simple & Complete API** - Works in browsers out of the box and provides parsers for all the data this library provides.
|
|
19
|
-
- **Easy to Use Items Textures** - Includes hand-crafted isometric textures for some blocks
|
|
20
|
-
|
|
19
|
+
- **Easy to Use Items Textures** - Includes hand-crafted isometric textures for some blocks.
|
|
20
|
+
- **Block Entities Models** - Includes community-crafted models for block entities.
|
|
21
21
|
|
|
22
22
|
This module was originally designed as standalone package for [https://mcraft.fun](mcraft.fun) (repo) project so it is easier to maintain, but now it became a library that I think can cover any use case where you need to work with minecraft assets. This library means block states, models data and texture contents, it doesn't cover minecraft-data use cases.
|
|
23
23
|
|
|
@@ -25,17 +25,182 @@ This module was originally designed as standalone package for [https://mcraft.fu
|
|
|
25
25
|
> Tested on Node.js 18 and above.
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
All blockstates + models + all atlas textures for all versions bundled (uncompressed): 4.
|
|
28
|
+
All blockstates + models + all atlas textures for all versions bundled with rsbuild (uncompressed): 4.73 MB.
|
|
29
29
|
|
|
30
30
|
This packages includes versions for: 1.7.10, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.10, 1.10.1, 1.10.2, 1.11, 1.11.1, 1.11.2, 1.12, 1.12.1, 1.12.2, 1.13, 1.13.1, 1.13.2, 1.14, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.15, 1.15.1, 1.15.2, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.17, 1.17.1, 1.18, 1.18.1, 1.18.2, 1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6, 1.21.
|
|
31
31
|
|
|
32
|
+
<details>
|
|
33
|
+
<summary>Included Block Entities (Additional Block Models) (130):</summary>
|
|
34
|
+
|
|
35
|
+
- ✅ sign
|
|
36
|
+
- ✅ wall_sign
|
|
37
|
+
- ✅ acacia_sign
|
|
38
|
+
- ✅ acacia_wall_sign
|
|
39
|
+
- ✅ birch_sign
|
|
40
|
+
- ✅ birch_wall_sign
|
|
41
|
+
- ✅ dark_oak_sign
|
|
42
|
+
- ✅ dark_oak_wall_sign
|
|
43
|
+
- ✅ jungle_sign
|
|
44
|
+
- ✅ jungle_wall_sign
|
|
45
|
+
- ✅ oak_sign
|
|
46
|
+
- ✅ oak_wall_sign
|
|
47
|
+
- ✅ spruce_sign
|
|
48
|
+
- ✅ spruce_wall_sign
|
|
49
|
+
- ✅ crimson_sign
|
|
50
|
+
- ✅ crimson_wall_sign
|
|
51
|
+
- ✅ warped_sign
|
|
52
|
+
- ✅ warped_wall_sign
|
|
53
|
+
- ✅ mangrove_sign
|
|
54
|
+
- ✅ mangrove_wall_sign
|
|
55
|
+
- ✅ decorated_pot
|
|
56
|
+
- ✅ acacia_hanging_sign
|
|
57
|
+
- ✅ acacia_wall_hanging_sign
|
|
58
|
+
- ✅ bamboo_hanging_sign
|
|
59
|
+
- ✅ bamboo_sign
|
|
60
|
+
- ✅ bamboo_wall_hanging_sign
|
|
61
|
+
- ✅ bamboo_wall_sign
|
|
62
|
+
- ✅ birch_hanging_sign
|
|
63
|
+
- ✅ birch_wall_hanging_sign
|
|
64
|
+
- ✅ cherry_hanging_sign
|
|
65
|
+
- ✅ cherry_sign
|
|
66
|
+
- ✅ cherry_wall_hanging_sign
|
|
67
|
+
- ✅ cherry_wall_sign
|
|
68
|
+
- ✅ crimson_hanging_sign
|
|
69
|
+
- ✅ crimson_wall_hanging_sign
|
|
70
|
+
- ✅ dark_oak_hanging_sign
|
|
71
|
+
- ✅ dark_oak_wall_hanging_sign
|
|
72
|
+
- ✅ jungle_hanging_sign
|
|
73
|
+
- ✅ jungle_wall_hanging_sign
|
|
74
|
+
- ✅ mangrove_hanging_sign
|
|
75
|
+
- ✅ mangrove_wall_hanging_sign
|
|
76
|
+
- ✅ oak_hanging_sign
|
|
77
|
+
- ✅ oak_wall_hanging_sign
|
|
78
|
+
- ✅ spruce_hanging_sign
|
|
79
|
+
- ✅ spruce_wall_hanging_sign
|
|
80
|
+
- ✅ warped_hanging_sign
|
|
81
|
+
- ✅ warped_wall_hanging_sign
|
|
82
|
+
- ✅ black_banner
|
|
83
|
+
- ✅ black_bed
|
|
84
|
+
- ✅ black_shulker_box
|
|
85
|
+
- ✅ black_wall_banner
|
|
86
|
+
- ✅ blue_banner
|
|
87
|
+
- ✅ blue_bed
|
|
88
|
+
- ✅ blue_shulker_box
|
|
89
|
+
- ✅ blue_wall_banner
|
|
90
|
+
- ✅ brown_banner
|
|
91
|
+
- ✅ brown_bed
|
|
92
|
+
- ✅ brown_shulker_box
|
|
93
|
+
- ✅ brown_wall_banner
|
|
94
|
+
- ✅ bubble_column
|
|
95
|
+
- ✅ chest
|
|
96
|
+
- ✅ creeper_head
|
|
97
|
+
- ✅ creeper_wall_head
|
|
98
|
+
- ✅ cyan_banner
|
|
99
|
+
- ✅ cyan_bed
|
|
100
|
+
- ✅ cyan_shulker_box
|
|
101
|
+
- ✅ cyan_wall_banner
|
|
102
|
+
- ✅ dragon_head
|
|
103
|
+
- ✅ dragon_wall_head
|
|
104
|
+
- ✅ ender_chest
|
|
105
|
+
- ✅ gray_banner
|
|
106
|
+
- ✅ gray_bed
|
|
107
|
+
- ✅ gray_shulker_box
|
|
108
|
+
- ✅ gray_wall_banner
|
|
109
|
+
- ✅ green_banner
|
|
110
|
+
- ✅ green_bed
|
|
111
|
+
- ✅ green_shulker_box
|
|
112
|
+
- ✅ green_wall_banner
|
|
113
|
+
- ✅ light_blue_banner
|
|
114
|
+
- ✅ light_blue_bed
|
|
115
|
+
- ✅ light_blue_shulker_box
|
|
116
|
+
- ✅ light_blue_wall_banner
|
|
117
|
+
- ✅ light_gray_banner
|
|
118
|
+
- ✅ light_gray_bed
|
|
119
|
+
- ✅ light_gray_shulker_box
|
|
120
|
+
- ✅ light_gray_wall_banner
|
|
121
|
+
- ✅ lime_banner
|
|
122
|
+
- ✅ lime_bed
|
|
123
|
+
- ✅ lime_shulker_box
|
|
124
|
+
- ✅ lime_wall_banner
|
|
125
|
+
- ✅ magenta_banner
|
|
126
|
+
- ✅ magenta_bed
|
|
127
|
+
- ✅ magenta_shulker_box
|
|
128
|
+
- ✅ magenta_wall_banner
|
|
129
|
+
- ✅ orange_banner
|
|
130
|
+
- ✅ orange_bed
|
|
131
|
+
- ✅ orange_shulker_box
|
|
132
|
+
- ✅ orange_wall_banner
|
|
133
|
+
- ✅ piglin_head
|
|
134
|
+
- ✅ piglin_wall_head
|
|
135
|
+
- ✅ pink_banner
|
|
136
|
+
- ✅ pink_bed
|
|
137
|
+
- ✅ pink_shulker_box
|
|
138
|
+
- ✅ pink_wall_banner
|
|
139
|
+
- ✅ player_head
|
|
140
|
+
- ✅ player_wall_head
|
|
141
|
+
- ✅ purple_banner
|
|
142
|
+
- ✅ purple_bed
|
|
143
|
+
- ✅ purple_shulker_box
|
|
144
|
+
- ✅ purple_wall_banner
|
|
145
|
+
- ✅ red_banner
|
|
146
|
+
- ✅ red_bed
|
|
147
|
+
- ✅ red_shulker_box
|
|
148
|
+
- ✅ red_wall_banner
|
|
149
|
+
- ✅ shulker_box
|
|
150
|
+
- ✅ skeleton_skull
|
|
151
|
+
- ✅ skeleton_wall_skull
|
|
152
|
+
- ✅ trapped_chest
|
|
153
|
+
- ✅ white_banner
|
|
154
|
+
- ✅ white_bed
|
|
155
|
+
- ✅ white_shulker_box
|
|
156
|
+
- ✅ white_wall_banner
|
|
157
|
+
- ✅ wither_skeleton_skull
|
|
158
|
+
- ✅ wither_skeleton_wall_skull
|
|
159
|
+
- ✅ yellow_banner
|
|
160
|
+
- ✅ yellow_bed
|
|
161
|
+
- ✅ yellow_shulker_box
|
|
162
|
+
- ✅ yellow_wall_banner
|
|
163
|
+
- ✅ zombie_head
|
|
164
|
+
- ✅ zombie_wall_head
|
|
165
|
+
- ❌ black_candle
|
|
166
|
+
- ❌ blue_candle
|
|
167
|
+
- ❌ brown_candle
|
|
168
|
+
- ❌ candle
|
|
169
|
+
- ❌ cyan_candle
|
|
170
|
+
- ❌ end_gateway
|
|
171
|
+
- ❌ end_portal
|
|
172
|
+
- ❌ gray_candle
|
|
173
|
+
- ❌ green_candle
|
|
174
|
+
- ❌ light_blue_candle
|
|
175
|
+
- ❌ light_gray_candle
|
|
176
|
+
- ❌ lime_candle
|
|
177
|
+
- ❌ magenta_candle
|
|
178
|
+
- ❌ orange_candle
|
|
179
|
+
- ❌ pink_candle
|
|
180
|
+
- ❌ pink_petals
|
|
181
|
+
- ❌ powder_snow_cauldron
|
|
182
|
+
- ❌ purple_candle
|
|
183
|
+
- ❌ red_candle
|
|
184
|
+
- ❌ repeater
|
|
185
|
+
- ❌ sea_pickle
|
|
186
|
+
- ❌ structure_void
|
|
187
|
+
- ❌ turtle_egg
|
|
188
|
+
- ❌ water_cauldron
|
|
189
|
+
- ❌ white_candle
|
|
190
|
+
- ❌ yellow_candle
|
|
191
|
+
|
|
192
|
+
</details>
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
[Atlas explorer (web demo)](https://zardoy.github.io/mc-assets/).
|
|
32
197
|
|
|
33
198
|
## Usage
|
|
34
199
|
|
|
35
200
|
Following atlases are generated:
|
|
36
201
|
|
|
37
202
|
- Items
|
|
38
|
-
- Blocks
|
|
203
|
+
- Blocks (block entities included)
|
|
39
204
|
- Particles
|
|
40
205
|
|
|
41
206
|
```ts
|
|
@@ -148,4 +313,4 @@ const ButtonHighlighted = styled(Button)`
|
|
|
148
313
|
`
|
|
149
314
|
```
|
|
150
315
|
|
|
151
|
-
|
|
316
|
+
Please, don't use json / image files directly as their format is not stable and can change in the future, use the parsers instead.
|
package/dist/atlasCreator.d.ts
CHANGED
package/dist/atlasCreator.js
CHANGED
|
@@ -16,7 +16,7 @@ export const getAtlasSize = (numberOfTiles, tileSize) => {
|
|
|
16
16
|
height: size * tileSize
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
export const makeTextureAtlas = ({ input, getLoadedImage, tileSize = 16, getCanvas = () => document.createElement('canvas'), }) => {
|
|
19
|
+
export const makeTextureAtlas = ({ input, getLoadedImage, tileSize = 16, getCanvas = (imgSize) => typeof document !== 'undefined' && document.createElement ? document.createElement('canvas') : new globalThis.Canvas(imgSize, imgSize, 'png'), }) => {
|
|
20
20
|
const tilesCount = input.length;
|
|
21
21
|
const imgSize = getAtlasSize(tilesCount, tileSize).width;
|
|
22
22
|
const MAX_CANVAS_SIZE = 16_384;
|
|
@@ -58,11 +58,14 @@ export const makeTextureAtlas = ({ input, getLoadedImage, tileSize = 16, getCanv
|
|
|
58
58
|
let renderWidth = tileSize * (inputData.tileWidthMult ?? 1);
|
|
59
59
|
let renderHeight = tileSize;
|
|
60
60
|
if (inputData.useOriginalSize || inputData.renderWidth || inputData.renderHeight) {
|
|
61
|
+
const texWidth = inputData.renderWidth ?? img.width;
|
|
62
|
+
const texHeight = inputData.renderHeight ?? img.height;
|
|
61
63
|
// todo check have enough space
|
|
62
|
-
renderWidth = Math.ceil(
|
|
63
|
-
renderHeight = Math.ceil(
|
|
64
|
-
su =
|
|
65
|
-
sv =
|
|
64
|
+
renderWidth = Math.ceil(texWidth / tileSize) * tileSize;
|
|
65
|
+
renderHeight = Math.ceil(texHeight / tileSize) * tileSize;
|
|
66
|
+
su = texWidth / imgSize;
|
|
67
|
+
sv = texHeight / imgSize;
|
|
68
|
+
// renderWidth and renderHeight take full tile size so everything is aligned to the grid
|
|
66
69
|
if (renderHeight > imgSize || renderWidth > imgSize) {
|
|
67
70
|
throw new Error('Texture ' + keyValue + ' is too big');
|
|
68
71
|
}
|
|
@@ -81,8 +84,8 @@ export const makeTextureAtlas = ({ input, getLoadedImage, tileSize = 16, getCanv
|
|
|
81
84
|
goToNextRow();
|
|
82
85
|
}
|
|
83
86
|
const renderSourceDefaultSize = Math.min(img.width, img.height);
|
|
84
|
-
const renderSourceWidth = inputData.renderSourceWidth ?? renderSourceDefaultSize;
|
|
85
|
-
const renderSourceHeight = inputData.renderSourceHeight ?? renderSourceDefaultSize;
|
|
87
|
+
const renderSourceWidth = inputData.useOriginalSize ? img.width : inputData.renderSourceWidth ?? renderSourceDefaultSize;
|
|
88
|
+
const renderSourceHeight = inputData.useOriginalSize ? img.height : inputData.renderSourceHeight ?? renderSourceDefaultSize;
|
|
86
89
|
try {
|
|
87
90
|
g.drawImage(img, inputData.renderSourceStartX ?? 0, inputData.renderSourceStartY ?? 0, renderSourceWidth, renderSourceHeight, x, y, renderWidth, renderHeight);
|
|
88
91
|
}
|
|
@@ -98,12 +101,13 @@ export const makeTextureAtlas = ({ input, getLoadedImage, tileSize = 16, getCanv
|
|
|
98
101
|
...su == suSv && sv == suSv ? {} : {
|
|
99
102
|
su,
|
|
100
103
|
sv,
|
|
101
|
-
width: renderWidth,
|
|
102
|
-
height: renderHeight
|
|
104
|
+
// width: renderWidth,
|
|
105
|
+
// height: renderHeight
|
|
103
106
|
}
|
|
104
107
|
};
|
|
105
108
|
}
|
|
106
109
|
return {
|
|
110
|
+
canvas,
|
|
107
111
|
json: {
|
|
108
112
|
suSv,
|
|
109
113
|
tileSize,
|
package/dist/atlasParser.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { VersionedStore } from './versionedStore';
|
|
2
2
|
import { makeTextureAtlas } from './atlasCreator';
|
|
3
|
+
import { getLoadedImage } from './utils';
|
|
3
4
|
export class AtlasParser {
|
|
4
5
|
atlasJson;
|
|
5
6
|
latestImage;
|
|
@@ -20,7 +21,7 @@ export class AtlasParser {
|
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
23
|
addByVersion(this.atlasStore, 'latest', itemsAtlases.latest.textures, 'latest');
|
|
23
|
-
this.atlasHasLegacyImage = !!
|
|
24
|
+
this.atlasHasLegacyImage = !!legacyImage;
|
|
24
25
|
if (legacyImage && itemsAtlases.legacy) {
|
|
25
26
|
for (const key of Object.keys(itemsAtlases.legacy.textures)) {
|
|
26
27
|
const [version, name] = key.split('/');
|
|
@@ -81,13 +82,8 @@ export class AtlasParser {
|
|
|
81
82
|
img: image
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
const { json } = makeTextureAtlas({
|
|
85
|
+
const { json, canvas } = makeTextureAtlas({
|
|
86
86
|
input: Object.keys(newTextures),
|
|
87
|
-
getCanvas() {
|
|
88
|
-
canvas = document.createElement('canvas');
|
|
89
|
-
return canvas;
|
|
90
|
-
},
|
|
91
87
|
getLoadedImage: (name) => {
|
|
92
88
|
const texture = newTextures[name];
|
|
93
89
|
const image = texture.img;
|
|
@@ -96,8 +92,8 @@ export class AtlasParser {
|
|
|
96
92
|
delete texture.img;
|
|
97
93
|
return {
|
|
98
94
|
image,
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
renderWidth: texture.su * imgSize,
|
|
96
|
+
renderHeight: texture.sv * imgSize,
|
|
101
97
|
renderSourceStartX: texture.u * imgSize,
|
|
102
98
|
renderSourceStartY: texture.v * imgSize,
|
|
103
99
|
renderSourceWidth: texture.su * imgSize,
|
|
@@ -122,12 +118,3 @@ export class AtlasParser {
|
|
|
122
118
|
};
|
|
123
119
|
}
|
|
124
120
|
}
|
|
125
|
-
const getLoadedImage = async (url) => {
|
|
126
|
-
const img = new Image();
|
|
127
|
-
img.src = url;
|
|
128
|
-
await new Promise((resolve, reject) => {
|
|
129
|
-
img.onload = resolve;
|
|
130
|
-
img.onerror = reject;
|
|
131
|
-
});
|
|
132
|
-
return img;
|
|
133
|
-
};
|