fast easy place now detects click

This commit is contained in:
ForestOfLight
2025-11-14 01:47:55 -08:00
Unverified
parent 4cbe1bc474
commit eca1846efa
2 changed files with 33 additions and 13 deletions
+6 -2
View File
@@ -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
}
}
}
+25 -9
View File
@@ -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,25 +41,39 @@ 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()) {
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) {
const { player, block, isFirstEvent } = 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) {