functional on 1.21.90

This commit is contained in:
ForestOfLight
2025-06-18 12:03:57 -07:00
Unverified
parent 5c5a4d65fb
commit 59615312c8
7 changed files with 66 additions and 82 deletions
+34
View File
@@ -1,5 +1,7 @@
import { system, EntityComponentTypes } from '@minecraft/server';
import { FormCancelationReason } from '@minecraft/server-ui';
import { specialItemPlacementConversions } from './data';
import { blocks } from './blocks';
export async function forceShow(player, form, timeout = Infinity) {
const startTick = system.currentTick;
@@ -24,4 +26,36 @@ export function fetchMatchingItemSlot(entity, itemToMatchId) {
if (itemSlot.hasItem() && itemSlot?.typeId === itemToMatchId)
return itemSlot;
}
}
export function placeBlock(player, placedBlock, blockToPlace, itemSlotToConsume = void 0) {
system.run(() => {
if (itemSlotToConsume)
consumeItem(itemSlotToConsume);
placedBlock.setPermutation(blockToPlace);
playBlockPlacementSound(player, placedBlock, blockToPlace);
});
}
function consumeItem(itemSlot) {
if (specialItemPlacementConversions[itemSlot.typeId.replace('minecraft:', '')]) {
itemSlot.setItem(new ItemStack(specialItemPlacementConversions[itemSlot.typeId.replace('minecraft:', '')]));
} else {
if (itemSlot.amount === 1)
itemSlot.setItem(void 0);
else
itemSlot.amount--;
}
}
function playBlockPlacementSound(player, block, structureBlock) {
const blockId = structureBlock.type.id.replace('minecraft:', '');
const blockData = blocks[blockId];
let blockSound = blockData['sound'] || 'stone';
if (['glass', 'terracotta'].includes(blockSound))
blockSound = 'stone';
let blockSoundId = 'dig.' + blockSound;
if (['iron', 'calcite'].includes(blockSound))
blockSoundId = 'place.' + blockSound;
player.dimension.playSound(blockSoundId, block.location);
}