add sounds to fast easy place and material grabber

This commit is contained in:
ForestOfLight
2025-06-08 00:34:45 -07:00
Unverified
parent c94d12347c
commit 87b5882cd8
3 changed files with 6361 additions and 5 deletions
File diff suppressed because it is too large Load Diff
+10 -1
View File
@@ -4,8 +4,9 @@ import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlo
blockIdToItemStackMap } from '../data'; blockIdToItemStackMap } from '../data';
import { Raycaster } from '../classes/Raycaster'; import { Raycaster } from '../classes/Raycaster';
import { Builders } from '../classes/Builder/Builders'; import { Builders } from '../classes/Builder/Builders';
import { blocks } from '../blocks';
const PROCESS_INTERVAL = 2; const PROCESS_INTERVAL = 2; // Fast Easy Place will attempt to place twice when at an interval of 1.
const builderOption = new BuilderOption({ const builderOption = new BuilderOption({
identifier: 'fastEasyPlace', identifier: 'fastEasyPlace',
@@ -167,6 +168,7 @@ function placeBlock(player, block, structureBlock, itemSlot) {
if (itemSlot) if (itemSlot)
consumeItem(itemSlot); consumeItem(itemSlot);
block.setPermutation(structureBlock); block.setPermutation(structureBlock);
playSoundEffect(player, structureBlock);
}); });
} }
@@ -183,4 +185,11 @@ function consumeItem(itemSlot) {
function consumeSpecial(itemSlot) { function consumeSpecial(itemSlot) {
itemSlot.setItem(new ItemStack(specialItemPlacementConversions[itemSlot.typeId.replace('minecraft:', '')])); itemSlot.setItem(new ItemStack(specialItemPlacementConversions[itemSlot.typeId.replace('minecraft:', '')]));
}
function playSoundEffect(player, structureBlock) {
const blockId = structureBlock.type.id.replace('minecraft:', '');
const blockData = blocks[blockId];
const blockSound = blockData['sound'] || 'stone';
player.dimension.playSound('dig.' + blockSound, player.location);
} }
@@ -62,6 +62,10 @@ function onPlayerInteract(event) {
} }
} }
function isActionItem(itemStack) {
return itemStack?.typeId === 'construct:material_grabber';
}
function openInstanceSelectionForm(player, event) { function openInstanceSelectionForm(player, event) {
event.cancel = true; event.cancel = true;
system.run(() => new MaterialGrabberForm(player)); system.run(() => new MaterialGrabberForm(player));
@@ -80,10 +84,6 @@ function tryGrabMaterials(player, target, focusedInstanceName, event) {
system.run(() => transferMaterialsToPlayer(player, targetContainer, materials)); system.run(() => transferMaterialsToPlayer(player, targetContainer, materials));
} }
function isActionItem(itemStack) {
return itemStack?.typeId === 'construct:material_grabber';
}
function getActiveMaterials(focusedInstanceName) { function getActiveMaterials(focusedInstanceName) {
const instance = structureCollection.get(focusedInstanceName); const instance = structureCollection.get(focusedInstanceName);
return instance?.getActiveMaterials(); return instance?.getActiveMaterials();
@@ -99,6 +99,7 @@ function transferMaterialsToPlayer(player, targetContainer, materials) {
const slot = targetContainer.getSlot(slotIndex); const slot = targetContainer.getSlot(slotIndex);
transferCount += tryTransferToPlayer(slot, playerContainer, materials); transferCount += tryTransferToPlayer(slot, playerContainer, materials);
} }
playSoundEffect(player, transferCount);
sendTransferMessage(player, transferCount); sendTransferMessage(player, transferCount);
materials.refresh(); materials.refresh();
} }
@@ -131,6 +132,11 @@ function tryTransferToPlayer(slot, playerContainer, materials) {
return 0; return 0;
} }
function playSoundEffect(player, transferCount) {
if (transferCount !== 0)
player.dimension.playSound('block.itemframe.remove_item', player.location, { pitch: 1.2 });
}
function tryTransferAmountToPlayer(slot, playerContainer, materials, grabAmount) { function tryTransferAmountToPlayer(slot, playerContainer, materials, grabAmount) {
const itemStack = slot.getItem(); const itemStack = slot.getItem();
if (canAddItem(playerContainer, itemStack)) { if (canAddItem(playerContainer, itemStack)) {