refactor BlockInfo & change action item to paper

This commit is contained in:
ForestOfLight
2025-04-12 14:31:30 -07:00
Unverified
parent fcc47a78a4
commit 0c90e13e2c
3 changed files with 31 additions and 27 deletions
+21 -17
View File
@@ -1,24 +1,28 @@
import { system, world } from '@minecraft/server';
import { Raycaster } from '../classes/Raycaster';
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
if (!player)
continue;
showStructureBlockInfo(player);
class BlockInfo {
static onTick() {
for (const player of world.getAllPlayers()) {
if (!player)
continue;
this.showStructureBlockInfo(player);
}
}
});
function showStructureBlockInfo(player) {
const block = Raycaster.getTargetedStructureBlock(player, { isFirst: true, collideWithWorldBlocks: true });
if (!block)
return;
player.onScreenDisplay.setActionBar({ text: getFormattedBlockInfo(block.permutation) });
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${JSON.stringify(block.getAllStates())}`;
}
}
function 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${JSON.stringify(block.getAllStates())}`;
}
system.runInterval(() => BlockInfo.onTick());