This commit is contained in:
2024-08-07 09:45:15 +02:00
commit 9d7b1e71ce
88 changed files with 21647 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import { Entity, Vector3, world } from "@minecraft/server";
import { Vector3ToString, vector3 } from "./vectorUtils";
import { mindKeeper } from "../../main";
function teleportAgent(position: Vector3) {
world
.getDimension("overworld")
.runCommand(`/execute as @a run tp @e[type=agent] ${position.x} ${position.y} ${position.z}`);
}
function isAgentAt(position: Vector3): boolean {
let isAgentAt: boolean = false;
world
.getDimension("overworld")
.getEntitiesAtBlockLocation(position)
.forEach((entity) => {
if (!entity.isValid()) {
world.sendMessage("INVALID ENTITY");
return;
}
if (entity.typeId == "minecraft:agent") {
isAgentAt = true;
}
});
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;
return agentLocation;
}
export { teleportAgent, isAgentAt, getAgentLocation, getAgent };

View File

@@ -0,0 +1,62 @@
import { MolangVariableMap, Vector3, world } from "@minecraft/server";
import { Vector3Add, vector3 } from "./vectorUtils";
import { PARTICLES, spawnParticle } from "./particleUtils";
let arrowTemplate: Vector3[] = [
vector3(0, 0, 0),
vector3(1, 1, 0),
vector3(-1, 1, 0),
vector3(1.5, 2, 0),
vector3(-1.5, 2, 0),
vector3(2, 3, 0),
vector3(-2, 3, 0),
vector3(0, 1, 0),
vector3(0, 2, 0),
vector3(0, 3, 0),
vector3(0, 4, 0),
vector3(0, 5, 0),
];
let offset: Vector3 = vector3(0, 0, 0);
let angleOffset = 0;
let heightBobbing = 0;
let tickCounter = 0;
function rotate(pos: Vector3, angle: number) {
let x = pos.x;
let z = pos.z;
let newX = x * Math.cos(angle) - z * Math.sin(angle);
let newZ = x * Math.sin(angle) + z * Math.cos(angle);
return vector3(newX, pos.y, newZ);
}
const particleData = new MolangVariableMap();
particleData.setColorRGB("variable.color", {
red: 1,
green: 1,
blue: 1,
});
function drawArrow(offsetPos: Vector3) {
tickCounter++;
if (tickCounter % 2 == 0) {
angleOffset += 0.1;
heightBobbing += 0.3;
offset = vector3(46.5, 75, 220.5);
arrowTemplate.forEach((pos) => {
let rotatedPos = rotate(pos, angleOffset);
let finalPos = Vector3Add(offsetPos, rotatedPos);
finalPos.y += Math.sin(heightBobbing) / 2;
spawnParticle(finalPos, PARTICLES.point, particleData);
});
}
}
export { drawArrow };

View File

@@ -0,0 +1,24 @@
import { BlockType, BlockTypes, BlockVolume, Vector3, world } from "@minecraft/server";
import { MinecraftBlockTypes } from "../../vanilla-data/mojang-block";
type Wall = {
startPos: Vector3;
endPos: Vector3;
};
function clearWall(wall: Wall) {
let volume: BlockVolume = new BlockVolume(wall.startPos, wall.endPos);
world.getDimension("overworld").fillBlocks(volume, MinecraftBlockTypes.Air);
}
function fillWall(wall: Wall, block: BlockType) {
let volume: BlockVolume = new BlockVolume(wall.startPos, wall.endPos);
world.getDimension("overworld").fillBlocks(volume, block);
}
function startLevel(commandBlockPos: Vector3) {
let volume: BlockVolume = new BlockVolume(commandBlockPos, commandBlockPos);
world.getDimension("overworld").fillBlocks(volume, MinecraftBlockTypes.RedstoneBlock);
}
BlockTypes;
export { Wall, clearWall, fillWall, startLevel };

View File

