Add Alot
This commit is contained in:
@@ -5,6 +5,7 @@ class Level {
|
||||
levelCheckCallback: Function;
|
||||
levelSetupCallback: Function;
|
||||
levelUpdateCallback: Function;
|
||||
levelResetCallback: Function;
|
||||
isCompleted: boolean = false;
|
||||
isSetup: boolean = false;
|
||||
|
||||
@@ -12,12 +13,14 @@ class Level {
|
||||
levelSetupCallback: Function,
|
||||
levelUpdateCallback: Function,
|
||||
levelCompleteCallback: Function,
|
||||
levelCheckCallback: Function
|
||||
levelCheckCallback: Function,
|
||||
levelResetCallback: Function = () => {}
|
||||
) {
|
||||
this.levelSetupCallback = levelSetupCallback;
|
||||
this.levelCompleteCallback = levelCompleteCallback;
|
||||
this.levelCheckCallback = levelCheckCallback;
|
||||
this.levelUpdateCallback = levelUpdateCallback;
|
||||
this.levelResetCallback = levelResetCallback;
|
||||
}
|
||||
|
||||
setup() {
|
||||
@@ -37,6 +40,7 @@ class Level {
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.levelResetCallback();
|
||||
this.isCompleted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,13 @@ class TrailPoint {
|
||||
}
|
||||
|
||||
spawn() {
|
||||
let spawnPosition: Vector3 = Vector3Add(this.postion, { x: 0.5, y: 0.5, z: 0.5 });
|
||||
// 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());
|
||||
} catch (e) {}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +26,15 @@ class Trail {
|
||||
id: string;
|
||||
points: TrailPoint[] = [];
|
||||
currentPoint: number = 0;
|
||||
wrapIndex: number = 0;
|
||||
nextParticleTimer: number = 0;
|
||||
currentParticleCounter: number = 0;
|
||||
|
||||
calculatedLength: number = 0;
|
||||
constructor(id: string, nextParticleTimer: number = 5) {
|
||||
constructor(id: string, nextParticleTimer: number = 5, wrapIndex: number = 0) {
|
||||
this.id = id;
|
||||
this.nextParticleTimer = nextParticleTimer;
|
||||
this.wrapIndex = wrapIndex;
|
||||
}
|
||||
|
||||
addPoint(point: TrailPoint) {
|
||||
@@ -58,10 +59,14 @@ class Trail {
|
||||
spawnNext() {
|
||||
if (this.currentParticleCounter >= this.nextParticleTimer) {
|
||||
this.currentParticleCounter = 0;
|
||||
|
||||
//wrapindex is in how many segments the trail is divided into
|
||||
let pointsPerInterval = this.wrapIndex > 0 ? this.calculatedLength / this.wrapIndex : 0;
|
||||
this.points
|
||||
.filter((point) => {
|
||||
return point.index === this.currentPoint;
|
||||
return (
|
||||
point.index === this.currentPoint ||
|
||||
(this.wrapIndex > 0 && point.index % pointsPerInterval === this.currentPoint)
|
||||
);
|
||||
})
|
||||
.forEach((point) => {
|
||||
point.spawn();
|
||||
|
||||
@@ -60,6 +60,7 @@ export namespace TrailMaker {
|
||||
if (event.itemStack.typeId == "minecraft:stick" && event.itemStack.nameTag == "AddPoint") {
|
||||
let block = event.block;
|
||||
let pos = this.BlockToParticlePosition(block);
|
||||
world.sendMessage(`Added Point ${Vector3ToString(pos)}`);
|
||||
this.currentTrail.points.push(new Point(pos, this.currentTrail.currentPoint));
|
||||
|
||||
this.currentTrail.currentPoint++;
|
||||
@@ -80,18 +81,14 @@ export namespace TrailMaker {
|
||||
}
|
||||
|
||||
if (event.itemStack.typeId == "minecraft:stick" && event.itemStack.nameTag == "AddLine") {
|
||||
world.sendMessage(`Waiting for point 2: ${this.waitingForPoint2}`);
|
||||
if (!this.waitingForPoint2) {
|
||||
this.point1 = vector3(blockInteracted.location.x, blockInteracted.location.y, blockInteracted.location.z);
|
||||
this.point1 = Vector3Add(this.point1, vector3(0.5, 0, 0.5));
|
||||
let isHalfBlock = blockInteracted.typeId.includes("slab") || blockInteracted.typeId.includes("stair");
|
||||
if (isHalfBlock) {
|
||||
this.point1 = Vector3Add(this.point1, vector3(0, 0.5, 0));
|
||||
} else {
|
||||
this.point1 = Vector3Add(this.point1, vector3(0, 1.1, 0));
|
||||
}
|
||||
// this.point1 = vector3(blockInteracted.location.x, blockInteracted.location.y, blockInteracted.location.z);
|
||||
this.point1 = this.BlockToParticlePosition(blockInteracted);
|
||||
|
||||
this.waitingForPoint2 = true;
|
||||
Pupeteer.setActionBar("Select a second point");
|
||||
world.sendMessage("Select a second point");
|
||||
|
||||
return;
|
||||
} else {
|
||||
@@ -166,9 +163,13 @@ export namespace TrailMaker {
|
||||
}
|
||||
|
||||
Export() {
|
||||
//Convert to json, and send to the log with console.warn
|
||||
let json = JSON.stringify(this.currentTrail.points);
|
||||
console.warn(json);
|
||||
let output = "";
|
||||
for (let i = 0; i < this.currentTrail.points.length; i++) {
|
||||
let point = this.currentTrail.points[i];
|
||||
let actualPos = point.position;
|
||||
output += `{ index: ${point.index}, position: vector3(${actualPos.x}, ${actualPos.y}, ${actualPos.z}) },\n`;
|
||||
}
|
||||
console.warn(output);
|
||||
}
|
||||
|
||||
private BlockToParticlePosition(block: Block): Vector3 {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { MinecraftEntityTypes, Vector3, world } from "@minecraft/server";
|
||||
import { Entity, MinecraftEntityTypes, Vector3, world } from "@minecraft/server";
|
||||
import { Vector3ToString, vector3 } from "./vectorUtils";
|
||||
import { mindKeeper } from "../../main";
|
||||
function teleportAgent(position: Vector3) {
|
||||
world
|
||||
.getDimension("overworld")
|
||||
@@ -23,12 +24,17 @@ function isAgentAt(position: Vector3): boolean {
|
||||
return isAgentAt;
|
||||
}
|
||||
|
||||
function getAgent(): Entity {
|
||||
let agent = world.getEntity(mindKeeper.get("agentid") as string);
|
||||
return agent!;
|
||||
}
|
||||
|
||||
function getAgentLocation(): Vector3 {
|
||||
let agentLocation: Vector3 = vector3(0, 0, 0);
|
||||
// let agent = world.getEntity(mindKeeper.get("agentid") as string);
|
||||
// agentLocation = agent!.location;
|
||||
let agent = world.getEntity(mindKeeper.get("agentid") as string);
|
||||
agentLocation = agent!.location;
|
||||
|
||||
return agentLocation;
|
||||
}
|
||||
|
||||
export { teleportAgent, isAgentAt, getAgentLocation };
|
||||
export { teleportAgent, isAgentAt, getAgentLocation, getAgent };
|
||||
|
||||
@@ -218,9 +218,10 @@ function spawnParticle(
|
||||
) {
|
||||
//check if the chunk is loaded
|
||||
const chunk = world.getDimension("overworld").getBlock(position);
|
||||
if (!chunk?.isValid) {
|
||||
if (!chunk?.isValid()) {
|
||||
return;
|
||||
}
|
||||
map.setVector3("variable.direction", vector3(0, 0, 0));
|
||||
|
||||
const dimension = world.getDimension("overworld");
|
||||
if (dimension) {
|
||||
|
||||
Reference in New Issue
Block a user