feat: Add cracked glass block and texture

Added the cracked glass block and its corresponding texture to the resource packs. Also made changes to the maker.ts file to include a save operation. Additionally, added a new behavior pack for the cracked glass block with specific properties. Updated the vectorUtils.ts file to include a new function for converting a Vector3 object to a command string. Finally, made changes to the triggers.ts file to register new triggers and update existing ones.
This commit is contained in:
Bram Verhulst
2024-07-05 14:14:17 +02:00
parent 67af73c6b5
commit ba384d79d8
13 changed files with 697 additions and 129 deletions

View File

@@ -1,72 +0,0 @@
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<string, number> = 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;
}
}
}

View File

@@ -54,6 +54,7 @@ export class Maker {
} else {
world.sendMessage("No trigger to delete");
}
this.manager.Save();
}
const command = event.message.split(" ")[0];
if (command == "!setFunction") {

View File

@@ -0,0 +1,70 @@
class Chalk {
static red(text: string): string {
return "§c" + text + "§r";
}
static yellow(text: string): string {
return "§e" + text + "§r";
}
static green(text: string): string {
return "§a" + text + "§r";
}
static blue(text: string): string {
return "§9" + text + "§r";
}
static aqua(text: string): string {
return "§b" + text + "§r";
}
static white(text: string): string {
return "§f" + text + "§r";
}
static black(text: string): string {
return "§0" + text + "§r";
}
static gold(text: string): string {
return "§6" + text + "§r";
}
static gray(text: string): string {
return "§7" + text + "§r";
}
static darkRed(text: string): string {
return "§4" + text + "§r";
}
static darkGreen(text: string): string {
return "§2" + text + "§r";
}
static darkBlue(text: string): string {
return "§1" + text + "§r";
}
static darkAqua(text: string): string {
return "§3" + text + "§r";
}
static darkPurple(text: string): string {
return "§5" + text + "§r";
}
static darkGray(text: string): string {
return "§8" + text + "§r";
}
static lightPurple(text: string): string {
return "§d" + text + "§r";
}
static bold(text: string): string {
return "§l" + text + "§r";
}
static italic(text: string): string {
return "§o" + text + "§r";
}
static underline(text: string): string {
return "§n" + text + "§r";
}
static strikethrough(text: string): string {
return "§m" + text + "§r";
}
static obfuscated(text: string): string {
return "§k" + text + "§r";
}
static reset(text: string): string {
return "§r" + text + "§r";
}
}
export default Chalk;

View File

@@ -1,14 +1,19 @@
import { RawText, TicksPerSecond, TitleDisplayOptions, Vector3, World, system } from "@minecraft/server";
import {
EntityInventoryComponent,
ItemStack,
Player,
RawText,
TicksPerSecond,
TitleDisplayOptions,
Vector3,
World,
system,
world,
} from "@minecraft/server";
import { delayedRun } from "./utils/waitUtil";
class Pupeteer {
world: World;
constructor(world: World) {
this.world = world;
}
private getActualString(message: string): string | RawText {
private static getActualString(message: string): string | RawText {
if (message.startsWith("%")) {
const key = message.substring(1);
return { rawtext: [{ translate: key }] };
@@ -16,27 +21,31 @@ class Pupeteer {
return message;
}
setActionBarTimed(message: string, duration: number): void {
this.world.getPlayers().forEach((player) => {
player.onScreenDisplay.setActionBar(this.getActualString(message));
static setActionBarTimed(message: string, duration: number): void {
world.getPlayers().forEach((player) => {
system.run(() => {
player.onScreenDisplay.setActionBar(this.getActualString(message));
});
});
delayedRun(() => {
this.clearActionBar();
}, duration * TicksPerSecond);
}
setActionBar(message: string): void {
this.world.getPlayers().forEach((player) => {
player.onScreenDisplay.setActionBar(this.getActualString(message));
static setActionBar(message: string): void {
world.getPlayers().forEach((player) => {
system.run(() => {
player.onScreenDisplay.setActionBar(this.getActualString(message));
});
});
}
sendWorldMessage(message: string): void {
this.world.sendMessage(this.getActualString(message));
static sendWorldMessage(message: string): void {
world.sendMessage(this.getActualString(message));
}
setTitleTimed(message: string, duration: number): void {
this.world.getPlayers().forEach((player) => {
static setTitleTimed(message: string, duration: number): void {
world.getPlayers().forEach((player) => {
let options: TitleDisplayOptions = {
fadeInDuration: 20,
fadeOutDuration: 20,
@@ -46,39 +55,39 @@ class Pupeteer {
});
}
setTitle(message: string): void {
this.world.getPlayers().forEach((player) => {
static setTitle(message: string): void {
world.getPlayers().forEach((player) => {
player.onScreenDisplay.setTitle(message);
});
}
updateSubtitle(message: string): void {
this.world.getPlayers().forEach((player) => {
static updateSubtitle(message: string): void {
world.getPlayers().forEach((player) => {
player.onScreenDisplay.updateSubtitle(this.getActualString(message));
});
}
clearTitle(): void {
this.world.getPlayers().forEach((player) => {
static clearTitle(): void {
world.getPlayers().forEach((player) => {
player.onScreenDisplay.setTitle("");
});
}
clearSubtitle(): void {
this.world.getPlayers().forEach((player) => {
static clearSubtitle(): void {
world.getPlayers().forEach((player) => {
player.onScreenDisplay.updateSubtitle("");
});
}
clearActionBar(): void {
this.world.getPlayers().forEach((player) => {
static clearActionBar(): void {
world.getPlayers().forEach((player) => {
player.onScreenDisplay.setActionBar("");
});
}
testForLocation(location: Vector3, radius: number): boolean {
static testForLocation(location: Vector3, radius: number): boolean {
let isPlayerInArea = false;
this.world.getPlayers().forEach((player) => {
world.getPlayers().forEach((player) => {
let dx = location.x - player.location.x;
let dy = location.y - player.location.y;
let dz = location.z - player.location.z;
@@ -91,8 +100,12 @@ class Pupeteer {
return isPlayerInArea;
}
setNpcText(npcTag: string, sceneName: string) {
this.world.getDimension("overworld").runCommand(`/dialogue change @e[tag=${npcTag}] ${sceneName} @a`);
static setNpcText(npcTag: string, sceneName: string) {
world.getDimension("overworld").runCommand(`/dialogue change @e[tag=${npcTag}] ${sceneName} @a`);
}
static givePlayerItem(player: Player, item: ItemStack) {
(player.getComponent("inventory") as EntityInventoryComponent).container.addItem(item);
}
}

View File

@@ -0,0 +1,211 @@
import {
Block,
ChatSendAfterEvent,
EntityInventoryComponent,
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";
import Pupeteer from "../pupeteer";
import Chalk from "../chalk";
export namespace TrailMaker {
export class Maker {
currentTrail: Trail;
log: Map<string, number> = new Map();
selectedIndex: number = 0;
//Line
point1: Vector3 = vector3(0, 0, 0);
point2: Vector3 = vector3(0, 0, 0);
waitingForPoint2: boolean = false;
OnChat(event: ChatSendAfterEvent) {
if (event.message == "!trailWand") {
let item: ItemStack = new ItemStack("minecraft:stick");
item.nameTag = "AddPoint";
Pupeteer.givePlayerItem(event.sender as Player, item);
world.sendMessage("Thou shall have the Trailing Powah");
}
if (event.message == "!trailDeleteWand") {
let item: ItemStack = new ItemStack("minecraft:stick");
item.nameTag = "DeletePoint";
Pupeteer.givePlayerItem(event.sender as Player, item);
world.sendMessage("Luke, i'm NOT your father");
}
if (event.message == "!trailLineWand") {
let item: ItemStack = new ItemStack("minecraft:stick");
item.nameTag = "AddLine";
Pupeteer.givePlayerItem(event.sender as Player, item);
world.sendMessage(`This is where i draw the ${Chalk.red("Line")} >:(`);
}
if (event.message == "!trailExport") {
this.Export();
}
}
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 block = event.block;
let pos = this.BlockToParticlePosition(block);
this.currentTrail.points.push(new Point(pos, this.currentTrail.currentPoint));
this.currentTrail.currentPoint++;
Pupeteer.setActionBarTimed(`Added point ${this.currentTrail.currentPoint}`, 3);
}
if (event.itemStack.typeId == "minecraft:stick" && event.itemStack.nameTag == "DeletePoint") {
let block = event.block;
let pos = this.BlockToParticlePosition(block);
let point = this.currentTrail.points.find((point) => Vector3ToString(point.position) == Vector3ToString(pos));
if (point) {
this.currentTrail.points.splice(this.currentTrail.points.indexOf(point), 1);
Pupeteer.setActionBarTimed(`Deleted point ${point.index}`, 3);
} else {
Pupeteer.setActionBarTimed(`No point found`, 3);
}
}
if (event.itemStack.typeId == "minecraft:stick" && event.itemStack.nameTag == "AddLine") {
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.waitingForPoint2 = true;
Pupeteer.setActionBar("Select a second point");
return;
} else {
this.point2 = this.BlockToParticlePosition(blockInteracted);
//Calculate the blocks between these 2 points, andd add them to the trail
//Assume point1 is the start, and point2 is the end
let x1 = this.point1.x;
let x2 = this.point2.x;
let y1 = this.point1.y;
let y2 = this.point2.y;
let z1 = this.point1.z;
let z2 = this.point2.z;
//Find out what axis is the movement on, throw an error if it's on more than one axis
let xDiff = Math.abs(x2 - x1);
let yDiff = Math.abs(y2 - y1);
let zDiff = Math.abs(z2 - z1);
let axis = "";
if (xDiff > 0 && yDiff == 0 && zDiff == 0) {
axis = "x";
} else if (xDiff == 0 && yDiff > 0 && zDiff == 0) {
axis = "y";
} else if (xDiff == 0 && yDiff == 0 && zDiff > 0) {
axis = "z";
} else {
Pupeteer.setActionBarTimed("Invalid line", 3);
return;
}
let start = 0;
let end = 0;
if (axis == "x") {
start = Math.min(x1, x2);
end = Math.max(x1, x2);
} else if (axis == "y") {
start = Math.min(y1, y2);
end = Math.max(y1, y2);
} else if (axis == "z") {
start = Math.min(z1, z2);
end = Math.max(z1, z2);
}
for (let i = start; i <= end; i++) {
let pos = vector3(0, 0, 0);
if (axis == "x") {
pos = vector3(i, y1, z1);
} else if (axis == "y") {
pos = vector3(x1, i, z1);
} else if (axis == "z") {
pos = vector3(x1, y1, i);
}
this.currentTrail.points.push(new Point(pos, this.currentTrail.currentPoint));
this.currentTrail.currentPoint++;
}
this.waitingForPoint2 = false;
Pupeteer.setActionBarTimed("Added line", 3);
}
}
}
Update() {
this.currentTrail.points.forEach((point) => {
spawnParticle(point.position, "minecraft:balloon_gas_particle", new MolangVariableMap());
});
}
Export() {
//Convert to json, and send to the log with console.warn
let json = JSON.stringify(this.currentTrail.points);
console.warn(json);
}
private BlockToParticlePosition(block: Block): Vector3 {
let pos = vector3(block.location.x, block.location.y, block.location.z);
pos = Vector3Add(pos, vector3(0.5, 0, 0.5));
//If block is a slab or stair, offset by half a block
let isHalfBlock = block.typeId.includes("slab") || block.typeId.includes("stair");
if (isHalfBlock) {
pos = Vector3Add(pos, vector3(0, 0.5, 0));
} else {
pos = Vector3Add(pos, vector3(0, 1.1, 0));
}
return pos;
}
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;
}
}
}

View File

@@ -8,6 +8,10 @@ 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)}}`;
}
@@ -62,5 +66,6 @@ export {
Vector3Round,
Vector3Abs,
vector3Distance,
Vector3ToCommandString,
vector3,
};