This module is made with following modules
@minecraft/server (stable API - version 1.10.0)
Space is a class which can express 3rd dimension grid. It can be used like Vector3 interface.
See the Example below.
const targetLocation: Space = Space.getByValue(1, 0, 0).tiltByView(entity.getViewDirection()).add(entity.location);
entity.dimension.spawnParticle("minecraft:basic_flame_particle", targetLocation);const basis: Space = Space.getByValue(1, 0, 0);
for (let i = 0; i < 8; ++i) {
entity.dimension.spawnParticle(
"minecraft:basic_flame_particle",
basis.yTilt(Math.PI / 4).clone().add(entity.location),
);
}- Tilting Basis with given
Vector3orSpace - Add, Subtract, Multiply, Cross with given other
Vector3orSpaceorNumber - Tilting Basis based on each axis basis (x, y, z).
- Converting into
YawandPitchwhich can be used for entity rotation - Calculating length of
Space - Verifying Grid if it's on available and script controlable position.
Yvalue increasing- Normalizing so that the
Spacehas a length 1.
When you try to tilt Space with given Vector3 or Space, Space (which is method tiltByView()) class doesn't follow the basis orientation of normal Minecraft. (like ^ ^ ^)
+x : right, -x : left
+y : up, -y : down
+z : behind, -z : front
+x : front, -x : behind
+y : up, -y : down
+z : right, -z : left
const targetLocation: Space = Space.getByValue(1, 0, 0).tiltByView(entity.getViewDirection()).add(entity.location);
entity.dimension.spawnParticle("minecraft:basic_flame_particle", targetLocation);Since the orignal Space has a value of {x: 1, y: 0, z: 0}, after tilting Space turns into 1 block front side of the entity's view direction.
If the orignal Space has a value of {x: -2, y: 0, z: 0}, after tilting Space turns into 2 block back side of the entity's view direction.
If the orignal Space has a value of {x: 0, y: 0, z: 3}, after tilting Space turns into 3 block right side of the entity's view direction.
And most of method change the Instance's value. If you want to get a new Instance with a calculation, use clone() method and then use other method you want.
const basis: Space = Spcae.getByValue(1, 0, 0);
const basis2: Space = Spcae.getByValue(1, 0, 0);
const a = basis.up(1); // basis and a value : { x: 1, y: 1, z : 0 }
const b = basis.up(1); // basis and b value : { x: 1, y: 2, z : 0 }
const c = basis.up(1); // basis and c value : { x: 1, y: 3, z : 0 }
/**
basis2 value : { x: 1, y: 0, z : 0 } -> not changed
basis3 value : { x: 1, y: 1, z : 0 }
**/
const basis3 = basis2.clone().up(1);