PrismarineJS / flying-squid

Create Minecraft servers with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/flying-squid/
MIT License
548 stars 100 forks source link

[/tp command] - Check if x/y/z is valid #576

Closed ghost closed 2 years ago

ghost commented 2 years ago

using Math.abs(x) > 29999999 || Math.abs(y) > 4096 || Math.abs(z) > 29999999 would likely look nicer

Remember that we also must have check for negative x/y/z so your code will look like this Math.abs(x) > 29999999 || Math.abs(y) > 4096 || Math.abs(z) > 29999999 || Math.abs(x) < -29999999 || Math.abs(y) < -4096 || Math.abs(z) < -29999999

so I think my code is nicer

darksunlight commented 2 years ago

using Math.abs(x) > 29999999 || Math.abs(y) > 4096 || Math.abs(z) > 29999999 would likely look nicer

Remember that we also must have check for negative x/y/z so your code will look like this Math.abs(x) > 29999999 || Math.abs(y) > 4096 || Math.abs(z) > 29999999 || Math.abs(x) < -29999999 || Math.abs(y) < -4096 || Math.abs(z) < -29999999

so I think my code is nicer

No. Not really. Math.abs returns the absolute value of its first parameter. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs