{"_id":"@apcraft/math","name":"@apcraft/math","dist-tags":{"latest":"2.2.7"},"versions":{"2.2.7":{"name":"@apcraft/math","version":"2.2.7","author":{"name":"Raphael Landaverde","url":"rlanda@microsoft.com"},"contributors":[{"name":"Jake Shirley","email":"jashir@mojang.com"}],"description":"Math utilities for use with minecraft scripting modules","exports":{"import":"./lib/index.js","types":"./lib/types/math-public.d.ts"},"type":"module","types":"./lib/types/math-public.d.ts","repository":{"type":"git","url":"git+https://github.com/Mojang/minecraft-scripting-libraries.git","directory":"libraries/math"},"scripts":{"build":"just build","lint":"just lint","test":"just test","clean":"just clean","postpublish":"just postpublish"},"license":"MIT","devDependencies":{"@minecraft/core-build-tasks":"*","@minecraft/server":"^2.0.0","just-scripts":"^2.3.3","prettier":"^3.5.3","vitest":"^3.0.8"},"_id":"@apcraft/math@2.2.7","bugs":{"url":"https://github.com/Mojang/minecraft-scripting-libraries/issues"},"homepage":"https://github.com/Mojang/minecraft-scripting-libraries#readme","_nodeVersion":"24.4.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-SpwGbq6dxkOVW+vAJMJacfPx7dFbJNEuGf6mkuCoLaSm5frFaQefs22Slqh4XP9mnGy2DkUfMm78UgnsT/zJWw==","shasum":"6095d0572ce4069c7b97910e41c2ec56347bd5b4","tarball":"https://registry.npmjs.org/@apcraft/math/-/math-2.2.7.tgz","fileCount":28,"unpackedSize":177237,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCQenFy63S7XEf1vsDPF019e7Hl4qlOQb3rPljTPnX7TQIhAPuyXNQDzdgUAf0ND46tZUgVrqyMP0NA2pwwp/+w2kO7"}]},"_npmUser":{"name":"apcraft","email":"remezibu@adadad.uk"},"directories":{},"maintainers":[{"name":"apcraft","email":"remezibu@adadad.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/math_2.2.7_1752973121619_0.31142297215297843"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-20T00:58:41.544Z","2.2.7":"2025-07-20T00:58:41.820Z","modified":"2025-07-20T00:58:42.079Z"},"maintainers":[{"name":"apcraft","email":"remezibu@adadad.uk"}],"description":"Math utilities for use with minecraft scripting modules","homepage":"https://github.com/Mojang/minecraft-scripting-libraries#readme","repository":{"type":"git","url":"git+https://github.com/Mojang/minecraft-scripting-libraries.git","directory":"libraries/math"},"contributors":[{"name":"Jake Shirley","email":"jashir@mojang.com"}],"author":{"name":"Raphael Landaverde","url":"rlanda@microsoft.com"},"bugs":{"url":"https://github.com/Mojang/minecraft-scripting-libraries/issues"},"license":"MIT","readme":"# Minecraft Math\n\nA set of utilities and functions for common math operations. Major pieces are covered below.\n\n## Vector3\n\nA set of utility functions and a wrapper class for common vector3 operations. Two distinct patterns are supported, a more pure computational approach operating on the Vector3 interface with no mutation, and a separate wrapper object oriented approach following a \"builder\" pattern. It is mostly preference whether you prefer the more \"mutation\" heavy pattern or the functional pattern, it depends on the structure of your code. Under the covers, the same helpers are used.\n\n### Pure Functional Style\n\n```ts\nimport { Vector3, world } from '@minecraft/server';\nimport { MinecraftDimensionTypes } from '@minecraft/vanilla-data';\nimport { Vector3Utils } from '@minecraft/math';\n\nconst vectorA: Vector3 = {x: 1, y: 2, z:3};\nconst vectorB: Vector3 = {x: 4, y: 5, z:6};\n\nconst resultAdd = Vector3Utils.add(vectorA, vectorB); // {x:5, y:7, z:9}\nconst resultSubtract = Vector3Utils.subtract(vectorA, vectorB); // {x:-3, y:-3, z:-3}\nconst resultAdd = Vector3Utils.cross(vectorA, vectorB); // {x:-3, y:6, z:-3}\n\nconsole.log(toString(vectorA)); // Prints out \"1, 2, 3\"\n\n// Use your vectors with any @minecraft/server API\nconst = dimension = world.getDimension(MinecraftDimensionTypes.Overworld);\ndimension.spawnParticle(\"minecraft:colored_flame_particle\", resultAdd);\n```\n\n### Builder Style\n\n```ts\nimport { Vector3, world } from '@minecraft/server';\nimport { Vector3Builder } from '@minecraft/math';\nimport { MinecraftDimensionTypes } from '@minecraft/vanilla-data';\n\nconst vectorA: Vector3Builder = new Vector3Builder({x: 1, y: 2, z:3});\nconst vectorB: Vector3 = {x: 4, y: 5, z:6};\nconst vectorC: Vector3 = {x: 1, y: 3, z:5};\n\n// Mutates vectorA directly each time\nvectorA.add(vectorB).subtract(vectorC).cross(vectorB); // Final result {x:4, y:-8, z:4}\n\nconsole.log(vectorA.toString()); // Prints out \"4, -8, 4\"\n\n// Vector3Builder type can directly be used in APIs that accept Vector3\nconst dimension = world.getDimension(MinecraftDimensionTypes.Overworld);\ndimension.spawnParticle(\"minecraft:colored_flame_particle\", vectorA);\n```\n\n## How to use @minecraft/math in your project\n\n@minecraft/math is published to NPM and follows standard semver semantics. To use it in your project,\n\n- Download `@minecraft/math` from NPM by doing `npm install @minecraft/math` within your scripts pack. By using `@minecraft/math`, you will need to do some sort of bundling to merge the library into your packs code. We recommend using [esbuild](https://esbuild.github.io/getting-started/#your-first-bundle) for simplicity.\n","readmeFilename":"README.md","_rev":"1-7045039a3ebc386fe5d01b715cd7d36a"}