@@ -0,0 +1,232 @@
import { MolangVariableMap, Vector3, world } from "@minecraft/server";
import { Vector3Add, vector3 } from "./vectorUtils";
const bedrockParticles = [
"minecraft:mobspell_emitter",
"minecraft:villager_angry",
"minecraft:bleach",
"minecraft:breaking_item_icon",
"minecraft:blockdust",
"minecraft:bubble_column_up_particle",
"minecraft:compfire_smoke_particle",
"minecraft:campfire_tall_smoke_particle",
"minecraft:cherry_leaves_particle",
"minecraft:crop_growth_emitter",
"minecraft:conduit_particle",
"minecraft:critical_hit_emitter",
"minecraft:bubble_column_down_particle",
"minecraft:dolphin_move_particle",
"minecraft:dragon_breath_trail",
"minecraft:dragon_breath_lingering",
"minecraft:lava_drip_particle",
"minecraft:water_drip_particle",
"minecraft:redstone_wire_dust_particle",
"minecraft:sculk_sensor_redstone_particle",
"minecraft:splash_spell_emitter",
"minecraft:electric_spark__particle",
"minecraft:enchanting_table_particle",
"minecraft:endrod",
"minecraft:balloon_gas_particle",
"minecraft:evoker_spell",
"minecraft:huge_explosion_emitter",
"minecraft:falling_dust_red_sand_particle",
"minecraft:falling_dust_sand_particle",
"minecraft:falling_dust_gravel_particle",
"minecraft:falling_dust_top_snow_particle",
"minecraft:falling_dust_dragon_egg_particle",
"minecraft:falling_dust_concrete_particle",
"minecraft:falling_dust_scaffolding_particle",
"minecraft:honey_drip_particle",
"minecraft:nectar_drip_particle",
"minecraft:obsidian_tear_particle",
"minecraft:spore_blossom_shower_particle",
"minecraft:water_splash_particle",
"minecraft:sparkler_emitter",
"minecraft:water_wake_particle",
"minecraft:basic_flame_particle",
"minecraft:flash",
"minecraft:glow_particle",
"minecraft:villager_happy",
"minecraft:heart_particle",
"minecraft:water_evaporation_actor_emitter",
"minecraft:lava_particle",
"minecraft:mobflame_emitter",
"minecraft:mobflame_single",
"minecraft:mycelium_dust_particle",
"minecraft:note_particle",
"minecraft:explode",
"minecraft:mob_portal",
"minecraft:rainsplash",
"minecraft:basic_smoke_particle",
"minecraft:snowflake_particle",
"minecraft:soul_particle",
"minecraft:blue_flame_particle",
"minecraft:spore_blossom_ambient_particle",
"minecraft:watersplash",
"minecraft:terrain",
"minecraft:totem_particle",
"minecraft:tracking_emitter",
"minecraft:vibration_signal",
"minecraft:wax_particle",
"minecraft:witchspell",
];
const PARTICLES = {
mobspell_emitter: "minecraft:mobspell_emitter",
villager_angry: "minecraft:villager_angry",
bleach: "minecraft:bleach",
breaking_item_icon: "minecraft:breaking_item_icon",
blockdust: "minecraft:blockdust",
bubble_column_up_particle: "minecraft:bubble_column_up_particle",
compfire_smoke_particle: "minecraft:compfire_smoke_particle",
campfire_tall_smoke_particle: "minecraft:campfire_tall_smoke_particle",
cherry_leaves_particle: "minecraft:cherry_leaves_particle",
crop_growth_emitter: "minecraft:crop_growth_emitter",
conduit_particle: "minecraft:conduit_particle",
critical_hit_emitter: "minecraft:critical_hit_emitter",
bubble_column_down_particle: "minecraft:bubble_column_down_particle",
dolphin_move_particle: "minecraft:dolphin_move_particle",
dragon_breath_trail: "minecraft:dragon_breath_trail",
dragon_breath_lingering: "minecraft:dragon_breath_lingering",
lava_drip_particle: "minecraft:lava_drip_particle",
water_drip_particle: "minecraft:water_drip_particle",
redstone_wire_dust_particle: "minecraft:redstone_wire_dust_particle",
sculk_sensor_redstone_particle: "minecraft:sculk_sensor_redstone_particle",
splash_spell_emitter: "minecraft:splash_spell_emitter",
electric_spark__particle: "minecraft:electric_spark__particle",
enchanting_table_particle: "minecraft:enchanting_table_particle",
endrod: "minecraft:endrod",
balloon_gas_particle: "minecraft:balloon_gas_particle",
evoker_spell: "minecraft:evoker_spell",
huge_explosion_emitter: "minecraft:huge_explosion_emitter",
falling_dust_red_sand_particle: "minecraft:falling_dust_red_sand_particle",
falling_dust_sand_particle: "minecraft:falling_dust_sand_particle",
falling_dust_gravel_particle: "minecraft:falling_dust_gravel_particle",
falling_dust_top_snow_particle: "minecraft:falling_dust_top_snow_particle",
falling_dust_dragon_egg_particle: "minecraft:falling_dust_dragon_egg_particle",
falling_dust_concrete_particle: "minecraft:falling_dust_concrete_particle",
falling_dust_scaffolding_particle: "minecraft:falling_dust_scaffolding_particle",
honey_drip_particle: "minecraft:honey_drip_particle",
nectar_drip_particle: "minecraft:nectar_drip_particle",
obsidian_tear_particle: "minecraft:obsidian_tear_particle",
spore_blossom_shower_particle: "minecraft:spore_blossom_shower_particle",
water_splash_particle: "minecraft:water_splash_particle",
sparkler_emitter: "minecraft:sparkler_emitter",
water_wake_particle: "minecraft:water_wake_particle",
basic_flame_particle: "minecraft:basic_flame_particle",
flash: "minecraft:flash",
glow_particle: "minecraft:glow_particle",
villager_happy: "minecraft:villager_happy",
heart_particle: "minecraft:heart_particle",
water_evaporation_actor_emitter: "minecraft:water_evaporation_actor_emitter",
lava_particle: "minecraft:lava_particle",
mobflame_emitter: "minecraft:mobflame_emitter",
mobflame_single: "minecraft:mobflame_single",
mycelium_dust_particle: "minecraft:mycelium_dust_particle",
note_particle: "minecraft:note_particle",
explode: "minecraft:explode",
mob_portal: "minecraft:mob_portal",
rainsplash: "minecraft:rainsplash",
basic_smoke_particle: "minecraft:basic_smoke_particle",
snowflake_particle: "minecraft:snowflake_particle",
soul_particle: "minecraft:soul_particle",
blue_flame_particle: "minecraft:blue_flame_particle",
spore_blossom_ambient_particle: "minecraft:spore_blossom_ambient_particle",
watersplash: "minecraft:watersplash",
terrain: "minecraft:terrain",
totem_particle: "minecraft:totem_particle",
tracking_emitter: "minecraft:tracking_emitter",
vibration_signal: "minecraft:vibration_signal",
wax_particle: "minecraft:wax_particle",
witchspell: "minecraft:witchspell",
point: "codecosmos:point",
};
class ParticleColumn {
pos: Vector3;
radius: number;
pointsPerLayer: number;
layerCount: number;
particle: string;
points: Vector3[] = [];
speed: number;
anglePerLayer: number[] = [];
tickCounter: number = 0;
constructor(
pos: Vector3,
radius: number,
pointsPerLayer: number,
layerCount: number,
speed: number,
particle: string
) {
this.pos = pos;
this.radius = radius;
this.particle = particle;
this.pointsPerLayer = pointsPerLayer;
this.layerCount = layerCount;
this.speed = speed;
this.generatePoints();
}
generatePoints() {
for (let layer = 0; layer < this.layerCount; layer++) {
let layerRadius = this.radius - layer;
for (let point = 0; point < this.pointsPerLayer; point++) {
let angle = (point / this.pointsPerLayer) * (Math.PI * 2);
this.anglePerLayer.push(angle);
let x = Math.cos(angle) * layerRadius;
let z = Math.sin(angle) * layerRadius;
let y = layer;
this.points.push(Vector3Add(this.pos, vector3(x, y, z)));
}
}
}
update() {
//update each point by increasing the angle by the speed
let layerCount = 0;
let pointCount = 0;
this.tickCounter++;
if (this.tickCounter % 2 == 0) {
this.points.forEach((point, index) => {
let layer = Math.floor(index / this.pointsPerLayer);
let angle = this.anglePerLayer[index];
angle += this.speed * (layer / 5);
this.anglePerLayer[index] = angle;
let layerRadius = this.radius - Math.floor(index / this.pointsPerLayer);
let calcAngle = angle;
let x = Math.cos(calcAngle) * this.radius;
let z = Math.sin(calcAngle) * this.radius;
let y = Math.floor(index / this.pointsPerLayer) + (this.tickCounter % 2);
this.points[index] = Vector3Add(this.pos, vector3(x, y, z));
});
}
}
draw() {
this.points.forEach((point) => {
spawnParticle(point);
});
}
}
function spawnParticle(
position: Vector3,
particle: string = PARTICLES.balloon_gas_particle,
map: MolangVariableMap = new MolangVariableMap()
) {
//check if the chunk is loaded
const chunk = world.getDimension("overworld").getBlock(position);
if (!chunk?.isValid()) {
return;
}
map.setVector3("variable.direction", vector3(0, 0, 0));
const dimension = world.getDimension("overworld");
if (dimension) {
dimension.spawnParticle(particle, position, map);
}
}
export { PARTICLES, bedrockParticles, ParticleColumn, spawnParticle };

