From 682a75def9bb10f5b82661d8978ebed4dc1913c7 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 11:38:47 -0600 Subject: [PATCH 1/8] add types and utils for orientation --- packages/world/src/ObjectType.sol | 4 +- packages/world/ts/exports/internal.ts | 1 + packages/world/ts/orientation.ts | 73 +++++++++++++++++---------- 3 files changed, 50 insertions(+), 28 deletions(-) diff --git a/packages/world/src/ObjectType.sol b/packages/world/src/ObjectType.sol index 477eae5e..51195fcf 100644 --- a/packages/world/src/ObjectType.sol +++ b/packages/world/src/ObjectType.sol @@ -1164,8 +1164,8 @@ library ObjectTypeLib { function isOrientationSupported(ObjectType self, Orientation orientation) internal pure returns (bool) { if (self == ObjectTypes.Bed) { - return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(40) - || orientation == Orientation.wrap(1) || orientation == Orientation.wrap(44); + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); } return orientation == Orientation.wrap(0); diff --git a/packages/world/ts/exports/internal.ts b/packages/world/ts/exports/internal.ts index e5da424d..d6881ec8 100644 --- a/packages/world/ts/exports/internal.ts +++ b/packages/world/ts/exports/internal.ts @@ -3,3 +3,4 @@ export * from "../recipes"; export * from "../trees"; export * from "../vec3"; export * from "../entityid"; +export * from "../orientation"; diff --git a/packages/world/ts/orientation.ts b/packages/world/ts/orientation.ts index e6fb5f5c..4f659d96 100644 --- a/packages/world/ts/orientation.ts +++ b/packages/world/ts/orientation.ts @@ -1,4 +1,6 @@ import config from "../mud.config"; +import type { Vec3 } from "./vec3"; + // Direction is an array of strings config.enums.Direction; @@ -17,49 +19,55 @@ const SUPPORTED_DIRECTION_VECTORS: { type SupportedDirection = keyof typeof SUPPORTED_DIRECTION_VECTORS; -const PERMUTATIONS: [number, number, number][] = [ - [0, 1, 2], - [0, 2, 1], - [1, 0, 2], - [1, 2, 0], - [2, 0, 1], - [2, 1, 0], +export type Orientation = number; // uint8 in Solidity + +type Axis = 0 | 1 | 2; +export type Permute = readonly [Axis, Axis, Axis]; +export type Reflect = readonly [0 | 1, 0 | 1, 0 | 1]; + +// 6 possible permutations +export const PERMUTATIONS: Permute[] = [ + [0, 1, 2], // Original orientation + [0, 2, 1], // Swap y and z + [1, 0, 2], // Swap x and y + [1, 2, 0], // Rotate x->y->z->x + [2, 0, 1], // Rotate x->z->y->x + [2, 1, 0], // Swap x and z ]; -const REFLECTIONS: [number, number, number][] = [ - [0, 0, 0], - [1, 0, 0], - [0, 1, 0], - [1, 1, 0], - [0, 0, 1], - [1, 0, 1], - [0, 1, 1], - [1, 1, 1], +// 8 possible reflections +export const REFLECTIONS: Reflect[] = [ + [0, 0, 0], // No reflection + [1, 0, 0], // Reflect x + [0, 1, 0], // Reflect y + [1, 1, 0], // Reflect x and y + [0, 0, 1], // Reflect z + [1, 0, 1], // Reflect x and z + [0, 1, 1], // Reflect y and z + [1, 1, 1], // Reflect all axes ]; -const CANONICAL_UP: [number, number, number] = [0, 1, 0]; -const CANONICAL_FORWARD: [number, number, number] = [1, 0, 0]; +const CANONICAL_UP: Vec3 = [0, 1, 0]; +const CANONICAL_FORWARD: Vec3 = [1, 0, 0]; -function applyOrientation( - v: [number, number, number], - perm: [number, number, number], - refl: [number, number, number], -): [number, number, number] { - const out: [number, number, number] = [v[perm[0]]!, v[perm[1]]!, v[perm[2]]!]; +export function applyOrientation(v: Vec3, perm: Permute, refl: Reflect): Vec3 { + const out: Vec3 = [v[perm[0]]!, v[perm[1]]!, v[perm[2]]!]; if (refl[0]) out[0] = -out[0]; if (refl[1]) out[1] = -out[1]; if (refl[2]) out[2] = -out[2]; return out; } -export function getOrientation(forwardDirection: SupportedDirection): number { +export function getOrientation( + forwardDirection: SupportedDirection, +): Orientation { return getOrientationGeneric(forwardDirection, "PositiveY"); } export function getOrientationGeneric( forwardDirection: SupportedDirection, upDirection: SupportedDirection, -): number { +): Orientation { const targetForward = SUPPORTED_DIRECTION_VECTORS[forwardDirection]!; const targetUp = SUPPORTED_DIRECTION_VECTORS[upDirection]!; @@ -85,3 +93,16 @@ export function getOrientationGeneric( } throw new Error("Unable to find orientation"); } + +// TODO: implement +export function encodeOrientation(refl: Reflect, perm: Permute): Orientation { + return 0; +} + +export function decodeOrientation( + orientation: Orientation, +): [Reflect, Permute] { + const reflIdx = orientation & 8; + const permIdx = orientation >> 3; + return [REFLECTIONS[reflIdx]!, PERMUTATIONS[permIdx]!]; +} From f199fa6e332c30941a35effe61467d999d6410b5 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 11:49:53 -0600 Subject: [PATCH 2/8] add orientation test --- packages/world/ts/orientation.ts | 6 +-- packages/world/ts/test/orientation.test.ts | 55 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 packages/world/ts/test/orientation.test.ts diff --git a/packages/world/ts/orientation.ts b/packages/world/ts/orientation.ts index 4f659d96..125d22d2 100644 --- a/packages/world/ts/orientation.ts +++ b/packages/world/ts/orientation.ts @@ -101,8 +101,8 @@ export function encodeOrientation(refl: Reflect, perm: Permute): Orientation { export function decodeOrientation( orientation: Orientation, -): [Reflect, Permute] { - const reflIdx = orientation & 8; +): [Permute, Reflect] { const permIdx = orientation >> 3; - return [REFLECTIONS[reflIdx]!, PERMUTATIONS[permIdx]!]; + const reflIdx = orientation & 7; + return [PERMUTATIONS[permIdx]!, REFLECTIONS[reflIdx]!]; } diff --git a/packages/world/ts/test/orientation.test.ts b/packages/world/ts/test/orientation.test.ts new file mode 100644 index 00000000..fa9af9fe --- /dev/null +++ b/packages/world/ts/test/orientation.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, it } from "vitest"; +import { PERMUTATIONS, REFLECTIONS, decodeOrientation } from "../orientation"; + +describe("Orientation decoding", () => { + it("decodeOrientation", () => { + expect(decodeOrientation(0)).toEqual([PERMUTATIONS[0], REFLECTIONS[0]]); + expect(decodeOrientation(1)).toEqual([PERMUTATIONS[0], REFLECTIONS[1]]); + expect(decodeOrientation(2)).toEqual([PERMUTATIONS[0], REFLECTIONS[2]]); + expect(decodeOrientation(3)).toEqual([PERMUTATIONS[0], REFLECTIONS[3]]); + expect(decodeOrientation(4)).toEqual([PERMUTATIONS[0], REFLECTIONS[4]]); + expect(decodeOrientation(5)).toEqual([PERMUTATIONS[0], REFLECTIONS[5]]); + expect(decodeOrientation(6)).toEqual([PERMUTATIONS[0], REFLECTIONS[6]]); + expect(decodeOrientation(7)).toEqual([PERMUTATIONS[0], REFLECTIONS[7]]); + expect(decodeOrientation(8)).toEqual([PERMUTATIONS[1], REFLECTIONS[0]]); + expect(decodeOrientation(9)).toEqual([PERMUTATIONS[1], REFLECTIONS[1]]); + expect(decodeOrientation(10)).toEqual([PERMUTATIONS[1], REFLECTIONS[2]]); + expect(decodeOrientation(11)).toEqual([PERMUTATIONS[1], REFLECTIONS[3]]); + expect(decodeOrientation(12)).toEqual([PERMUTATIONS[1], REFLECTIONS[4]]); + expect(decodeOrientation(13)).toEqual([PERMUTATIONS[1], REFLECTIONS[5]]); + expect(decodeOrientation(14)).toEqual([PERMUTATIONS[1], REFLECTIONS[6]]); + expect(decodeOrientation(15)).toEqual([PERMUTATIONS[1], REFLECTIONS[7]]); + expect(decodeOrientation(16)).toEqual([PERMUTATIONS[2], REFLECTIONS[0]]); + expect(decodeOrientation(17)).toEqual([PERMUTATIONS[2], REFLECTIONS[1]]); + expect(decodeOrientation(18)).toEqual([PERMUTATIONS[2], REFLECTIONS[2]]); + expect(decodeOrientation(19)).toEqual([PERMUTATIONS[2], REFLECTIONS[3]]); + expect(decodeOrientation(20)).toEqual([PERMUTATIONS[2], REFLECTIONS[4]]); + expect(decodeOrientation(21)).toEqual([PERMUTATIONS[2], REFLECTIONS[5]]); + expect(decodeOrientation(22)).toEqual([PERMUTATIONS[2], REFLECTIONS[6]]); + expect(decodeOrientation(23)).toEqual([PERMUTATIONS[2], REFLECTIONS[7]]); + expect(decodeOrientation(24)).toEqual([PERMUTATIONS[3], REFLECTIONS[0]]); + expect(decodeOrientation(25)).toEqual([PERMUTATIONS[3], REFLECTIONS[1]]); + expect(decodeOrientation(26)).toEqual([PERMUTATIONS[3], REFLECTIONS[2]]); + expect(decodeOrientation(27)).toEqual([PERMUTATIONS[3], REFLECTIONS[3]]); + expect(decodeOrientation(28)).toEqual([PERMUTATIONS[3], REFLECTIONS[4]]); + expect(decodeOrientation(29)).toEqual([PERMUTATIONS[3], REFLECTIONS[5]]); + expect(decodeOrientation(30)).toEqual([PERMUTATIONS[3], REFLECTIONS[6]]); + expect(decodeOrientation(31)).toEqual([PERMUTATIONS[3], REFLECTIONS[7]]); + expect(decodeOrientation(32)).toEqual([PERMUTATIONS[4], REFLECTIONS[0]]); + expect(decodeOrientation(33)).toEqual([PERMUTATIONS[4], REFLECTIONS[1]]); + expect(decodeOrientation(34)).toEqual([PERMUTATIONS[4], REFLECTIONS[2]]); + expect(decodeOrientation(35)).toEqual([PERMUTATIONS[4], REFLECTIONS[3]]); + expect(decodeOrientation(36)).toEqual([PERMUTATIONS[4], REFLECTIONS[4]]); + expect(decodeOrientation(37)).toEqual([PERMUTATIONS[4], REFLECTIONS[5]]); + expect(decodeOrientation(38)).toEqual([PERMUTATIONS[4], REFLECTIONS[6]]); + expect(decodeOrientation(39)).toEqual([PERMUTATIONS[4], REFLECTIONS[7]]); + expect(decodeOrientation(40)).toEqual([PERMUTATIONS[5], REFLECTIONS[0]]); + expect(decodeOrientation(41)).toEqual([PERMUTATIONS[5], REFLECTIONS[1]]); + expect(decodeOrientation(42)).toEqual([PERMUTATIONS[5], REFLECTIONS[2]]); + expect(decodeOrientation(43)).toEqual([PERMUTATIONS[5], REFLECTIONS[3]]); + expect(decodeOrientation(44)).toEqual([PERMUTATIONS[5], REFLECTIONS[4]]); + expect(decodeOrientation(45)).toEqual([PERMUTATIONS[5], REFLECTIONS[5]]); + expect(decodeOrientation(46)).toEqual([PERMUTATIONS[5], REFLECTIONS[6]]); + expect(decodeOrientation(47)).toEqual([PERMUTATIONS[5], REFLECTIONS[7]]); + }); +}); From 79d18f3d810bdf3e3a611f26016e2d19c8bf9992 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 11:53:35 -0600 Subject: [PATCH 3/8] add encode orientation util and tests --- packages/world/ts/orientation.ts | 18 +++++-- packages/world/ts/test/orientation.test.ts | 59 +++++++++++++++++++++- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/packages/world/ts/orientation.ts b/packages/world/ts/orientation.ts index 125d22d2..00f9fd21 100644 --- a/packages/world/ts/orientation.ts +++ b/packages/world/ts/orientation.ts @@ -94,9 +94,21 @@ export function getOrientationGeneric( throw new Error("Unable to find orientation"); } -// TODO: implement -export function encodeOrientation(refl: Reflect, perm: Permute): Orientation { - return 0; +export function encodeOrientation(perm: Permute, refl: Reflect): Orientation { + // Find the index of the permutation in PERMUTATIONS array + const permIdx = PERMUTATIONS.findIndex( + (p) => p[0] === perm[0] && p[1] === perm[1] && p[2] === perm[2], + ); + if (permIdx === -1) throw new Error("Invalid permutation"); + + // Find the index of the reflection in REFLECTIONS array + const reflIdx = REFLECTIONS.findIndex( + (r) => r[0] === refl[0] && r[1] === refl[1] && r[2] === refl[2], + ); + if (reflIdx === -1) throw new Error("Invalid reflection"); + + // Combine the indices into a single orientation number + return (permIdx << 3) | reflIdx; } export function decodeOrientation( diff --git a/packages/world/ts/test/orientation.test.ts b/packages/world/ts/test/orientation.test.ts index fa9af9fe..19fd026a 100644 --- a/packages/world/ts/test/orientation.test.ts +++ b/packages/world/ts/test/orientation.test.ts @@ -1,7 +1,62 @@ import { describe, expect, it } from "vitest"; -import { PERMUTATIONS, REFLECTIONS, decodeOrientation } from "../orientation"; +import { + PERMUTATIONS, + REFLECTIONS, + decodeOrientation, + encodeOrientation, +} from "../orientation"; -describe("Orientation decoding", () => { +describe("Orientation encoding and decoding", () => { + it("encodeOrientation", () => { + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[0])).toEqual(0); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[1])).toEqual(1); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[2])).toEqual(2); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[3])).toEqual(3); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[4])).toEqual(4); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[5])).toEqual(5); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[6])).toEqual(6); + expect(encodeOrientation(PERMUTATIONS[0], REFLECTIONS[7])).toEqual(7); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[0])).toEqual(8); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[1])).toEqual(9); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[2])).toEqual(10); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[3])).toEqual(11); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[4])).toEqual(12); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[5])).toEqual(13); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[6])).toEqual(14); + expect(encodeOrientation(PERMUTATIONS[1], REFLECTIONS[7])).toEqual(15); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[0])).toEqual(16); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[1])).toEqual(17); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[2])).toEqual(18); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[3])).toEqual(19); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[4])).toEqual(20); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[5])).toEqual(21); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[6])).toEqual(22); + expect(encodeOrientation(PERMUTATIONS[2], REFLECTIONS[7])).toEqual(23); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[0])).toEqual(24); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[1])).toEqual(25); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[2])).toEqual(26); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[3])).toEqual(27); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[4])).toEqual(28); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[5])).toEqual(29); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[6])).toEqual(30); + expect(encodeOrientation(PERMUTATIONS[3], REFLECTIONS[7])).toEqual(31); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[0])).toEqual(32); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[1])).toEqual(33); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[2])).toEqual(34); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[3])).toEqual(35); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[4])).toEqual(36); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[5])).toEqual(37); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[6])).toEqual(38); + expect(encodeOrientation(PERMUTATIONS[4], REFLECTIONS[7])).toEqual(39); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[0])).toEqual(40); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[1])).toEqual(41); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[2])).toEqual(42); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[3])).toEqual(43); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[4])).toEqual(44); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[5])).toEqual(45); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[6])).toEqual(46); + expect(encodeOrientation(PERMUTATIONS[5], REFLECTIONS[7])).toEqual(47); + }); it("decodeOrientation", () => { expect(decodeOrientation(0)).toEqual([PERMUTATIONS[0], REFLECTIONS[0]]); expect(decodeOrientation(1)).toEqual([PERMUTATIONS[0], REFLECTIONS[1]]); From 44f93054effc3a8c1c394b91638e5a4d1e9091c2 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 11:56:47 -0600 Subject: [PATCH 4/8] fix ts doesnt know size --- packages/world/ts/orientation.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/world/ts/orientation.ts b/packages/world/ts/orientation.ts index 00f9fd21..f9d46152 100644 --- a/packages/world/ts/orientation.ts +++ b/packages/world/ts/orientation.ts @@ -26,17 +26,33 @@ export type Permute = readonly [Axis, Axis, Axis]; export type Reflect = readonly [0 | 1, 0 | 1, 0 | 1]; // 6 possible permutations -export const PERMUTATIONS: Permute[] = [ +export const PERMUTATIONS: readonly [ + Permute, + Permute, + Permute, + Permute, + Permute, + Permute, +] = [ [0, 1, 2], // Original orientation [0, 2, 1], // Swap y and z [1, 0, 2], // Swap x and y [1, 2, 0], // Rotate x->y->z->x [2, 0, 1], // Rotate x->z->y->x [2, 1, 0], // Swap x and z -]; +] as const; // 8 possible reflections -export const REFLECTIONS: Reflect[] = [ +export const REFLECTIONS: readonly [ + Reflect, + Reflect, + Reflect, + Reflect, + Reflect, + Reflect, + Reflect, + Reflect, +] = [ [0, 0, 0], // No reflection [1, 0, 0], // Reflect x [0, 1, 0], // Reflect y @@ -45,7 +61,7 @@ export const REFLECTIONS: Reflect[] = [ [1, 0, 1], // Reflect x and z [0, 1, 1], // Reflect y and z [1, 1, 1], // Reflect all axes -]; +] as const; const CANONICAL_UP: Vec3 = [0, 1, 0]; const CANONICAL_FORWARD: Vec3 = [1, 0, 0]; From 9e705b917b449c512c8d4a4176bc641c695d38fa Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 12:33:50 -0600 Subject: [PATCH 5/8] add getDirection util --- packages/world/ts/orientation.ts | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/world/ts/orientation.ts b/packages/world/ts/orientation.ts index f9d46152..704e9ead 100644 --- a/packages/world/ts/orientation.ts +++ b/packages/world/ts/orientation.ts @@ -87,8 +87,8 @@ export function getOrientationGeneric( const targetForward = SUPPORTED_DIRECTION_VECTORS[forwardDirection]!; const targetUp = SUPPORTED_DIRECTION_VECTORS[upDirection]!; - for (let permIdx = 0; permIdx < 6; ++permIdx) { - for (let reflIdx = 0; reflIdx < 8; ++reflIdx) { + for (let permIdx = 0; permIdx < PERMUTATIONS.length; ++permIdx) { + for (let reflIdx = 0; reflIdx < REFLECTIONS.length; ++reflIdx) { const perm = PERMUTATIONS[permIdx]!; const refl = REFLECTIONS[reflIdx]!; @@ -103,13 +103,45 @@ export function getOrientationGeneric( forward[1] === targetForward[1] && forward[2] === targetForward[2] ) { - return permIdx * 8 + reflIdx; + return encodeOrientation(perm, refl); } } } throw new Error("Unable to find orientation"); } +export function getDirection(orientation: Orientation): SupportedDirection { + return getDirectionGeneric(orientation, "PositiveY"); +} + +export function getDirectionGeneric( + orientation: Orientation, + upDirection: SupportedDirection, +): SupportedDirection { + const [perm, refl] = decodeOrientation(orientation); + const up = applyOrientation(CANONICAL_UP, perm, refl); + const targetUp = SUPPORTED_DIRECTION_VECTORS[upDirection]!; + + const forward = applyOrientation(CANONICAL_FORWARD, perm, refl); + + const forwardDirection = Object.keys(SUPPORTED_DIRECTION_VECTORS).find( + (dir) => { + const targetForward = + SUPPORTED_DIRECTION_VECTORS[dir as SupportedDirection]!; + return ( + up[0] === targetUp[0] && + up[1] === targetUp[1] && + up[2] === targetUp[2] && + forward[0] === targetForward[0] && + forward[1] === targetForward[1] && + forward[2] === targetForward[2] + ); + }, + ); + if (!forwardDirection) throw new Error("Unable to find direction"); + return forwardDirection as SupportedDirection; +} + export function encodeOrientation(perm: Permute, refl: Reflect): Orientation { // Find the index of the permutation in PERMUTATIONS array const permIdx = PERMUTATIONS.findIndex( From b1e6f183fc27737b89d79a592ba7849ce32d9f77 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 12:47:13 -0600 Subject: [PATCH 6/8] add orientation to other placeables --- packages/world/src/ObjectType.sol | 28 +++++++ packages/world/ts/objects.ts | 77 +++++++++++++++++-- packages/world/ts/scripts/genObjectTypeSol.ts | 3 +- 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/packages/world/src/ObjectType.sol b/packages/world/src/ObjectType.sol index 51195fcf..7b249fc9 100644 --- a/packages/world/src/ObjectType.sol +++ b/packages/world/src/ObjectType.sol @@ -1163,10 +1163,38 @@ library ObjectTypeLib { } function isOrientationSupported(ObjectType self, Orientation orientation) internal pure returns (bool) { + if (self == ObjectTypes.TextSign) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } + if (self == ObjectTypes.ForceField) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } + if (self == ObjectTypes.Chest) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } + if (self == ObjectTypes.SpawnTile) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } if (self == ObjectTypes.Bed) { return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); } + if (self == ObjectTypes.Workbench) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } + if (self == ObjectTypes.Powerstone) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } + if (self == ObjectTypes.Furnace) { + return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) + || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + } return orientation == Orientation.wrap(0); } diff --git a/packages/world/ts/objects.ts b/packages/world/ts/objects.ts index c3d9beed..83c4627b 100644 --- a/packages/world/ts/objects.ts +++ b/packages/world/ts/objects.ts @@ -381,7 +381,16 @@ export const objectDef: Optional[] = [ { name: "GoldOre", mass: 1600000000000000000n }, { name: "DiamondOre", mass: 5000000000000000000n }, { name: "NeptuniumOre", mass: 5000000000000000000n }, - { name: "TextSign", mass: 18000000000000000n }, + { + name: "TextSign", + mass: 18000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, { name: "OakPlanks", mass: 4500000000000000n }, { name: "BirchPlanks", mass: 4500000000000000n }, { name: "JunglePlanks", mass: 4500000000000000n }, @@ -453,9 +462,36 @@ export const objectDef: Optional[] = [ growableEnergy: 232000000000000000n, timeToGrow: 345600n, }, - { name: "ForceField", mass: 1035000000000000000n }, - { name: "Chest", mass: 36000000000000000n }, - { name: "SpawnTile", mass: 6435000000000000000n }, + { + name: "ForceField", + mass: 1035000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, + { + name: "Chest", + mass: 36000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, + { + name: "SpawnTile", + mass: 6435000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, { name: "Bed", mass: 13500000000000000n, @@ -466,9 +502,36 @@ export const objectDef: Optional[] = [ getOrientation("NegativeZ"), ], }, - { name: "Workbench", mass: 18000000000000000n }, - { name: "Powerstone", mass: 80000000000000000n }, - { name: "Furnace", mass: 108000000000000000n }, + { + name: "Workbench", + mass: 18000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, + { + name: "Powerstone", + mass: 80000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, + { + name: "Furnace", + mass: 108000000000000000n, + supportedOrientations: [ + getOrientation("PositiveX"), + getOrientation("NegativeX"), + getOrientation("PositiveZ"), + getOrientation("NegativeZ"), + ], + }, { name: "Torch", mass: 1125000000000000n }, // Non blocks diff --git a/packages/world/ts/scripts/genObjectTypeSol.ts b/packages/world/ts/scripts/genObjectTypeSol.ts index 0a7baf07..9155986d 100644 --- a/packages/world/ts/scripts/genObjectTypeSol.ts +++ b/packages/world/ts/scripts/genObjectTypeSol.ts @@ -197,7 +197,8 @@ ${Object.entries(categories) return `if (self == ObjectTypes.${obj.name}) { return ${obj.supportedOrientations!.map((orientation) => `orientation == Orientation.wrap(${orientation})`).join(" || ")}; }`; - })} + }) + .join("\n ")} return orientation == Orientation.wrap(0); } From c81c6dd9d3b774e745b0b55690cfc219f6649049 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 13:27:51 -0600 Subject: [PATCH 7/8] fix bed only supports 2 --- packages/world/src/ObjectType.sol | 5 ++--- packages/world/ts/objects.ts | 2 -- packages/world/ts/scripts/genObjectTypeSol.ts | 2 +- packages/world/worlds.json | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/world/src/ObjectType.sol b/packages/world/src/ObjectType.sol index 7b249fc9..6284464c 100644 --- a/packages/world/src/ObjectType.sol +++ b/packages/world/src/ObjectType.sol @@ -1130,7 +1130,7 @@ library ObjectTypeLib { if (self == ObjectTypes.Bed) { Vec3[] memory bedRelativePositions = new Vec3[](1); - bedRelativePositions[0] = vec3(1, 0, 0); + bedRelativePositions[0] = vec3(0, 0, 1); return bedRelativePositions; } @@ -1180,8 +1180,7 @@ library ObjectTypeLib { || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); } if (self == ObjectTypes.Bed) { - return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) - || orientation == Orientation.wrap(40) || orientation == Orientation.wrap(44); + return orientation == Orientation.wrap(1) || orientation == Orientation.wrap(44); } if (self == ObjectTypes.Workbench) { return orientation == Orientation.wrap(0) || orientation == Orientation.wrap(1) diff --git a/packages/world/ts/objects.ts b/packages/world/ts/objects.ts index 83c4627b..9c9584b7 100644 --- a/packages/world/ts/objects.ts +++ b/packages/world/ts/objects.ts @@ -496,9 +496,7 @@ export const objectDef: Optional[] = [ name: "Bed", mass: 13500000000000000n, supportedOrientations: [ - getOrientation("PositiveX"), getOrientation("NegativeX"), - getOrientation("PositiveZ"), getOrientation("NegativeZ"), ], }, diff --git a/packages/world/ts/scripts/genObjectTypeSol.ts b/packages/world/ts/scripts/genObjectTypeSol.ts index 9155986d..b1c8f765 100644 --- a/packages/world/ts/scripts/genObjectTypeSol.ts +++ b/packages/world/ts/scripts/genObjectTypeSol.ts @@ -158,7 +158,7 @@ ${Object.entries(categories) if (self == ObjectTypes.Bed) { Vec3[] memory bedRelativePositions = new Vec3[](1); - bedRelativePositions[0] = vec3(1, 0, 0); + bedRelativePositions[0] = vec3(0, 0, 1); return bedRelativePositions; } diff --git a/packages/world/worlds.json b/packages/world/worlds.json index e333e8a3..fed3d6b2 100644 --- a/packages/world/worlds.json +++ b/packages/world/worlds.json @@ -4,7 +4,7 @@ "blockNumber": 17810274 }, "31337": { - "address": "0x6439113f0e1f64018c3167DA2aC21e2689818086" + "address": "0x3c9C3822680c42c2BC633A3de26e1074Cf7c1b06" }, "695569": { "address": "0xaa544E5e0D1C45cC43Ac8D5512a5081aA6Ca9EFE", From c37b94e6a11aaa941d5d5bb630abccd6cacd539f Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Wed, 21 May 2025 13:37:45 -0600 Subject: [PATCH 8/8] fix bed pos --- packages/world/src/ObjectType.sol | 2 +- packages/world/ts/scripts/genObjectTypeSol.ts | 2 +- packages/world/worlds.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/world/src/ObjectType.sol b/packages/world/src/ObjectType.sol index 6284464c..5c166d92 100644 --- a/packages/world/src/ObjectType.sol +++ b/packages/world/src/ObjectType.sol @@ -1130,7 +1130,7 @@ library ObjectTypeLib { if (self == ObjectTypes.Bed) { Vec3[] memory bedRelativePositions = new Vec3[](1); - bedRelativePositions[0] = vec3(0, 0, 1); + bedRelativePositions[0] = vec3(1, 0, 0); return bedRelativePositions; } diff --git a/packages/world/ts/scripts/genObjectTypeSol.ts b/packages/world/ts/scripts/genObjectTypeSol.ts index b1c8f765..9155986d 100644 --- a/packages/world/ts/scripts/genObjectTypeSol.ts +++ b/packages/world/ts/scripts/genObjectTypeSol.ts @@ -158,7 +158,7 @@ ${Object.entries(categories) if (self == ObjectTypes.Bed) { Vec3[] memory bedRelativePositions = new Vec3[](1); - bedRelativePositions[0] = vec3(0, 0, 1); + bedRelativePositions[0] = vec3(1, 0, 0); return bedRelativePositions; } diff --git a/packages/world/worlds.json b/packages/world/worlds.json index fed3d6b2..eb18cffc 100644 --- a/packages/world/worlds.json +++ b/packages/world/worlds.json @@ -4,7 +4,7 @@ "blockNumber": 17810274 }, "31337": { - "address": "0x3c9C3822680c42c2BC633A3de26e1074Cf7c1b06" + "address": "0x277aacC16eB69d66Eeb0A4aF60f7f0e9522B2a23" }, "695569": { "address": "0xaa544E5e0D1C45cC43Ac8D5512a5081aA6Ca9EFE",