How to add structures screen

This commit is contained in:
ForestOfLight
2025-04-13 01:50:15 -07:00
Unverified
parent 79b22e5fd7
commit 77994b26dd
5 changed files with 22 additions and 5 deletions
+4 -4
View File
@@ -4,13 +4,13 @@ import { world } from "@minecraft/server";
export class Raycaster {
static STEP_SIZE = 0.2;
static getStructureBlocks(dimension, startLocation, direction, { maxDistance, getFirst = true, collideWithWorldBlocks = true }) {
static getStructureBlocks(dimension, startLocation, direction, { maxDistance = 7, getFirst = true, collideWithWorldBlocks = true, useLayers = true }) {
// Can probably be optimized by the fact that we only need full blocks and aren't checking for partial blocks
const blocks = [];
let location = startLocation;
let distance = 0;
while (distance < maxDistance) {
const locatedStructures = structureCollection.getStructures(dimension.id, location);
const locatedStructures = structureCollection.getStructures(dimension.id, location, { useLayers });
if (locatedStructures.length !== 0) {
const structure = locatedStructures[0];
const block = structure.getBlock(structure.toStructureCoords(location));
@@ -36,11 +36,11 @@ export class Raycaster {
return blocks;
}
static getTargetedStructureBlock(player, { isFirst = true, collideWithWorldBlocks = true }) {
static getTargetedStructureBlock(player, { isFirst = true, collideWithWorldBlocks = true, useLayers = true } = {}) {
const startLocation = player.getHeadLocation();
const direction = player.getViewDirection();
const maxDistance = 7;
const blocks = this.getStructureBlocks(player.dimension, startLocation, direction, { maxDistance, getFirst: isFirst, collideWithWorldBlocks });
const blocks = this.getStructureBlocks(player.dimension, startLocation, direction, { maxDistance, getFirst: isFirst, collideWithWorldBlocks, useLayers });
if (blocks.length === 0)
return void 0;
return isFirst ? blocks[0] : blocks[blocks.length - 1];