View File

@@ -0,0 +1,71 @@
import { Vector3 } from "@minecraft/server";
function vector3(x: number, y: number, z: number): Vector3 {
return { x: x, y: y, z: z };
}
function Vector3ToString(vector: Vector3) {
return vector.x + "," + vector.y + "," + vector.z;
}
function Vector3ToCommandString(vector: Vector3) {
return `${vector.x} ${vector.y} ${vector.z}`;
}
function Vector3ToFancyString(vector: Vector3) {
return `{X: ${Math.floor(vector.x)}, Y: ${Math.floor(vector.y)}, Z: ${Math.floor(vector.z)}}`;
}
function Vector3Add(vector1: Vector3, vector2: Vector3): Vector3 {
return { x: vector1.x + vector2.x, y: vector1.y + vector2.y, z: vector1.z + vector2.z };
}
function Vector3Subtract(vector1: Vector3, vector2: Vector3): Vector3 {
return { x: vector1.x - vector2.x, y: vector1.y - vector2.y, z: vector1.z - vector2.z };
}
function Vector3Multiply(vector1: Vector3, vector2: Vector3): Vector3 {
return { x: vector1.x * vector2.x, y: vector1.y * vector2.y, z: vector1.z * vector2.z };
}
function Vector3Divide(vector1: Vector3, vector2: Vector3): Vector3 {
return { x: vector1.x / vector2.x, y: vector1.y / vector2.y, z: vector1.z / vector2.z };
}
function Vector3Floor(vector: Vector3): Vector3 {
return { x: Math.floor(vector.x), y: Math.floor(vector.y), z: Math.floor(vector.z) };
}
function Vector3Ceil(vector: Vector3): Vector3 {
return { x: Math.ceil(vector.x), y: Math.ceil(vector.y), z: Math.ceil(vector.z) };
}
function Vector3Round(vector: Vector3): Vector3 {
return { x: Math.round(vector.x), y: Math.round(vector.y), z: Math.round(vector.z) };
}
function Vector3Abs(vector: Vector3): Vector3 {
return { x: Math.abs(vector.x), y: Math.abs(vector.y), z: Math.abs(vector.z) };
}
function vector3Distance(vector1: Vector3, vector2: Vector3): number {
return Math.sqrt(
Math.pow(vector2.x - vector1.x, 2) + Math.pow(vector2.y - vector1.y, 2) + Math.pow(vector2.z - vector1.z, 2)
);
}
export {
Vector3ToString,
Vector3ToFancyString,
Vector3Add,
Vector3Subtract,
Vector3Multiply,
Vector3Divide,
Vector3Floor,
Vector3Ceil,
Vector3Round,
Vector3Abs,
vector3Distance,
Vector3ToCommandString,
vector3,
};

