mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 01:47:54 +01:00
Fix chunk coordinates not being properly calculated
This commit is contained in:
parent
0010c1c158
commit
4f2ec0a65f
@ -646,8 +646,8 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
|
||||
final ChunkCallback eachCallback = chunk -> {
|
||||
if (chunk != null) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate((int) spawnPosition.getX());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate((int) spawnPosition.getZ());
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate(spawnPosition.getX());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate(spawnPosition.getZ());
|
||||
if (chunk.getChunkX() == chunkX &&
|
||||
chunk.getChunkZ() == chunkZ) {
|
||||
updateViewPosition(chunkX, chunkZ);
|
||||
|
@ -581,8 +581,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
* @param callback the optional callback to run when the chunk is loaded
|
||||
*/
|
||||
public void loadChunk(@NotNull Position position, @Nullable ChunkCallback callback) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ());
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate(position.getX());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate(position.getZ());
|
||||
loadChunk(chunkX, chunkZ, callback);
|
||||
}
|
||||
|
||||
@ -594,8 +594,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
* @param callback the optional callback executed when the chunk is loaded (or with a null chunk if not)
|
||||
*/
|
||||
public void loadOptionalChunk(@NotNull Position position, @Nullable ChunkCallback callback) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ());
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate(position.getX());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate(position.getZ());
|
||||
loadOptionalChunk(chunkX, chunkZ, callback);
|
||||
}
|
||||
|
||||
@ -786,8 +786,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
*/
|
||||
@Nullable
|
||||
public Chunk getChunkAt(double x, double z) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate((int) Math.floor(x));
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate((int) Math.floor(z));
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate(x);
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate(z);
|
||||
return getChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
|
@ -268,11 +268,11 @@ public class Position implements PublicCloneable<Position> {
|
||||
* @return true if 'this' is in the same chunk as {@code position}
|
||||
*/
|
||||
public boolean inSameChunk(@NotNull Position position) {
|
||||
final int chunkX1 = ChunkUtils.getChunkCoordinate((int) getX());
|
||||
final int chunkZ1 = ChunkUtils.getChunkCoordinate((int) getZ());
|
||||
final int chunkX1 = ChunkUtils.getChunkCoordinate(getX());
|
||||
final int chunkZ1 = ChunkUtils.getChunkCoordinate(getZ());
|
||||
|
||||
final int chunkX2 = ChunkUtils.getChunkCoordinate((int) position.getX());
|
||||
final int chunkZ2 = ChunkUtils.getChunkCoordinate((int) position.getZ());
|
||||
final int chunkX2 = ChunkUtils.getChunkCoordinate(position.getX());
|
||||
final int chunkZ2 = ChunkUtils.getChunkCoordinate(position.getZ());
|
||||
|
||||
return chunkX1 == chunkX2 && chunkZ1 == chunkZ2;
|
||||
}
|
||||
|
@ -77,8 +77,8 @@ public final class ChunkUtils {
|
||||
* @return true if the chunk is loaded, false otherwise
|
||||
*/
|
||||
public static boolean isLoaded(@NotNull Instance instance, double x, double z) {
|
||||
final int chunkX = getChunkCoordinate((int) x);
|
||||
final int chunkZ = getChunkCoordinate((int) z);
|
||||
final int chunkX = getChunkCoordinate(x);
|
||||
final int chunkZ = getChunkCoordinate(z);
|
||||
|
||||
final Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
||||
return isLoaded(chunk);
|
||||
@ -88,9 +88,10 @@ public final class ChunkUtils {
|
||||
* @param xz the instance coordinate to convert
|
||||
* @return the chunk X or Z based on the argument
|
||||
*/
|
||||
public static int getChunkCoordinate(int xz) {
|
||||
public static int getChunkCoordinate(double xz) {
|
||||
final int coordinate = (int) Math.floor(xz);
|
||||
assert Chunk.CHUNK_SIZE_X == Chunk.CHUNK_SIZE_Z;
|
||||
return Math.floorDiv(xz, Chunk.CHUNK_SIZE_X);
|
||||
return Math.floorDiv(coordinate, Chunk.CHUNK_SIZE_X);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,8 +156,8 @@ public final class ChunkUtils {
|
||||
int counter = 0;
|
||||
for (int x = startLoop; x < endLoop; x++) {
|
||||
for (int z = startLoop; z < endLoop; z++) {
|
||||
final int chunkX = getChunkCoordinate((int) (position.getX() + Chunk.CHUNK_SIZE_X * x));
|
||||
final int chunkZ = getChunkCoordinate((int) (position.getZ() + Chunk.CHUNK_SIZE_Z * z));
|
||||
final int chunkX = getChunkCoordinate(position.getX() + Chunk.CHUNK_SIZE_X * x);
|
||||
final int chunkZ = getChunkCoordinate(position.getZ() + Chunk.CHUNK_SIZE_Z * z);
|
||||
visibleChunks[counter++] = getChunkIndex(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user