add player collision check to fastEasyPlace
This commit is contained in:
@@ -31,6 +31,11 @@ Vector.rejection = function rejection(a, b) { return Vector.subtract(a, Vector.p
|
|||||||
Vector.reflect = function reflect(v, n) { return Vector.subtract(v, Vector.multiply(n, 2 * Vector.dot(v, n))); }
|
Vector.reflect = function reflect(v, n) { return Vector.subtract(v, Vector.multiply(n, 2 * Vector.dot(v, n))); }
|
||||||
Vector.lerp = function lerp(a, b, t) { return Vector.multiply(a, 1 - t).add(Vector.multiply(b, t)); }
|
Vector.lerp = function lerp(a, b, t) { return Vector.multiply(a, 1 - t).add(Vector.multiply(b, t)); }
|
||||||
Vector.distance = function distance(a, b) { return Vector.magnitude(Vector.subtract(a, b)); }
|
Vector.distance = function distance(a, b) { return Vector.magnitude(Vector.subtract(a, b)); }
|
||||||
|
Vector.intersect = function intersect(maxA, minA, maxB, minB) {
|
||||||
|
return (maxA.x >= minB.x && minA.x <= maxB.x) &&
|
||||||
|
(maxA.y >= minB.y && minA.y <= maxB.y) &&
|
||||||
|
(maxA.z >= minB.z && minA.z <= maxB.z);
|
||||||
|
}
|
||||||
Vector.from = function from(object) {
|
Vector.from = function from(object) {
|
||||||
if (Vector.isVec3(object)) return object;
|
if (Vector.isVec3(object)) return object;
|
||||||
if (Array.isArray(object)) return new Vector(object[0], object[1], object[2]);
|
if (Array.isArray(object)) return new Vector(object[0], object[1], object[2]);
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import { bannedBlocks, bannedToValidBlockMap, whitelistedBlockStates, resetToBlo
|
|||||||
import { placeBlock, fetchMatchingItemSlot } from '../utils';
|
import { placeBlock, fetchMatchingItemSlot } from '../utils';
|
||||||
import { Raycaster } from '../classes/Raycaster';
|
import { Raycaster } from '../classes/Raycaster';
|
||||||
import { Builders } from '../classes/Builder/Builders';
|
import { Builders } from '../classes/Builder/Builders';
|
||||||
|
import { Vector } from '../lib/Vector';
|
||||||
|
|
||||||
const PROCESS_INTERVAL = 2; // Fast Easy Place will attempt to place twice when at an interval of 1.
|
const PROCESS_INTERVAL = 2; // Fast Easy Place will attempt to place twice when at an interval of 1.
|
||||||
|
const PLAYER_COLLISION_BOX = { width: 0.6, height: 1.8 };
|
||||||
|
|
||||||
const builderOption = new BuilderOption({
|
const builderOption = new BuilderOption({
|
||||||
identifier: 'fastEasyPlace',
|
identifier: 'fastEasyPlace',
|
||||||
@@ -86,7 +88,7 @@ function isHoldingActionItem(player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
function tryPlaceBlock(player, worldBlock, structureBlock) {
|
||||||
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(worldBlock)) return;
|
if (isBannedBlock(player, structureBlock) || !locationIsPlaceable(player, worldBlock)) return;
|
||||||
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
structureBlock = tryConvertBannedToValidBlock(structureBlock);
|
||||||
if (player.getGameMode() === GameMode.Creative) {
|
if (player.getGameMode() === GameMode.Creative) {
|
||||||
placeBlock(player, worldBlock, structureBlock);
|
placeBlock(player, worldBlock, structureBlock);
|
||||||
@@ -96,8 +98,8 @@ function tryPlaceBlock(player, worldBlock, structureBlock) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function locationIsPlaceable(worldBlock) {
|
function locationIsPlaceable(player, worldBlock) {
|
||||||
return worldBlock.isAir || worldBlock.isLiquid;
|
return (worldBlock.isAir || worldBlock.isLiquid) && !isBlockInsidePlayer(player, worldBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isBannedBlock(player, structureBlock) {
|
function isBannedBlock(player, structureBlock) {
|
||||||
@@ -147,4 +149,14 @@ function getPlaceableItemStack(structureBlock) {
|
|||||||
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
const blockId = structureBlock.type.id.replace('minecraft:', '');
|
||||||
const newItemId = blockIdToItemStackMap[blockId];
|
const newItemId = blockIdToItemStackMap[blockId];
|
||||||
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
|
return newItemId ? new ItemStack(newItemId) : structureBlock.getItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
function isBlockInsidePlayer(player, worldBlock) {
|
||||||
|
const playerLocation = Vector.from(player.location);
|
||||||
|
const blockLocation = Vector.from(worldBlock.location);
|
||||||
|
const playerMin = playerLocation.subtract({ x: PLAYER_COLLISION_BOX.width / 2, y: -0.1, z: PLAYER_COLLISION_BOX.width / 2 });
|
||||||
|
const playerMax = playerLocation.add({ x: PLAYER_COLLISION_BOX.width / 2, y: PLAYER_COLLISION_BOX.height, z: PLAYER_COLLISION_BOX.width / 2 });
|
||||||
|
const blockMin = blockLocation;
|
||||||
|
const blockMax = blockLocation.add({ x: 1, y: 1, z: 1 });
|
||||||
|
return Vector.intersect(playerMax, playerMin, blockMax, blockMin);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user