revert fast easy place to looking method
This commit is contained in:
@@ -21,6 +21,7 @@ function giveActionItem(playerId) {
|
|||||||
const itemStack = new ItemStack('construct:easy_place');
|
const itemStack = new ItemStack('construct:easy_place');
|
||||||
if (!container.contains(itemStack)) {
|
if (!container.contains(itemStack)) {
|
||||||
const remainingItemStack = container.addItem(itemStack);
|
const remainingItemStack = container.addItem(itemStack);
|
||||||
|
if (remainingItemStack)
|
||||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { Builders } from '../classes/Builder/Builders';
|
|||||||
|
|
||||||
const PROCESS_INTERVAL = 2;
|
const PROCESS_INTERVAL = 2;
|
||||||
|
|
||||||
let runner = void 0;
|
|
||||||
const builderOption = new BuilderOption({
|
const builderOption = new BuilderOption({
|
||||||
identifier: 'fastEasyPlace',
|
identifier: 'fastEasyPlace',
|
||||||
displayName: 'Fast Easy Place',
|
displayName: 'Fast Easy Place',
|
||||||
@@ -23,6 +22,7 @@ function giveActionItem(playerId) {
|
|||||||
const itemStack = new ItemStack('construct:easy_place');
|
const itemStack = new ItemStack('construct:easy_place');
|
||||||
if (!container.contains(itemStack)) {
|
if (!container.contains(itemStack)) {
|
||||||
const remainingItemStack = container.addItem(itemStack);
|
const remainingItemStack = container.addItem(itemStack);
|
||||||
|
if (remainingItemStack)
|
||||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,22 +46,20 @@ function removeActionItem(playerId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
system.runInterval(onTick, PROCESS_INTERVAL);
|
system.runInterval(onTick, PROCESS_INTERVAL);
|
||||||
|
world.beforeEvents.playerInteractWithBlock.subscribe(onPlayerInteractWithBlock);
|
||||||
|
|
||||||
function onTick() {
|
function onTick() {
|
||||||
for (const player of world.getAllPlayers()) {
|
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);
|
processEasyPlace(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
world.beforeEvents.itemUse.subscribe(event => {
|
function onPlayerInteractWithBlock(event) {
|
||||||
const player = event.source;
|
const { player, block, isFirstEvent } = event;
|
||||||
if (player && builderOption.isEnabled(event.source?.id) && player.inputInfo.lastInputModeUsed !== InputMode.Touch) {
|
if (!player || !isFirstEvent || !block || !builderOption.isEnabled(player.id) || !isHoldingActionItem(player)) return;
|
||||||
system.run(() => {
|
preventAction(event, player);
|
||||||
processEasyPlace(event.source);
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function processEasyPlace(player) {
|
function processEasyPlace(player) {
|
||||||
if (!player || !isHoldingActionItem(player)) return;
|
if (!player || !isHoldingActionItem(player)) return;
|
||||||
@@ -72,6 +70,13 @@ function processEasyPlace(player) {
|
|||||||
tryPlaceBlock(player, worldBlock, structureBlock.permutation);
|
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) {
|
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)
|
||||||
@@ -80,17 +85,17 @@ function isHoldingActionItem(player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||||
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(player, worldBlock)) return;
|
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(worldBlock)) return;
|
||||||
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
||||||
if (player.getGameMode() === GameMode.creative) {
|
if (player.getGameMode() === GameMode.creative) {
|
||||||
placeBlock(worldBlock, structureBlock);
|
placeBlock(player, worldBlock, structureBlock);
|
||||||
} else if (player.getGameMode() === GameMode.survival) {
|
} else if (player.getGameMode() === GameMode.survival) {
|
||||||
structureBlock = tryConvertToDefaultState(structureBlock);
|
structureBlock = tryConvertToDefaultState(structureBlock);
|
||||||
tryPlaceBlockSurvival(player, worldBlock, structureBlock);
|
tryPlaceBlockSurvival(player, worldBlock, structureBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function locationIsPlaceable(player, worldBlock) {
|
function locationIsPlaceable(worldBlock) {
|
||||||
return worldBlock.isAir;
|
return worldBlock.isAir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,10 +137,9 @@ function tryConvertToDefaultState(structureBlock) {
|
|||||||
|
|
||||||
function tryPlaceBlockSurvival(player, block, structureBlock) {
|
function tryPlaceBlockSurvival(player, block, structureBlock) {
|
||||||
const placeableItemStack = getPlaceableItemStack(structureBlock);
|
const placeableItemStack = getPlaceableItemStack(structureBlock);
|
||||||
// console.warn(`Looking for item to place ${structureBlock?.type.id} (${placeableItemStack?.typeId})...`);
|
|
||||||
const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId);
|
const itemSlotToUse = fetchMatchingItemSlot(player, placeableItemStack?.typeId);
|
||||||
if (itemSlotToUse) {
|
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(() => {
|
system.run(() => {
|
||||||
if (itemSlot) {
|
if (itemSlot)
|
||||||
consumeItem(itemSlot);
|
consumeItem(itemSlot);
|
||||||
}
|
|
||||||
block.setPermutation(structureBlock);
|
block.setPermutation(structureBlock);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function giveActionItem(playerId) {
|
|||||||
const itemStack = new ItemStack('construct:material_grabber');
|
const itemStack = new ItemStack('construct:material_grabber');
|
||||||
if (!container.contains(itemStack)) {
|
if (!container.contains(itemStack)) {
|
||||||
const remainingItemStack = container.addItem(itemStack);
|
const remainingItemStack = container.addItem(itemStack);
|
||||||
|
if (remainingItemStack)
|
||||||
player.dimension.spawnItem(remainingItemStack, player.location);
|
player.dimension.spawnItem(remainingItemStack, player.location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user