#Wrong Calculations

1 messages · Page 1 of 1 (latest)

uncut cobalt
#

So basically I found out minecraft is doing this to me:

[Scripting][warning]-K: unkS:-15 127 -23|minecraft:overworld
Dim: minecraft:overworld
Loc: -15 127 -23
Entity Loc: -16.067209243774414 127.99999237060547 -21.498493194580078
Entity Dimension: minecraft:overworld
Distance: 14.431276321411133

So that's the info right... tell me, does that sound like 14 blocks of distance?
So I decided to test out my script on normal js console...

class blocksMap {
  static locToCoord(location) {
    return Object.values(location).join(' ');
  }
  static coordToLoc(coord) {
    let [x, y, z] = coord.split(' ').map(c => Number(c));
    return {x, y, z};
  }
}
function calcDistance(pA, pB) {
  let d = {
    x: Math.abs(pA.x - pB.x),
    y: Math.abs(pA.y - pB.y),
    z: Math.abs(pA.z - pB.z)
  };
  return d.x + d.y + d.z;
}

console.warn(calcDistance(blocksMap.coordToLoc('-15 127 -23'), blocksMap.coordToLoc('-16.067209243774414 127.99999237060547 -21.498493194580078')));

Output: 3.5687084197998047
So basically I'm confused, wtf is going on? The only thing I changed is the setup, from normal js to the entitySpawn event... and the calculations are literally so different...

#
let excludedMobTypes = ["minecraft:player", "minecraft:tnt", "minecraft:item", "minecraft:thrown_trident", "minecraft:arrow", "minecraft:fishing_hook", "minecraft:snowball", "minecraft:endermite", "minecraft:ender_pearl"];
world.afterEvents.entitySpawn.subscribe((data) => {
  if (data.cause !== "Spawned") return;
  if (registrationBlocks.size === 0) return;
  if (excludedMobTypes.includes(data.entity.typeId)) return;
  let entity = data.entity;
  system.run(() => {
    if (typeof entity?.location !== 'object') return;
    let blocks = Array.from(registrationBlocks.entries())
      .filter(([k, _]) => {
        let dim = k.split('|')[1], loc = k.split(':')[1].split('|')[0], dist = calcDistance(entity.location, blocksMap.coordToLoc(loc));
        console.warn(`K: ${k}\nDim: ${dim}\nLoc: ${loc}\nEntity Loc: ${blocksMap.locToCoord(entity.location)}\nEntity Dimension: ${entity.dimension.id}\nDistance: ${dist}`);
        return dist < 4.5 && entity.dimension.id === dim
      })
      ?.forEach(([k, v]) => {
        registrationBlocks.delete(k);
        registrationPlayers[k]?.forEach(p => sendMsgWithSound(p, `§g[§6§lServer§r§g] §aThe Spawner At §3${k.split(':')[1].split('|')[0]}§a In The Dimension §3(${k.split('|')[1]}) §aRegistered Successfully!`, 'random.toast'));
      });
    blocksMap.getAll()
      ?.filter(([k, _]) => calcDistance(entity.location, blocksMap.coordToLoc(k.split(':')[1].split('|')[0])) < 4.5 && entity.dimension.id === k.split('|')[1])
      ?.length >= 1 ? entity.remove() : null;
  });
});

The reason the script doesn't seem compact or anything is cuz I lost my sanity trying to fix it.

#

For extra context, registrationBlocks is map, basically all of this is a custom spawners script

high peak
#

const calcDistance = (pA, pB) => ( Math.sqrt(Math.pow(pA.x- pB.x, 2) + Math.pow(pA.y- pB.y, 2) + Math.pow(pA.z- pB.z, 2) ,2));

high peak
#

True

#

Forgot

uncut cobalt
#

It reversed my coordinates, I didn't know that yet so yeah