Mojira Archive
MCPE-155131

Location and BlockLocation are incongruous when they have negative coords

Let me explain, when you have a Location variable  and wants to transform it in a BlockLocation variable have some issues, look:

const location = new Location(20, 0, 20);

let locationToBlock = new BlockLocation(location.x, location.y, location.z) // Then this returns a block location with (20, 0, 20).

//Now if the coordinates are negative like

const location = new Location(-20, 0, -20);

let locationToBlock = new BlockLocation(location.x, location.y, location.z) // Then this returns a strange block location like this (-19, 0, -19).

I hope you understand this

 

I created a function to "fix" this:

function getBlockFromLocation(location : Location, dimension : Dimension) : Block
{
    if(location.x < 0 && location.z < 0)
    {        
        return dimension.getBlock(new BlockLocation(location.x-1, location.y, location.z-1));
    }
    else if(location.x < 0)
    {
        return dimension.getBlock(new BlockLocation(location.x-1, location.y, location.z));
    }
    else if(location.z < 0)
    {
        return dimension.getBlock(new BlockLocation(location.x, location.y, location.z-1));
    }
    else
    {
        return dimension.getBlock(new BlockLocation(location.x, location.y, location.z));
    }
} 

 

Incomplete

Aletropy

2022-04-30, 06:33 PM

2023-01-20, 05:48 PM

2023-01-20, 05:48 PM

0

0

Plausible

1.19.0.29 Preview, 1.19.0.28 Beta

-