add placement sound for easyPlace, move sounds to block location & update Canopy cmd description

This commit is contained in:
ForestOfLight
2025-06-18 11:04:49 -07:00
Unverified
parent 8b6b5530fa
commit 5c5a4d65fb
3 changed files with 15 additions and 8 deletions
+11 -4
View File
@@ -124,7 +124,7 @@ function tryPlaceBlockSurvival(event, player, block, structureBlock) {
const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId);
if (itemSlotToUse) {
event.cancel = true;
placeBlock(block, structureBlock, itemSlotToUse);
placeBlock(player, block, structureBlock, itemSlotToUse);
} else {
preventAction(event, player);
}
@@ -136,12 +136,12 @@ function getPlaceableItemStack(structureBlock) {
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
}
function placeBlock(block, structureBlock, itemSlot) {
function placeBlock(player, block, structureBlock, itemSlot) {
system.run(() => {
if (itemSlot) {
if (itemSlot)
consumeItem(itemSlot);
}
block.setPermutation(structureBlock);
playSoundEffect(player, block, structureBlock);
});
}
@@ -159,3 +159,10 @@ function consumeItem(itemSlot) {
function consumeSpecial(itemSlot) {
itemSlot.setItem(new ItemStack(specialItemPlacementConversions[itemSlot.typeId.replace('minecraft:', '')]));
}
function playSoundEffect(player, block, structureBlock) {
const blockId = structureBlock.type.id.replace('minecraft:', '');
const blockData = blocks[blockId];
const blockSound = blockData['sound'] || 'stone';
player.dimension.playSound('dig.' + blockSound, block.location);
}
@@ -168,7 +168,7 @@ function placeBlock(player, block, structureBlock, itemSlot) {
if (itemSlot)
consumeItem(itemSlot);
block.setPermutation(structureBlock);
playSoundEffect(player, structureBlock);
playSoundEffect(player, block, structureBlock);
});
}
@@ -187,9 +187,9 @@ function consumeSpecial(itemSlot) {
itemSlot.setItem(new ItemStack(specialItemPlacementConversions[itemSlot.typeId.replace('minecraft:', '')]));
}
function playSoundEffect(player, structureBlock) {
function playSoundEffect(player, block, structureBlock) {
const blockId = structureBlock.type.id.replace('minecraft:', '');
const blockData = blocks[blockId];
const blockSound = blockData['sound'] || 'stone';
player.dimension.playSound('dig.' + blockSound, player.location);
player.dimension.playSound('dig.' + blockSound, block.location);
}