@adatechnology/game-items-three 0.14.0 → 0.14.1

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.
@@ -3,7 +3,7 @@ import { discardObject3D } from "@adatechnology/game-shapes-three";
3
3
  import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
4
4
  import { furnitureSpec } from "@adatechnology/game-floorplan-three";
5
5
  import { rng } from "@adatechnology/game-interactables";
6
- import { canCraft, craft, createFindsProvider, freshness as freshness2, ITEM_CATEGORIES } from "@adatechnology/game-items";
6
+ import { canCraft, craft, createFindsProvider, freshness as freshness2, ITEM_CATEGORIES, itemFluid as itemFluid2 } from "@adatechnology/game-items";
7
7
 
8
8
  // src/area-layout.ts
9
9
  var SHELF_HEIGHT = 0.9;
@@ -69,6 +69,7 @@ function shelvesLayout(items, categories) {
69
69
 
70
70
  // src/build-item.ts
71
71
  import { markKitOrigin } from "@adatechnology/game-contracts";
72
+ import { itemFluid } from "@adatechnology/game-items";
72
73
 
73
74
  // src/destruction.ts
74
75
  import { LIQUIDS } from "@adatechnology/game-fluids";
@@ -636,14 +637,15 @@ var SHELL_PART_ID = "shell";
636
637
  var WALL_SHARE = 0.9;
637
638
  var OPENING_RADIUS = 0.012;
638
639
  function itemContents(subject) {
639
- const contents = subject.model === void 0 ? void 0 : CONTENTS[subject.model];
640
+ const known = subject.model === void 0 ? void 0 : CONTENTS[subject.model];
641
+ const contents = known ?? (subject.fluid ? { liquid: subject.fluid.liquid, fill: 1, ...subject.box ? { box: true } : {} } : void 0);
640
642
  if (!contents) return void 0;
641
643
  const [width, height, depth] = subject.size;
642
644
  const radius = Math.min(width, depth) / 2;
643
645
  const innerLiters = (contents.box ? width * depth : Math.PI * radius * radius) * height * WALL_SHARE * 1e3;
644
646
  const density = LIQUIDS.find((liquid) => liquid.id === contents.liquid)?.density ?? 1e3;
645
647
  const heaviest = subject.weight === void 0 ? Infinity : subject.weight * 1e3 / density;
646
- const liters = Math.min(innerLiters * contents.fill, heaviest);
648
+ const liters = Math.min(known ? innerLiters * contents.fill : subject.fluid?.liters ?? 0, innerLiters, heaviest);
647
649
  const container = {
648
650
  capacity: innerLiters,
649
651
  liquid: contents.liquid,
@@ -654,6 +656,10 @@ function itemContents(subject) {
654
656
  };
655
657
  return { container, liquid: contents.liquid, liters };
656
658
  }
659
+ function containsOf(contents) {
660
+ const viscosity = LIQUIDS.find((liquid) => liquid.id === contents.liquid)?.viscosity ?? 1;
661
+ return { fluid: contents.liquid, liters: contents.liters, viscosity };
662
+ }
657
663
  var VESSEL_FLOORS = { cup: CUP_FLOOR_SHARE };
658
664
  function itemVessel(subject) {
659
665
  const capacity = subject.capacityLiters;
@@ -779,14 +785,23 @@ function tagForDestruction(root, options = {}) {
779
785
  if (powder) mesh.userData.destructionPowder = { color: powder.color };
780
786
  solid.push(mesh);
781
787
  });
782
- if (!rule?.welded || solid.length < 2) return;
783
- const anchor = solid.reduce((largest, mesh) => volumeOf(mesh) > volumeOf(largest) ? mesh : largest);
788
+ const largest = () => solid.reduce((big, mesh) => volumeOf(mesh) > volumeOf(big) ? mesh : big);
789
+ if (!rule?.welded || solid.length < 2) {
790
+ const held = options.fluid && size !== void 0 && solid.length > 0 ? itemContents({ size, ...weight === void 0 ? {} : { weight }, fluid: options.fluid }) : void 0;
791
+ if (!held) return;
792
+ const body2 = largest();
793
+ body2.userData.destructionPart = { id: SHELL_PART_ID };
794
+ body2.userData.hollow = true;
795
+ body2.userData.destructionContains = containsOf(held);
796
+ return;
797
+ }
798
+ const anchor = largest();
784
799
  solid.forEach((mesh, index) => {
785
800
  mesh.userData.destructionPart = mesh === anchor ? { id: SHELL_PART_ID } : { id: `shell_${index}`, parent: SHELL_PART_ID, kind: "weld" };
786
801
  if (rule.wall) mesh.userData.destructionThickness = mesh === anchor ? rule.wall.body : rule.wall.ends;
787
802
  });
788
803
  const contents = size === void 0 ? void 0 : itemContents({ ...modelId === void 0 ? {} : { model: modelId }, size, ...weight === void 0 ? {} : { weight } });
789
- if (contents) anchor.userData.destructionContains = { fluid: contents.liquid, liters: contents.liters };
804
+ if (contents) anchor.userData.destructionContains = containsOf(contents);
790
805
  }
791
806
 
792
807
  // src/kit.ts
@@ -7420,7 +7435,8 @@ function buildItem(T, item, options = {}) {
7420
7435
  const materials = kit.materials.slice(first);
7421
7436
  if (options.wear) setWear(materials, options.wear);
7422
7437
  root.userData.wear = options.wear ?? 0;
7423
- if (options.destructible) tagForDestruction(root, { ...kind === "model" && item.model !== void 0 ? { modelId: item.model } : {}, ...shape === void 0 ? {} : { shapeId: shape }, ...item.weight === void 0 ? {} : { weight: item.weight }, size: item.size, ...item.powder ? { powder: item.powder } : {}, ...item.parts ? { parts: item.parts } : {}, three: T });
7438
+ const held = itemFluid(item);
7439
+ if (options.destructible) tagForDestruction(root, { ...kind === "model" && item.model !== void 0 ? { modelId: item.model } : {}, ...shape === void 0 ? {} : { shapeId: shape }, ...item.weight === void 0 ? {} : { weight: item.weight }, size: item.size, ...item.powder ? { powder: item.powder } : {}, ...item.parts ? { parts: item.parts } : {}, ...held ? { fluid: held } : {}, three: T });
7424
7440
  markKitOrigin(root, { owner: "game-items-three", kind: "item", id: item.id, ...kind === "shape" ? { standIn: true } : {} });
7425
7441
  return { root, kind, ...shape ? { shape } : {}, size: item.size, materials };
7426
7442
  }
@@ -7946,7 +7962,8 @@ function createItemsTestModule(options) {
7946
7962
  };
7947
7963
  const usesOf = (def) => {
7948
7964
  const use = options.itemUse?.(def);
7949
- const contents = fluidOf({ ...def.model === void 0 ? {} : { model: def.model }, size: def.size, weight: def.weight });
7965
+ const held = itemFluid2(def);
7966
+ const contents = fluidOf({ ...def.model === void 0 ? {} : { model: def.model }, size: def.size, weight: def.weight, ...held ? { fluid: held } : {} });
7950
7967
  const liquid = sealOf(def, contents.fluid ? contents : vesselOf(def));
7951
7968
  if (!use) return liquid;
7952
7969
  const edible = def.category === "food" || def.category === "drink";
@@ -8525,4 +8542,4 @@ export {
8525
8542
  HUMAN_HEIGHT,
8526
8543
  createItemsTestModule
8527
8544
  };
8528
- //# sourceMappingURL=chunk-XJG7IGO3.js.map
8545
+ //# sourceMappingURL=chunk-PAQ3Q5I2.js.map