統合版には、装備の耐久値を調べる方法がないのでスクリプトで追加した。
鍛冶台に向かってスニークすることで耐久値一覧のフォームを表示して確認できる。
function getBlockInFront(player, maxDistance = 1) {
const loc = player.location;
const dir = player.getViewDirection(); // プレイヤーの視線方向ベクトル
if(!dir) return null;
for (let i = 1; i <= maxDistance; i++) {
const x = loc.x + dir.x * i;
const y = loc.y + 0.9 + dir.y * i; // 視線の高さに補正
const z = loc.z + dir.z * i;
const block = player.dimension.getBlock({ x, y, z });
if (!block) continue;
// 空気以外なら「前方のブロック」とみなす
if (block.typeId !== "minecraft:air") {
return block;
}
}
return null;
}
// ========================================================================
// 鍛冶台の前でしゃがむと装備の耐久値一覧を表示する
// ========================================================================
system.runInterval(() => {
for (const p of world.getPlayers()){
// 前方ブロックを取得
const block = getBlockInFront(p, 1);
if (!block) continue;
// 鍛冶台か?
if (block.typeId !== "minecraft:smithing_table") continue;
// しゃがんでいるか?
if (!p.isSneaking) {
p.removeTag("smithing_ui_open");
continue;
}
// ★ Form を一度だけ出すためのタグ
if (p.hasTag("smithing_ui_open")) continue;
p.addTag("smithing_ui_open");
// 装備の耐久値一覧を作る
const eq = p.getComponent("minecraft:equippable");
if(!eq) {
p.sendMessage("§c装備情報を取得できませんでした。");
continue;
}
const slots = [
[EquipmentSlot.Mainhand, "ウェポン"],
[EquipmentSlot.Offhand, "オフハンド"],
[EquipmentSlot.Head, "ヘルメット"],
[EquipmentSlot.Chest, "チェスト"],
[EquipmentSlot.Legs, "レギンス"],
[EquipmentSlot.Feet, "ブーツ"]
];
let body = "";
for (const [slot, name] of slots) {
const item = eq.getEquipment(slot);
if (!item) {
body += `${name}: なし\n`;
continue;
}
const dura = item.getComponent("minecraft:durability");
if (!dura) {
body += `${name}: 耐久なし\n`;
continue;
}
const remain = dura.maxDurability - dura.damage;
body += `${name}: ${remain} / ${dura.maxDurability}\n`;
}
// Form UI を作成
const form = new ActionFormData()
.title("装備の耐久値一覧")
.body(body)
.button("閉じる");
form.show(p).then(() => {
// Form を閉じたらタグを消す
p.removeTag("smithing_ui_open");
});
}
}, 30);