Skip to content

Commit d117193

Browse files
authored
Resolving feedback on @minecraft/math after testing internally (#4)
Switch to a couple of classes with static methods to remove ambiguity with shortly named methods. Add a release pipeline to do build validations for now, but not the actual release.
1 parent d924eb9 commit d117193

13 files changed

+315
-329
lines changed

Diff for: .github/workflows/release-changes.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release Changes
2+
3+
environment: release
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
16+
- name: Use Node.js 20.x
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '20.x'
20+
- run: npm ci
21+
- run: npm run test # Fully build the repo so we have artifacts available to create releases, include tests so we don't ship in a broken state
22+
23+
# Uncomment the below when ready to publish to NPM for the first time
24+
# - name: Set git credentials
25+
# run: |
26+
# git config --global user.name "Raphael Landaverde"
27+
# git config --global user.email "[email protected]"
28+
# git remote set-url origin "https://[email protected]/mojang/minecraft-scripting-libraries"
29+
# env:
30+
# REPO_PAT: ${{ secrets.REPO_PAT }}
31+
32+
# # Pass the token on the command line for publishing
33+
# - name: Publish
34+
# run: npm run release -- --token "$NPM_TOKEN" --yes --new
35+
# env:
36+
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Diff for: CONTRIBUTING.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ or contact [[email protected]](mailto:[email protected]) with any addi
1515

1616
## Specific Guidelines
1717

18-
Contributions to these libraries are welcome! These libraries are maintained by Mojang but we are open to contributions and bug fixes. In general, we consider the backwards compatibility and versioning to be the absolute top priority when making changes to the libraries. Because of this, we strictly adhere to semver for changes, and libraries depend on minecraft modules at specific major versions as well. Any PR submitted to any library **must** contain a change file using the beachball tool to indicate the severity of the change. When a change is submitted, it will automatically update versions and publish to NPM via our pipelines.
18+
Contributions to these libraries are welcome! These libraries are maintained by Mojang but we are open to contributions and bug fixes. In general, we consider the backwards compatibility and versioning to be the absolute top priority when making changes to the libraries. Because of this, we strictly adhere to semver for changes, and libraries depend on minecraft modules at specific major versions as well. Any PR submitted to any library **must** contain a change file using the beachball tool to indicate the severity of the change. When a change is submitted, it will automatically update versions and publish to NPM via our pipelines.
19+
20+
### Naming
21+
22+
We generally follow the naming conventiosn specified by the [google style guide](https://google.github.io/styleguide/jsguide.html#naming). There is other general good practice within the style guide as well, though generally the vast majority of our style is enforced via a combination of ESLint and prettier enforcement at PR time.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Switch to a couple of classes with static methods to remove ambiguity with shortly named methods",
4+
"packageName": "@minecraft/math",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Start from a 0 version so it bumps to a 1.0.0 version",
4+
"packageName": "eslint-plugin-minecraft-linting",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

Diff for: libraries/math/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ A set of utilities and functions for common math operations. Major pieces are co
44

55
## Vector3
66

7-
A set of free 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, so it depends on the structure of your code. Under the covers, the same helpers are used.
7+
A 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.
88

99
### Pure Functional Style
1010

1111
```ts
1212
import { Vector3, world } from '@minecraft/server';
1313
import { MinecraftDimensionTypes } from '@minecraft/vanilla-data';
14-
import { add, subtract, cross } from '@minecraft/math';
14+
import { Vector3Utils } from '@minecraft/math';
1515

1616
const vectorA: Vector3 = {x: 1, y: 2, z:3};
1717
const vectorB: Vector3 = {x: 4, y: 5, z:6};
1818

19-
const resultAdd = add(vectorA, vectorB); // {x:5, y:7, z:9}
20-
const resultSubtract = subtract(vectorA, vectorB); // {x:-3, y:-3, z:-3}
21-
const resultAdd = cross(vectorA, vectorB); // {x:-3, y:6, z:-3}
19+
const resultAdd = Vector3Utils.add(vectorA, vectorB); // {x:5, y:7, z:9}
20+
const resultSubtract = Vector3Utils.subtract(vectorA, vectorB); // {x:-3, y:-3, z:-3}
21+
const resultAdd = Vector3Utils.cross(vectorA, vectorB); // {x:-3, y:6, z:-3}
2222

2323
console.log(toString(vectorA)); // Prints out "1, 2, 3"
2424

@@ -53,4 +53,4 @@ dimension.spawnParticle("minecraft:colored_flame_particle", vectorA);
5353
@minecraft/math is published to NPM and follows standard semver semantics. To use it in your project, there are two main options:
5454

5555
1. 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.
56-
2. This repository publishes releases for `@minecraft/math`, and on each release we attach a pre-bundled copy of the `@minecraft/math` module. Feel free to take this JS bundle and integrate into your projects as it contains all dependencies coupled together, and this pattern does not require bundling.
56+
2. This repository publishes releases for `@minecraft/math`, and on each release we attach a pre-bundled copy of the `@minecraft/math` module. Feel free to take this JS bundle and integrate into your projects as it contains all dependencies coupled together, and this pattern does not require bundling within your own project.

Diff for: libraries/math/api-report/math.api.md

+53-69
Original file line numberDiff line numberDiff line change
@@ -4,95 +4,70 @@
44
55
```ts
66

7-
import { Vector2 } from '@minecraft/server';
8-
import { Vector3 } from '@minecraft/server';
7+
import type { Vector2 } from '@minecraft/server';
8+
import type { Vector3 } from '@minecraft/server';
99

1010
// @public
11-
export function add(v1: Vector3, v2: Vector3): Vector3;
11+
export function clampNumber(val: number, min: number, max: number): number;
1212

1313
// @public
14-
export const back: Vector3;
15-
16-
// @public
17-
export function clamp(v: Vector3, limits?: {
18-
min?: Partial<Vector3>;
19-
max?: Partial<Vector3>;
20-
}): Vector3;
21-
22-
// @public
23-
export function clamp_number(val: number, min: number, max: number): number;
24-
25-
// @public
26-
export function cross(a: Vector3, b: Vector3): Vector3;
27-
28-
// @public
29-
export function dot(a: Vector3, b: Vector3): number;
30-
31-
// @public
32-
export const down: Vector3;
33-
34-
// @public
35-
export const east: Vector3;
36-
37-
// @public
38-
export function equals(v1: Vector3, v2: Vector3): boolean;
39-
40-
// @public
41-
export function floor(v: Vector3): Vector3;
14+
export class Vector2Builder implements Vector2 {
15+
constructor(vec: Vector2, arg?: never);
16+
constructor(x: number, y: number);
17+
// (undocumented)
18+
toString(options?: {
19+
decimals?: number;
20+
delimiter?: string;
21+
}): string;
22+
// (undocumented)
23+
x: number;
24+
// (undocumented)
25+
y: number;
26+
}
4227

4328
// @public
44-
export const forward: Vector3;
29+
export class Vector2Utils {
30+
static toString(v: Vector2, options?: {
31+
decimals?: number;
32+
delimiter?: string;
33+
}): string;
34+
}
4535

4636
// @public
47-
export const left: Vector3;
37+
export const VECTOR3_BACK: Vector3;
4838

4939
// @public
50-
export function magnitude(v: Vector3): number;
40+
export const VECTOR3_DOWN: Vector3;
5141

5242
// @public
53-
export function normalize(v: Vector3): Vector3;
43+
export const VECTOR3_EAST: Vector3;
5444

5545
// @public
56-
export const north: Vector3;
46+
export const VECTOR3_FORWARD: Vector3;
5747

5848
// @public
59-
export const one: Vector3;
49+
export const VECTOR3_LEFT: Vector3;
6050

6151
// @public
62-
export const right: Vector3;
52+
export const VECTOR3_NORTH: Vector3;
6353

6454
// @public
65-
export function scale(v1: Vector3, scale: number): Vector3;
55+
export const VECTOR3_ONE: Vector3;
6656

6757
// @public
68-
export const south: Vector3;
58+
export const VECTOR3_RIGHT: Vector3;
6959

7060
// @public
71-
export function subtract(v1: Vector3, v2: Vector3): Vector3;
61+
export const VECTOR3_SOUTH: Vector3;
7262

7363
// @public
74-
export const up: Vector3;
64+
export const VECTOR3_UP: Vector3;
7565

7666
// @public
77-
export class Vector2Builder implements Vector2 {
78-
constructor(vec: Vector2, arg?: never);
79-
constructor(x: number, y: number);
80-
// (undocumented)
81-
toString(options?: {
82-
decimals?: number;
83-
delimiter?: string;
84-
}): string;
85-
// (undocumented)
86-
x: number;
87-
// (undocumented)
88-
y: number;
89-
}
67+
export const VECTOR3_WEST: Vector3;
9068

9169
// @public
92-
export function vector2ToString(v: Vector2, options?: {
93-
decimals?: number;
94-
delimiter?: string;
95-
}): string;
70+
export const VECTOR3_ZERO: Vector3;
9671

9772
// @public
9873
export class Vector3Builder implements Vector3 {
@@ -125,16 +100,25 @@ export class Vector3Builder implements Vector3 {
125100
}
126101

127102
// @public
128-
export function vector3ToString(v: Vector3, options?: {
129-
decimals?: number;
130-
delimiter?: string;
131-
}): string;
132-
133-
// @public
134-
export const west: Vector3;
135-
136-
// @public
137-
export const zero: Vector3;
103+
export class Vector3Utils {
104+
static add(v1: Vector3, v2: Vector3): Vector3;
105+
static clamp(v: Vector3, limits?: {
106+
min?: Partial<Vector3>;
107+
max?: Partial<Vector3>;
108+
}): Vector3;
109+
static cross(a: Vector3, b: Vector3): Vector3;
110+
static dot(a: Vector3, b: Vector3): number;
111+
static equals(v1: Vector3, v2: Vector3): boolean;
112+
static floor(v: Vector3): Vector3;
113+
static magnitude(v: Vector3): number;
114+
static normalize(v: Vector3): Vector3;
115+
static scale(v1: Vector3, scale: number): Vector3;
116+
static subtract(v1: Vector3, v2: Vector3): Vector3;
117+
static toString(v: Vector3, options?: {
118+
decimals?: number;
119+
delimiter?: string;
120+
}): string;
121+
}
138122

139123
// (No @packageDocumentation comment for this package)
140124

Diff for: libraries/math/src/general/clamp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
*
66
* @public
77
*/
8-
export function clamp_number(val: number, min: number, max: number): number {
8+
export function clampNumber(val: number, min: number, max: number): number {
99
return Math.min(Math.max(val, min), max);
1010
}

0 commit comments

Comments
 (0)