Before Format Wars
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { MolangVariableMap, Vector3, world } from "@minecraft/server";
|
||||
import { Vector3Add } from "../utils/vectorUtils";
|
||||
import { TrailType } from "./trailTypes";
|
||||
import { PARTICLES, spawnParticle } from "../utils/particleUtils";
|
||||
|
||||
class TrailPoint {
|
||||
postion: Vector3;
|
||||
@@ -15,9 +16,7 @@ class TrailPoint {
|
||||
// let spawnPosition: Vector3 = Vector3Add(this.postion, { x: 0.5, y: 0.5, z: 0.5 });
|
||||
let spawnPosition: Vector3 = this.postion;
|
||||
try {
|
||||
world
|
||||
.getDimension("overworld")
|
||||
.spawnParticle("minecraft:balloon_gas_particle", spawnPosition, new MolangVariableMap());
|
||||
spawnParticle(spawnPosition, PARTICLES.balloon_gas_particle, new MolangVariableMap());
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
@@ -40,19 +39,14 @@ class Trail {
|
||||
addPoint(point: TrailPoint) {
|
||||
this.points.push(point);
|
||||
|
||||
//this could be a one liner,
|
||||
let maxlength: number = 0;
|
||||
this.points.forEach((point) => {
|
||||
if (point.index > maxlength) {
|
||||
maxlength = point.index;
|
||||
}
|
||||
});
|
||||
this.calculatedLength = maxlength;
|
||||
this.calculatedLength = this.points.length;
|
||||
}
|
||||
|
||||
fromTrail(trail: TrailType) {
|
||||
let currentIndex = 0;
|
||||
trail.points.forEach((point) => {
|
||||
this.addPoint(new TrailPoint(point.position, point.index));
|
||||
this.addPoint(new TrailPoint(point.position, currentIndex));
|
||||
currentIndex++;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,17 +57,19 @@ class Trail {
|
||||
let pointsPerInterval = this.wrapIndex > 0 ? this.calculatedLength / this.wrapIndex : 0;
|
||||
this.points
|
||||
.filter((point) => {
|
||||
return (
|
||||
point.index === this.currentPoint ||
|
||||
(this.wrapIndex > 0 && point.index % pointsPerInterval === this.currentPoint)
|
||||
);
|
||||
if (this.wrapIndex > 0) {
|
||||
return point.index % this.wrapIndex == this.currentPoint;
|
||||
} else {
|
||||
return point.index == this.currentPoint;
|
||||
}
|
||||
})
|
||||
.forEach((point) => {
|
||||
point.spawn();
|
||||
});
|
||||
|
||||
this.currentPoint++;
|
||||
if (this.currentPoint >= this.calculatedLength) {
|
||||
let actualLength = this.wrapIndex > 0 ? this.wrapIndex : this.calculatedLength;
|
||||
if (this.currentPoint >= actualLength) {
|
||||
this.currentPoint = 0;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user