fast easy place now detects click
This commit is contained in:
@@ -1,21 +1,25 @@
|
|||||||
{
|
{
|
||||||
"format_version": "1.20.30",
|
"format_version": "1.20.50",
|
||||||
"minecraft:item": {
|
"minecraft:item": {
|
||||||
"description": {
|
"description": {
|
||||||
"identifier": "construct:easy_place",
|
"identifier": "construct:easy_place",
|
||||||
"category": "Items"
|
"category": "Items"
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
"minecraft:max_stack_size": 1,
|
|
||||||
"minecraft:icon": {
|
"minecraft:icon": {
|
||||||
"texture": "construct:easy_place"
|
"texture": "construct:easy_place"
|
||||||
},
|
},
|
||||||
"minecraft:display_name": {
|
"minecraft:display_name": {
|
||||||
"value": "Easy Place"
|
"value": "Easy Place"
|
||||||
},
|
},
|
||||||
|
"minecraft:max_stack_size": 1,
|
||||||
"minecraft:wearable": {
|
"minecraft:wearable": {
|
||||||
"dispensable": true,
|
"dispensable": true,
|
||||||
"slot": "slot.weapon.offhand"
|
"slot": "slot.weapon.offhand"
|
||||||
|
},
|
||||||
|
"minecraft:use_modifiers": {
|
||||||
|
"use_duration": 3600,
|
||||||
|
"movement_modifier": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import { Vector } from '../lib/Vector';
|
|||||||
|
|
||||||
const locationsPlacedLastTick = new Set();
|
const locationsPlacedLastTick = new Set();
|
||||||
const PLAYER_COLLISION_BOX = { width: 0.6, height: 1.8 };
|
const PLAYER_COLLISION_BOX = { width: 0.6, height: 1.8 };
|
||||||
|
const ACTION_ITEM = 'construct:easy_place';
|
||||||
|
const runnerByPlayer = {};
|
||||||
|
|
||||||
const builderOption = new BuilderOption({
|
const builderOption = new BuilderOption({
|
||||||
identifier: 'fastEasyPlace',
|
identifier: 'fastEasyPlace',
|
||||||
@@ -22,9 +24,9 @@ const builderOption = new BuilderOption({
|
|||||||
function giveActionItem(playerId) {
|
function giveActionItem(playerId) {
|
||||||
const player = world.getEntity(playerId);
|
const player = world.getEntity(playerId);
|
||||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
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);
|
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);
|
const remainingItemStack = container.addItem(itemStack);
|
||||||
if (remainingItemStack)
|
if (remainingItemStack)
|
||||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||||
@@ -39,24 +41,38 @@ function removeActionItem(playerId) {
|
|||||||
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
const container = player.getComponent(EntityComponentTypes.Inventory)?.container;
|
||||||
for (let i = 0; i < container.size; i++) {
|
for (let i = 0; i < container.size; i++) {
|
||||||
const itemStack = container.getItem(i);
|
const itemStack = container.getItem(i);
|
||||||
if (itemStack?.typeId === 'construct:easy_place')
|
if (itemStack?.typeId === ACTION_ITEM)
|
||||||
container.setItem(i, void 0);
|
container.setItem(i, void 0);
|
||||||
}
|
}
|
||||||
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
const equipment = player.getComponent(EntityComponentTypes.Equippable);
|
||||||
const offhandItemStack = equipment?.getEquipment(EquipmentSlot.Offhand);
|
const offhandItemStack = equipment?.getEquipment(EquipmentSlot.Offhand);
|
||||||
if (offhandItemStack?.typeId === 'construct:easy_place') {
|
if (offhandItemStack?.typeId === ACTION_ITEM) {
|
||||||
equipment.setEquipment(EquipmentSlot.Offhand, void 0);
|
equipment.setEquipment(EquipmentSlot.Offhand, void 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
system.runInterval(onTick);
|
system.runInterval(onPlacingTick);
|
||||||
world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock);
|
world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock);
|
||||||
|
world.afterEvents.itemStartUse.subscribe(onItemStartUse);
|
||||||
|
world.afterEvents.itemStopUse.subscribe(onItemStopUse);
|
||||||
|
|
||||||
function onTick() {
|
function onItemStartUse(event) {
|
||||||
for (const player of world.getAllPlayers()) {
|
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))
|
if (player && builderOption.isEnabled(player.id))
|
||||||
processEasyPlace(player);
|
processEasyPlace(player);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPlayerInteractWithBlock(event) {
|
function onPlayerInteractWithBlock(event) {
|
||||||
@@ -91,7 +107,7 @@ function isHoldingActionItem(player) {
|
|||||||
const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand);
|
const mainhandItemStack = player.getComponent(EntityComponentTypes.Equippable).getEquipment(EquipmentSlot.Mainhand);
|
||||||
if (!mainhandItemStack)
|
if (!mainhandItemStack)
|
||||||
return false;
|
return false;
|
||||||
return mainhandItemStack.typeId === 'construct:easy_place';
|
return mainhandItemStack.typeId === ACTION_ITEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||||
|
|||||||
Reference in New Issue
Block a user