Files
Construct-CN/scripts/classes/BlockInfo.js
T
2025-04-12 20:05:10 -07:00

32 lines
1.1 KiB
JavaScript

import { system, world } from '@minecraft/server';
import { Raycaster } from '../classes/Raycaster';
class BlockInfo {
static onTick() {
for (const player of world.getAllPlayers()) {
if (!player)
continue;
this.showStructureBlockInfo(player);
}
}
static showStructureBlockInfo(player) {
const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true });
if (!block)
return;
player.onScreenDisplay.setActionBar({ text: this.getFormattedBlockInfo(block.permutation) });
}
static getFormattedBlockInfo(block) {
const states = block.getAllStates();
if (Object.keys(states).length === 0)
return `Structure:\n§a${block.type.id}`;
return `Structure:\n§a${block.type.id}\n§7${this.getFormattedStates(states)}`;
}
static getFormattedStates(states) {
return Object.entries(states).map(([key, value]) => `§7${key}: ${value}`).join('\n');
}
}
system.runInterval(() => BlockInfo.onTick());