From a17b62c5f7ee6ec50da12a53489bd6286bc8ecd1 Mon Sep 17 00:00:00 2001 From: stirante Date: Thu, 23 May 2024 11:27:46 +0200 Subject: [PATCH] Fix toBlockLocation when provided negative block location --- package.json | 2 +- src/Vec3.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e91006c..93e04d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bedrock-oss/bedrock-boost", - "version": "0.0.17", + "version": "0.0.18", "description": "A utility package with helper functions for developing add-ons with Script API in Minecraft Bedrock Edition", "keywords": [ "minecraft", diff --git a/src/Vec3.ts b/src/Vec3.ts index 88a9f17..6f3ba4f 100644 --- a/src/Vec3.ts +++ b/src/Vec3.ts @@ -646,10 +646,11 @@ export default class Vec3 implements Vector3 { * Returns a new vector with the X, Y, and Z components rounded to the nearest block location. */ toBlockLocation(): Vec3 { + // At this point I'm not sure if it wouldn't be better to use Math.floor instead return Vec3.from( - (this.x << 0) - (this.x < 0 ? 1 : 0), - (this.y << 0) - (this.y < 0 ? 1 : 0), - (this.z << 0) - (this.z < 0 ? 1 : 0) + (this.x << 0) - (this.x < 0 && this.x !== (this.x << 0) ? 1 : 0), + (this.y << 0) - (this.y < 0 && this.y !== (this.y << 0) ? 1 : 0), + (this.z << 0) - (this.z < 0 && this.z !== (this.z << 0) ? 1 : 0) ); } /**