UID975762性别保密经验 EP铁粒 粒回帖0主题精华在线时间 小时注册时间2023-4-1最后登录1970-1-1
|
发表于 2024-11-23 17:46:22 来自手机|显示全部楼层 IP:山东省
import { world, system, BlockPermutation } from "@minecraft/server";
function rightHandDecrementStack(player, equippable) {
if (player.matches({gameMode:'creative'})) return;
const item = equippable.getEquipment('Mainhand');
const stack = item.amount;
if (stack > 1) --item.amount;
equippable.setEquipment('Mainhand', stack > 1 ? item : null);
}
world.beforeEvents.itemUse.subscribe((event) => {
const player = event.source;
player.setDynamicProperty("xy.itemStartUse", true);
});
// ############ [玩家对方块使用道具] ############
world.beforeEvents.itemUseOn.subscribe((event) => {
const player = event.source;
if (
player.getDynamicProperty("xy.itemStartUse") != undefined &&
player.getDynamicProperty("xy.itemStartUse") == true
) {
player.setDynamicProperty("xy.itemStartUse", false);
const item = event.itemStack;
const tile = event.block;
// ++++++ 苹果 ++++++++++++
if (tile.typeId == "xy:apple_block") {
if (item.typeId == "minecraft:apple" || item.typeId == "xy:apple_block") {
const tilePerm = tile.permutation;
const stack = tilePerm.getState("block:stack");
const vertical_half = tilePerm.getState("minecraft:vertical_half");
const block_face = tilePerm.getState("minecraft:block_face");
const cardinal_direction = tilePerm.getState(
"minecraft:cardinal_direction"
);
if (stack < 3) {
system.run(() => {
const equippable = player.getComponent("equippable");
rightHandDecrementStack(player, equippable);
tile.setPermutation(
BlockPermutation.resolve(tile.typeId, {
"block:stack": stack + 1,
"minecraft:vertical_half": vertical_half,
"minecraft:block_face": block_face,
"minecraft:cardinal_direction": cardinal_direction,
})
);
player.runCommand(`/function xy/sound/placeApple`);
});
}
}
}
}
});
|
|