add showStructBlockInfo, fastEasyPlace, and add arrow slot for easyPlace

This commit is contained in:
ForestOfLight
2025-03-16 22:46:20 -07:00
Unverified
parent c9927f8e24
commit fb3deea181
8 changed files with 246 additions and 35 deletions
+13 -3
View File
@@ -5,9 +5,11 @@ import { structureCollection } from '../classes/StructureCollection';
import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlockStates, bannedDimensionBlocks, specialItemPlacementConversions,
blockIdToItemStackMap } from '../data';
const ARROW_SLOT = 35;
const easyPlace = new Rule({
identifier: 'easyPlace',
description: { text: 'Places a structure with ease.' },
description: { text: 'Simplifies placing blocks in a structure (arrow in bottom right inventory slot).' },
onEnableCallback: () => { world.beforeEvents.playerPlaceBlock.subscribe(onPlayerPlaceBlock); },
onDisableCallback: () => { world.beforeEvents.playerPlaceBlock.unsubscribe(onPlayerPlaceBlock); }
})
@@ -15,13 +17,21 @@ extension.addRule(easyPlace);
function onPlayerPlaceBlock(event) {
const { player, block } = event;
if (!player || !block) return;
if (!player || !block || !hasArrowInCorrectSlot(player)) return;
const structureBlock = fetchStructureBlock(block.location);
if (!structureBlock)
return;
tryPlaceBlock(event, player, block, structureBlock);
}
function hasArrowInCorrectSlot(player) {
const inventory = player.getComponent(EntityComponentTypes.Inventory)?.container;
if (!inventory)
return false;
const arrowSlot = inventory.getSlot(ARROW_SLOT);
return arrowSlot.hasItem() && arrowSlot.typeId === 'minecraft:arrow';
}
function fetchStructureBlock(location) {
const locatedStructures = structureCollection.getStructuresAtLocation(location);
if (locatedStructures.length === 0)
@@ -77,7 +87,7 @@ function tryConvertToDefaultState(structureBlock) {
function tryPlaceBlockSurvival(event, player, block, structureBlock) {
const placeableItemStack = getPlaceableItemStack(structureBlock);
console.warn(`Looking for item to place ${structureBlock?.type.id} (${placeableItemStack?.typeId})...`);
// console.warn(`Looking for item to place ${structureBlock?.type.id} (${placeableItemStack?.typeId})...`);
const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId);
if (itemSlotToUse) {
event.cancel = true;