From 98bbc6e9ef2376636392a911cbc86a41ffa3a576 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Fri, 14 Nov 2025 01:47:55 -0800 Subject: [PATCH] fast easy place now detects click --- packs/BP/items/easy_place.json | 8 +++-- packs/BP/scripts/options/fastEasyPlace.js | 38 ++++++++++++++++------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/packs/BP/items/easy_place.json b/packs/BP/items/easy_place.json index e4ed343..af4ba61 100644 --- a/packs/BP/items/easy_place.json +++ b/packs/BP/items/easy_place.json @@ -1,21 +1,25 @@ { - "format_version": "1.20.30", + "format_version": "1.20.50", "minecraft:item": { "description": { "identifier": "construct:easy_place", "category": "Items" }, "components": { - "minecraft:max_stack_size": 1, "minecraft:icon": { "texture": "construct:easy_place" }, "minecraft:display_name": { "value": "Easy Place" }, + "minecraft:max_stack_size": 1, "minecraft:wearable": { "dispensable": true, "slot": "slot.weapon.offhand" + }, + "minecraft:use_modifiers": { + "use_duration": 3600, + "movement_modifier": 1 } } } diff --git a/packs/BP/scripts/options/fastEasyPlace.js b/packs/BP/scripts/options/fastEasyPlace.js index 6917a83..b22e0f0 100644 --- a/packs/BP/scripts/options/fastEasyPlace.js +++ b/packs/BP/scripts/options/fastEasyPlace.js @@ -9,6 +9,8 @@ import { Vector } from '../lib/Vector'; const locationsPlacedLastTick = new Set(); const PLAYER_COLLISION_BOX = { width: 0.6, height: 1.8 }; +const ACTION_ITEM = 'construct:easy_place'; +const runnerByPlayer = {}; const builderOption = new BuilderOption({ identifier: 'fastEasyPlace', @@ -22,9 +24,9 @@ const builderOption = new BuilderOption({ function giveActionItem(playerId) { const player = world.getEntity(playerId); const container = player.getComponent(EntityComponentTypes.Inventory)?.container; - const itemStack = new ItemStack('construct:easy_place'); + const itemStack = new ItemStack(ACTION_ITEM); const offhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Offhand); - if (!container.contains(itemStack) && offhandItemStack?.typeId !== 'construct:easy_place') { + if (!container.contains(itemStack) && offhandItemStack?.typeId !== ACTION_ITEM) { const remainingItemStack = container.addItem(itemStack); if (remainingItemStack) player.dimension.spawnItem(remainingItemStack, player.location); @@ -39,24 +41,38 @@ function removeActionItem(playerId) { const container = player.getComponent(EntityComponentTypes.Inventory)?.container; for (let i = 0; i < container.size; i++) { const itemStack = container.getItem(i); - if (itemStack?.typeId === 'construct:easy_place') + if (itemStack?.typeId === ACTION_ITEM) container.setItem(i, void 0); } const equipment = player.getComponent(EntityComponentTypes.Equippable); const offhandItemStack = equipment?.getEquipment(EquipmentSlot.Offhand); - if (offhandItemStack?.typeId === 'construct:easy_place') { + if (offhandItemStack?.typeId === ACTION_ITEM) { equipment.setEquipment(EquipmentSlot.Offhand, void 0); } } -system.runInterval(onTick); +system.runInterval(onPlacingTick); world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock); +world.afterEvents.itemStartUse.subscribe(onItemStartUse); +world.afterEvents.itemStopUse.subscribe(onItemStopUse); -function onTick() { - for (const player of world.getAllPlayers()) { - if (player && builderOption.isEnabled(player.id)) - processEasyPlace(player); - } +function onItemStartUse(event) { + if (event.itemStack?.typeId !== ACTION_ITEM) + return; + runnerByPlayer[event.source.id] = system.runInterval((() => onPlacingTick(event.source))); +} + +function onItemStopUse(event) { + if (event.itemStack?.typeId !== ACTION_ITEM) + return; + const playerRunnerId = runnerByPlayer[event.source.id]; + if (playerRunnerId) + system.clearRun(playerRunnerId); +} + +function onPlacingTick(player) { + if (player && builderOption.isEnabled(player.id)) + processEasyPlace(player); } function onPlayerInteractWithBlock(event) { @@ -91,7 +107,7 @@ function isHoldingActionItem(player) { const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand); if (!mainhandItemStack) return false; - return mainhandItemStack.typeId === 'construct:easy_place'; + return mainhandItemStack.typeId === ACTION_ITEM; } function tryPlaceBlock(player, worldBlock, structureBlock) {