From 20727027a9f38edbb079d81ddd161af51e37ef15 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Sat, 7 Jun 2025 21:47:18 -0700 Subject: [PATCH 1/4] move to Equipment tab --- Construct[BP]/items/easy_place.json | 2 +- Construct[BP]/items/material_grabber.json | 2 +- Construct[BP]/items/menu.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Construct[BP]/items/easy_place.json b/Construct[BP]/items/easy_place.json index e4ed343..b830465 100644 --- a/Construct[BP]/items/easy_place.json +++ b/Construct[BP]/items/easy_place.json @@ -3,7 +3,7 @@ "minecraft:item": { "description": { "identifier": "construct:easy_place", - "category": "Items" + "category": "Equipment" }, "components": { "minecraft:max_stack_size": 1, diff --git a/Construct[BP]/items/material_grabber.json b/Construct[BP]/items/material_grabber.json index f3d45fd..e7ffe24 100644 --- a/Construct[BP]/items/material_grabber.json +++ b/Construct[BP]/items/material_grabber.json @@ -3,7 +3,7 @@ "minecraft:item": { "description": { "identifier": "construct:material_grabber", - "category": "Items" + "category": "Equipment" }, "components": { "minecraft:max_stack_size": 1, diff --git a/Construct[BP]/items/menu.json b/Construct[BP]/items/menu.json index 7994039..8e8400a 100644 --- a/Construct[BP]/items/menu.json +++ b/Construct[BP]/items/menu.json @@ -3,7 +3,7 @@ "minecraft:item": { "description": { "identifier": "construct:menu", - "category": "Items" + "category": "Equipment" }, "components": { "minecraft:max_stack_size": 1, From aa7b0a7273a39045f1cd2c8439ed3fdbe62d3251 Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Sat, 7 Jun 2025 21:52:00 -0700 Subject: [PATCH 2/4] that thing you did? yeah, it didn't work. it was fine how it was. --- Construct[BP]/items/easy_place.json | 2 +- Construct[BP]/items/material_grabber.json | 2 +- Construct[BP]/items/menu.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Construct[BP]/items/easy_place.json b/Construct[BP]/items/easy_place.json index b830465..e4ed343 100644 --- a/Construct[BP]/items/easy_place.json +++ b/Construct[BP]/items/easy_place.json @@ -3,7 +3,7 @@ "minecraft:item": { "description": { "identifier": "construct:easy_place", - "category": "Equipment" + "category": "Items" }, "components": { "minecraft:max_stack_size": 1, diff --git a/Construct[BP]/items/material_grabber.json b/Construct[BP]/items/material_grabber.json index e7ffe24..f3d45fd 100644 --- a/Construct[BP]/items/material_grabber.json +++ b/Construct[BP]/items/material_grabber.json @@ -3,7 +3,7 @@ "minecraft:item": { "description": { "identifier": "construct:material_grabber", - "category": "Equipment" + "category": "Items" }, "components": { "minecraft:max_stack_size": 1, diff --git a/Construct[BP]/items/menu.json b/Construct[BP]/items/menu.json index 8e8400a..7994039 100644 --- a/Construct[BP]/items/menu.json +++ b/Construct[BP]/items/menu.json @@ -3,7 +3,7 @@ "minecraft:item": { "description": { "identifier": "construct:menu", - "category": "Equipment" + "category": "Items" }, "components": { "minecraft:max_stack_size": 1, From aa3b21477bc92318748485665c59b739c768fcaf Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Sat, 7 Jun 2025 22:59:11 -0700 Subject: [PATCH 3/4] drop custom items if giving and inventory is full --- Construct[BP]/scripts/options/easyPlace.js | 6 ++++-- Construct[BP]/scripts/options/fastEasyPlace.js | 6 ++++-- Construct[BP]/scripts/options/materialGrabber.js | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Construct[BP]/scripts/options/easyPlace.js b/Construct[BP]/scripts/options/easyPlace.js index 63facdd..ff7a298 100644 --- a/Construct[BP]/scripts/options/easyPlace.js +++ b/Construct[BP]/scripts/options/easyPlace.js @@ -19,8 +19,10 @@ function giveActionItem(playerId) { const player = world.getEntity(playerId); const container = player.getComponent(EntityComponentTypes.Inventory)?.container; const itemStack = new ItemStack('construct:easy_place'); - if (!container.contains(itemStack)) - container.addItem(itemStack); + if (!container.contains(itemStack)) { + const remainingItemStack = container.addItem(itemStack); + player.dimension.spawnItem(remainingItemStack, player.location); + } } function removeActionItem(playerId) { diff --git a/Construct[BP]/scripts/options/fastEasyPlace.js b/Construct[BP]/scripts/options/fastEasyPlace.js index b025e31..1185ee6 100644 --- a/Construct[BP]/scripts/options/fastEasyPlace.js +++ b/Construct[BP]/scripts/options/fastEasyPlace.js @@ -21,8 +21,10 @@ function giveActionItem(playerId) { const player = world.getEntity(playerId); const container = player.getComponent(EntityComponentTypes.Inventory)?.container; const itemStack = new ItemStack('construct:easy_place'); - if (!container.contains(itemStack)) - container.addItem(itemStack); + if (!container.contains(itemStack)) { + const remainingItemStack = container.addItem(itemStack); + player.dimension.spawnItem(remainingItemStack, player.location); + } } function removeActionItem(playerId) { diff --git a/Construct[BP]/scripts/options/materialGrabber.js b/Construct[BP]/scripts/options/materialGrabber.js index 6080cea..051d739 100644 --- a/Construct[BP]/scripts/options/materialGrabber.js +++ b/Construct[BP]/scripts/options/materialGrabber.js @@ -17,8 +17,10 @@ function giveActionItem(playerId) { const player = world.getEntity(playerId); const container = player.getComponent(EntityComponentTypes.Inventory)?.container; const itemStack = new ItemStack('construct:material_grabber'); - if (!container.contains(itemStack)) - container.addItem(itemStack); + if (!container.contains(itemStack)) { + const remainingItemStack = container.addItem(itemStack); + player.dimension.spawnItem(remainingItemStack, player.location); + } } function removeActionItem(playerId) { From 0f10ec65e4d82bf4e5d462f3b50342f3a92d82fc Mon Sep 17 00:00:00 2001 From: ForestOfLight Date: Sat, 7 Jun 2025 23:44:27 -0700 Subject: [PATCH 4/4] revert fast easy place to looking method --- Construct[BP]/scripts/options/easyPlace.js | 3 +- .../scripts/options/fastEasyPlace.js | 41 ++++++++++--------- .../scripts/options/materialGrabber.js | 3 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Construct[BP]/scripts/options/easyPlace.js b/Construct[BP]/scripts/options/easyPlace.js index ff7a298..1636781 100644 --- a/Construct[BP]/scripts/options/easyPlace.js +++ b/Construct[BP]/scripts/options/easyPlace.js @@ -21,7 +21,8 @@ function giveActionItem(playerId) { const itemStack = new ItemStack('construct:easy_place'); if (!container.contains(itemStack)) { const remainingItemStack = container.addItem(itemStack); - player.dimension.spawnItem(remainingItemStack, player.location); + if (remainingItemStack) + player.dimension.spawnItem(remainingItemStack, player.location); } } diff --git a/Construct[BP]/scripts/options/fastEasyPlace.js b/Construct[BP]/scripts/options/fastEasyPlace.js index 1185ee6..47d1ead 100644 --- a/Construct[BP]/scripts/options/fastEasyPlace.js +++ b/Construct[BP]/scripts/options/fastEasyPlace.js @@ -7,7 +7,6 @@ import { Builders } from '../classes/Builder/Builders'; const PROCESS_INTERVAL = 2; -let runner = void 0; const builderOption = new BuilderOption({ identifier: 'fastEasyPlace', displayName: 'Fast Easy Place', @@ -23,7 +22,8 @@ function giveActionItem(playerId) { const itemStack = new ItemStack('construct:easy_place'); if (!container.contains(itemStack)) { const remainingItemStack = container.addItem(itemStack); - player.dimension.spawnItem(remainingItemStack, player.location); + if (remainingItemStack) + player.dimension.spawnItem(remainingItemStack, player.location); } } @@ -46,22 +46,20 @@ function removeActionItem(playerId) { } system.runInterval(onTick, PROCESS_INTERVAL); +world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock); function onTick() { for (const player of world.getAllPlayers()) { - if (player && builderOption.isEnabled(player.id) && player.inputInfo.lastInputModeUsed === InputMode.Touch) + if (player && builderOption.isEnabled(player.id)) processEasyPlace(player); } } -world.beforeEvents.itemUse.subscribe(event => { - const player = event.source; - if (player && builderOption.isEnabled(event.source?.id) && player.inputInfo.lastInputModeUsed !== InputMode.Touch) { - system.run(() => { - processEasyPlace(event.source); - }); - } -}); +function onPlayerInteractWithBlock(event) { + const { player, block, isFirstEvent } = event; + if (!player || !isFirstEvent || !block || !builderOption.isEnabled(player.id) || !isHoldingActionItem(player)) return; + preventAction(event, player); +} function processEasyPlace(player) { if (!player || !isHoldingActionItem(player)) return; @@ -72,6 +70,13 @@ function processEasyPlace(player) { tryPlaceBlock(player, worldBlock, structureBlock.permutation); } +function preventAction(event, player) { + event.cancel = true; + system.run(() => { + player.onScreenDisplay.setActionBar('§cAction prevented by Easy Place.'); + }); +} + function isHoldingActionItem(player) { const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand); if (!mainhandItemStack) @@ -80,17 +85,17 @@ function isHoldingActionItem(player) { } function tryPlaceBlock(player, worldBlock, structureBlock) { - if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(player, worldBlock)) return; + if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(worldBlock)) return; structureBlock = tryConvertBannedToValidBlock(structureBlock); if (player.getGameMode() === GameMode.creative) { - placeBlock(worldBlock, structureBlock); + placeBlock(player, worldBlock, structureBlock); } else if (player.getGameMode() === GameMode.survival) { structureBlock = tryConvertToDefaultState(structureBlock); tryPlaceBlockSurvival(player, worldBlock, structureBlock); } } -function locationIsPlaceable(player, worldBlock) { +function locationIsPlaceable(worldBlock) { return worldBlock.isAir; } @@ -132,10 +137,9 @@ function tryConvertToDefaultState(structureBlock) { function tryPlaceBlockSurvival(player, block, structureBlock) { const placeableItemStack = getPlaceableItemStack(structureBlock); - // console.warn(`Looking for item to place ${structureBlock?.type.id} (${placeableItemStack?.typeId})...`); const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId); if (itemSlotToUse) { - placeBlock(block, structureBlock, itemSlotToUse); + placeBlock(player, block, structureBlock, itemSlotToUse); } } @@ -158,11 +162,10 @@ function fetchMatchingItemSlot(player, itemToMatchId) { } } -function placeBlock(block, structureBlock, itemSlot) { +function placeBlock(player, block, structureBlock, itemSlot) { system.run(() => { - if (itemSlot) { + if (itemSlot) consumeItem(itemSlot); - } block.setPermutation(structureBlock); }); } diff --git a/Construct[BP]/scripts/options/materialGrabber.js b/Construct[BP]/scripts/options/materialGrabber.js index 051d739..e0652c2 100644 --- a/Construct[BP]/scripts/options/materialGrabber.js +++ b/Construct[BP]/scripts/options/materialGrabber.js @@ -19,7 +19,8 @@ function giveActionItem(playerId) { const itemStack = new ItemStack('construct:material_grabber'); if (!container.contains(itemStack)) { const remainingItemStack = container.addItem(itemStack); - player.dimension.spawnItem(remainingItemStack, player.location); + if (remainingItemStack) + player.dimension.spawnItem(remainingItemStack, player.location); } }