View File

@@ -0,0 +1,16 @@
import { system } from "@minecraft/server";
function delayedRun(callback: Function, delay: number) {
let timer = system.runTimeout(() => {
callback();
system.clearRun(timer);
}, delay);
}
function delay(t: number) {
return new Promise((r: any) => {
system.runTimeout(r, t);
});
}
export { delayedRun, delay };

View File

@@ -0,0 +1,34 @@
import { Vector3, world } from "@minecraft/server";
function clone(startPos: Vector3, endPos: Vector3, destination: Vector3) {
world
.getDimension("overworld")
.runCommand(
`clone ${startPos.x} ${startPos.y} ${startPos.z} ${endPos.x} ${endPos.y} ${endPos.z} ${destination.x} ${destination.y} ${destination.z} replace normal`
);
}
enum LeverDirection {
DownEastWest = "down_east_west",
DownNorthSouth = "down_north_south",
East = "east",
North = "north",
South = "south",
UpEastWest = "up_east_west",
UpNorthSouth = "up_north_south",
West = "west",
}
function setLever(pos: Vector3, direction: LeverDirection, isOpen: boolean) {
world
.getDimension("overworld")
.runCommandAsync(
`/setblock ${pos.x} ${pos.y} ${pos.z} lever["lever_direction":"${direction}","open_bit":${
isOpen ? "true" : "false"
}]`
);
///setblock 53 70 216 lever["lever_direction"="down_east_west","open_bit"=false]
}
export { clone, LeverDirection, setLever };