#problem with blocksBetween
1 messages · Page 1 of 1 (latest)
i saw it
if u want basic implementation
find every min and max axis of each dimension and use for loops to foreach it
like this ```js
function betweenXYZ(XYZa, XYZb, XYZc) {
return XYZc.every(
(c, i) => c >= Math.min(XYZa[i], XYZb[i]) && c <= Math.max(XYZa[i], XYZb[i])
)
}
do you have any changes about XYZc i want to remove it
i have no idea what it does
i used it for like this ```js
if(betweenXYZ([10, -61, 11], [-125, -61, -98], [block.location.x, block.location.y, block.location.z]))
nope i tried it with foreach did also not working
it's nice if you do it
function *square({x:x1,y = 0,z:z1}, {x:x2 = 0,z:z2 = 0} = {}){
const xMin = (x1 - x2)/2, xMax = xMin + x2, zMin = (z1 - z2)/2, zMax = zMin + z2;
for (let x = 0; x < x1; x++)
if(x < xMin || x > xMax) for (let z = 0; z < z1; z++)
if(z < zMin || z > zMax) yield {x,y,z}
}
function *cube({x,y:yS,z},{x:x2 = 0,y:y2 = 0,z:z2 = 0} = {}){
const yMin = (yS - y2)/2, yMax = yMin + y2;
for (let y = 0; y < yS; y++)
if(y < yMin || y > yMax) yield* this.square({x,y,z},{x:x2,z:z2});
}
usage
for(const loc of cube(location1, location2)){
//code here use for each location
}
fillBlocks(randomPerms) {
const blockDATA = [],
{ dim, blockGroups, current, positions: [loc1, loc2] } = this,
locations = cube(loc1, loc2),
{ floor, random } = Math,
{ length: randSize } = randomPerms,
{ length: size } = blockGroups;
if (!size) {
const firstPerms = Array.from(locations, loc => (
{
loc, perm: dim.getBlock(loc).permutation.clone()
}
))
blockGroups.push(firstPerms)
}
for (const loc of cube(loc1, loc2)) {
const perm = randomPerms[floor(random() * randSize)]
dim.getBlock(loc).setPermutation(perm)
blockDATA.push({ loc, perm })
}
if (current > size) blockGroups.splice(current, size)
blockGroups.push(blockDATA)
this.blockGroups = blockGroups
this.current = blockGroups.length - 1
}
```can you change it idk where
any errors?
nope
try console.warn("test") inside the loop
its doesn't show any error
s
ore the console warn
i think its bc of this ```js
{ dim, blockGroups, current, positions: [loc1, loc2] } = this,
locations = cube(loc1, loc2),
/\
u should for each locations between once
fillBlocks(randomPerms) {
const blockDATA = [],
{ dim, blockGroups, current, positions: [loc1, loc2] } = this,
locations = loc1.blocksBetween(loc2),
{ floor, random } = Math,
{ length: randSize } = randomPerms,
{ length: size } = blockGroups;
if (!size) {
const firstPerms = Array.from(locations, loc => (
{
loc, perm: dim.getBlock(loc).permutation.clone()
}
))
blockGroups.push(firstPerms)
}
for (const loc of locations) {
const perm = randomPerms[floor(random() * randSize)]
dim.getBlock(loc).setPermutation(perm)
blockDATA.push({ loc, perm })
}
if (current > size) blockGroups.splice(current, size)
blockGroups.push(blockDATA)
this.blockGroups = blockGroups
this.current = blockGroups.length - 1
}
```ID get it
im to dump
import { Vector } from "@minecraft/server";
Object.defineProperty(Vector, 'blocksBetween', {
value(loc1,loc2) {
const locations = []
const { x: min_x, y: min_y, z: min_z } = this.min(loc1, loc2)
const { x: max_x, y: max_y, z: max_z } = this.max(loc1, loc2)
for (let x = min_x; x < max_x + 1; x++) {
for (let y = min_y; y < max_y + 1; y++) {
for (let z = min_z; z < max_z + 1; z++) {
locations.push({ x, y, z })
}
}
}
return locations
}
})
import './file1'
import './file2'
import './file3'
```usage```js
const locsA = Vector.blocksBetween({ x, y, z }, { x: 0, y: 0, z: 0 })
const locsB = Vector.blocksBetween({ x: 0, y: 0, z: 0 }, new Vector(0, 0, 0))
const locsC = Vector.blocksBetween(new Vector(0, 0, 0), { x, y, z })
```just leaving this here
ah now i understand thx and btw it works now
sounds great