minerender 2.1.0-alpha.77 → 2.1.0-alpha.78
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/dist/browser/index.d.mts +57 -2
- package/dist/browser/index.d.ts +57 -2
- package/dist/browser/index.js +127 -3
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +127 -3
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +127 -3
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +57 -2
- package/dist/node/index.d.ts +57 -2
- package/dist/node/index.js +128 -3
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +127 -3
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -93757,6 +93757,7 @@ ${shader.fragmentShader}`.replace(
|
|
|
93757
93757
|
Env: () => Env,
|
|
93758
93758
|
FluidModelObject: () => FluidModelObject,
|
|
93759
93759
|
Fonts: () => Fonts,
|
|
93760
|
+
GUI_CONTAINER_LAYOUTS: () => GUI_CONTAINER_LAYOUTS,
|
|
93760
93761
|
Geometries: () => Geometries,
|
|
93761
93762
|
GuiHelper: () => GuiHelper,
|
|
93762
93763
|
GuiLight: () => GuiLight,
|
|
@@ -97340,6 +97341,7 @@ property list uchar int vertex_index
|
|
|
97340
97341
|
init_buffer2();
|
|
97341
97342
|
init_process2();
|
|
97342
97343
|
init_AssetKey();
|
|
97344
|
+
init_ModelTextures();
|
|
97343
97345
|
|
|
97344
97346
|
// src/gui/GuiText.ts
|
|
97345
97347
|
init_dirname();
|
|
@@ -97452,7 +97454,128 @@ property list uchar int vertex_index
|
|
|
97452
97454
|
}
|
|
97453
97455
|
|
|
97454
97456
|
// src/gui/GuiHelper.ts
|
|
97457
|
+
var GUI_CONTAINER_LAYOUTS = {
|
|
97458
|
+
generic_54: {
|
|
97459
|
+
texture: "minecraft:gui/container/generic_54",
|
|
97460
|
+
crop: [0, 0, 176, 222],
|
|
97461
|
+
slotOrigin: [8, 18],
|
|
97462
|
+
slotOffset: [18, 18],
|
|
97463
|
+
rowSize: 9,
|
|
97464
|
+
slotCount: 54
|
|
97465
|
+
},
|
|
97466
|
+
crafting_table: {
|
|
97467
|
+
texture: "minecraft:gui/container/crafting_table",
|
|
97468
|
+
crop: [0, 0, 176, 166],
|
|
97469
|
+
slotOrigin: [30, 17],
|
|
97470
|
+
slotOffset: [18, 18],
|
|
97471
|
+
rowSize: 3,
|
|
97472
|
+
slotCount: 9,
|
|
97473
|
+
resultPosition: [124, 35]
|
|
97474
|
+
}
|
|
97475
|
+
};
|
|
97455
97476
|
var GuiHelper = class {
|
|
97477
|
+
/**
|
|
97478
|
+
* Creates a 182×5 boss bar using the active resource pack. Finite progress is clamped to 0–1.
|
|
97479
|
+
* The fill crops the source image; explicit crops do not apply `.mcmeta` sprite scaling.
|
|
97480
|
+
*/
|
|
97481
|
+
static async bossBar(options = {}) {
|
|
97482
|
+
const { color: color3 = "pink", progress = 1, position = [0, 0] } = options;
|
|
97483
|
+
this.validatePosition(position);
|
|
97484
|
+
if (!["pink", "blue", "red", "green", "yellow", "purple", "white"].includes(color3)) {
|
|
97485
|
+
throw new Error(`Unsupported boss bar color: ${color3}`);
|
|
97486
|
+
}
|
|
97487
|
+
if (!Number.isFinite(progress)) throw new Error("Boss bar progress must be finite");
|
|
97488
|
+
const value = Math.max(0, Math.min(1, progress));
|
|
97489
|
+
const width = value > 0 ? Math.floor(value * 181) + 1 : 0;
|
|
97490
|
+
const texture = `minecraft:gui/sprites/boss_bar/${color3}`;
|
|
97491
|
+
const layers = [{
|
|
97492
|
+
name: "boss-bar-background",
|
|
97493
|
+
texture: `${texture}_background`,
|
|
97494
|
+
position: [...position],
|
|
97495
|
+
size: [182, 5]
|
|
97496
|
+
}];
|
|
97497
|
+
if (width > 0) {
|
|
97498
|
+
layers.push({
|
|
97499
|
+
...await this.cropTexture(`${texture}_progress`, [0, 0, width, 5], [182, 5], position),
|
|
97500
|
+
name: "boss-bar-progress"
|
|
97501
|
+
});
|
|
97502
|
+
}
|
|
97503
|
+
return layers;
|
|
97504
|
+
}
|
|
97505
|
+
/**
|
|
97506
|
+
* Creates a 192×192 book page with optional arrows and supplied text. Buttons are hidden by default.
|
|
97507
|
+
* Callers choose the page content and button states; this helper does not paginate or handle clicks.
|
|
97508
|
+
*/
|
|
97509
|
+
static async book(options = {}) {
|
|
97510
|
+
const {
|
|
97511
|
+
position = [0, 0],
|
|
97512
|
+
previous = "hidden",
|
|
97513
|
+
next = "hidden",
|
|
97514
|
+
text: text2,
|
|
97515
|
+
color: color3 = 0,
|
|
97516
|
+
shadow = false,
|
|
97517
|
+
maxWidth = 114,
|
|
97518
|
+
lineHeight = 9,
|
|
97519
|
+
...style
|
|
97520
|
+
} = options;
|
|
97521
|
+
this.validatePosition(position);
|
|
97522
|
+
for (const state of [previous, next]) {
|
|
97523
|
+
if (!["hidden", "normal", "hover"].includes(state)) throw new Error(`Unsupported book button state: ${state}`);
|
|
97524
|
+
}
|
|
97525
|
+
const layers = [{
|
|
97526
|
+
...await this.cropTexture("minecraft:gui/book", [0, 0, 192, 192], [256, 256], position),
|
|
97527
|
+
name: "book-background"
|
|
97528
|
+
}];
|
|
97529
|
+
for (const [name2, direction, state, x4] of [
|
|
97530
|
+
["previous", "backward", previous, 43],
|
|
97531
|
+
["next", "forward", next, 116]
|
|
97532
|
+
]) {
|
|
97533
|
+
if (state === "hidden") continue;
|
|
97534
|
+
layers.push({
|
|
97535
|
+
name: `book-${name2}`,
|
|
97536
|
+
texture: `minecraft:gui/sprites/widget/page_${direction}${state === "hover" ? "_highlighted" : ""}`,
|
|
97537
|
+
position: [position[0] + x4, position[1] + 157],
|
|
97538
|
+
size: [23, 13]
|
|
97539
|
+
});
|
|
97540
|
+
}
|
|
97541
|
+
if (text2 !== void 0) {
|
|
97542
|
+
layers.push({
|
|
97543
|
+
name: "book-text",
|
|
97544
|
+
text: text2,
|
|
97545
|
+
position: [position[0] + 36, position[1] + 30],
|
|
97546
|
+
color: color3,
|
|
97547
|
+
shadow,
|
|
97548
|
+
maxWidth,
|
|
97549
|
+
lineHeight,
|
|
97550
|
+
...style
|
|
97551
|
+
});
|
|
97552
|
+
}
|
|
97553
|
+
return layers;
|
|
97554
|
+
}
|
|
97555
|
+
/** Creates a container background. Use {@link GUI_CONTAINER_LAYOUTS} with {@link inventorySlot} to place its items. */
|
|
97556
|
+
static async container(type, position = [0, 0]) {
|
|
97557
|
+
this.validatePosition(position);
|
|
97558
|
+
if (type !== "generic_54" && type !== "crafting_table") throw new Error(`Unsupported GUI container: ${type}`);
|
|
97559
|
+
const layout = GUI_CONTAINER_LAYOUTS[type];
|
|
97560
|
+
return [{ ...await this.cropTexture(layout.texture, layout.crop, [256, 256], position), name: "background" }];
|
|
97561
|
+
}
|
|
97562
|
+
static validatePosition(position) {
|
|
97563
|
+
if (!Array.isArray(position) || position.length !== 2 || !position.every(Number.isFinite)) {
|
|
97564
|
+
throw new Error("GUI position must contain two finite coordinates");
|
|
97565
|
+
}
|
|
97566
|
+
}
|
|
97567
|
+
static async cropTexture(texture, crop, referenceSize, position) {
|
|
97568
|
+
const image = await ModelTextures.preload(AssetKey.parse("textures", texture));
|
|
97569
|
+
if (!image) throw new Error(`Could not load GUI texture ${texture}`);
|
|
97570
|
+
const [x4, y5, width, height] = crop;
|
|
97571
|
+
const scaleX = image.width / referenceSize[0], scaleY = image.height / referenceSize[1];
|
|
97572
|
+
return {
|
|
97573
|
+
texture,
|
|
97574
|
+
crop: [x4 * scaleX, y5 * scaleY, width * scaleX, height * scaleY],
|
|
97575
|
+
position: [...position],
|
|
97576
|
+
size: [width, height]
|
|
97577
|
+
};
|
|
97578
|
+
}
|
|
97456
97579
|
/** Sizes a tooltip around supplied text; the first entry is its title. */
|
|
97457
97580
|
static async tooltip(lines, options = {}) {
|
|
97458
97581
|
if (!lines.length) return [];
|
|
@@ -97487,8 +97610,9 @@ property list uchar int vertex_index
|
|
|
97487
97610
|
}
|
|
97488
97611
|
/** Creates crafting-table layers for ingredients and the result; stack counts are not drawn. */
|
|
97489
97612
|
static recipe(recipe, options = {}) {
|
|
97613
|
+
const layout = GUI_CONTAINER_LAYOUTS.crafting_table;
|
|
97490
97614
|
const layers = [
|
|
97491
|
-
{ name: "background", texture:
|
|
97615
|
+
{ name: "background", texture: layout.texture, crop: [...layout.crop] }
|
|
97492
97616
|
];
|
|
97493
97617
|
const itemKey = (ingredient) => {
|
|
97494
97618
|
const item = typeof ingredient === "string" && !ingredient.startsWith("#") ? ingredient : typeof ingredient === "object" && "item" in ingredient ? ingredient.item : options.resolveIngredient?.(ingredient);
|
|
@@ -97503,7 +97627,7 @@ property list uchar int vertex_index
|
|
|
97503
97627
|
layers.push({
|
|
97504
97628
|
name: `ingredient-${slot}`,
|
|
97505
97629
|
item: itemKey(ingredient),
|
|
97506
|
-
position: this.inventorySlot(slot,
|
|
97630
|
+
position: this.inventorySlot(slot, layout.slotOrigin, layout.slotOffset, layout.rowSize)
|
|
97507
97631
|
});
|
|
97508
97632
|
};
|
|
97509
97633
|
switch (recipe.type) {
|
|
@@ -97538,7 +97662,7 @@ property list uchar int vertex_index
|
|
|
97538
97662
|
layers.push({
|
|
97539
97663
|
name: "result",
|
|
97540
97664
|
item: itemKey("id" in recipe.result ? recipe.result.id : recipe.result.item),
|
|
97541
|
-
position: [
|
|
97665
|
+
position: [...layout.resultPosition]
|
|
97542
97666
|
});
|
|
97543
97667
|
return layers;
|
|
97544
97668
|
}
|