import { Block, ChatSendAfterEvent, ItemStack, ItemUseOnBeforeEvent, MolangVariableMap, Player, world, } from "@minecraft/server"; import { Vector3 } from "@minecraft/server"; import { Vector3Add, Vector3ToString, vector3 } from "../utils/vectorUtils"; import { spawnParticle } from "../utils/particleUtils"; export namespace TrailMaker { export class Maker { currentTrail: Trail; log: Map = new Map(); selectedIndex: number = 0; OnChat(event: ChatSendAfterEvent) {} OnItemUse(event: ItemUseOnBeforeEvent) { const currentItemHeld: ItemStack = event.itemStack; const blockInteracted: Block = event.block; const player: Player = event.source as Player; const oldLog = this.log.get(player.name)!; this.log.set(player.name, Date.now()); if (oldLog + 150 >= Date.now()) return; if (event.itemStack.typeId == "minecraft:stick" && event.itemStack.nameTag == "AddPoint") { let pos = vector3(event.block.location.x, event.block.location.y, event.block.location.z); pos = Vector3Add(pos, vector3(0.5, 0, 0.5)); pos = Vector3Add(pos, vector3(0, 1.1, 0)); this.currentTrail.points.push(new Point(pos, this.currentTrail.currentPoint)); //offset by half a block this.currentTrail.currentPoint++; world.sendMessage(`Added point ${this.currentTrail.currentPoint}`); } } Update() { this.currentTrail.points.forEach((point) => { spawnParticle(point.position, "minecraft:balloon_gas_particle", new MolangVariableMap()); }); } Export() {} constructor() { this.currentTrail = new Trail(); } } class Trail { points: Point[] = []; currentPoint: number = 0; nextParticleTimer: number = 0; currentParticleCounter: number = 0; constructor() {} } class Point { position: Vector3; index: number; constructor(position: Vector3, index: number) { this.position = position; this.index = index; } } }