This commit is contained in:
Felix Cravic 2020-04-26 17:03:42 +02:00
parent 1639a4947c
commit 161e229985
4 changed files with 9 additions and 41 deletions

View File

@ -342,6 +342,12 @@ public class Chunk implements Viewable {
}
private int getBlockIndex(int x, int y, int z) {
x = x % 16;
z = z % 16;
x = x < 0 ? Chunk.CHUNK_SIZE_X + x : x;
z = z < 0 ? Chunk.CHUNK_SIZE_Z + z : z;
int index = (((y * 16) + x) * 16) + z;
return index;
}

View File

@ -157,11 +157,6 @@ public abstract class Instance implements BlockModifier, DataContainer {
public short getBlockId(int x, int y, int z) {
Chunk chunk = getChunkAt(x, z);
x = x % 16;
z = z % 16;
x = ChunkUtils.refreshChunkXZ(x);
z = ChunkUtils.refreshChunkXZ(z);
return chunk.getBlockId(x, y, z);
}
@ -175,11 +170,6 @@ public abstract class Instance implements BlockModifier, DataContainer {
public CustomBlock getCustomBlock(int x, int y, int z) {
Chunk chunk = getChunkAt(x, z);
x = x % 16;
z = z % 16;
x = ChunkUtils.refreshChunkXZ(x);
z = ChunkUtils.refreshChunkXZ(z);
return chunk.getCustomBlock(x, y, z);
}
@ -202,11 +192,6 @@ public abstract class Instance implements BlockModifier, DataContainer {
public Data getBlockData(int x, int y, int z) {
Chunk chunk = getChunkAt(x, z);
x = x % 16;
z = z % 16;
x = ChunkUtils.refreshChunkXZ(x);
z = ChunkUtils.refreshChunkXZ(z);
return chunk.getData((byte) x, (byte) y, (byte) z);
}

View File

@ -52,9 +52,6 @@ public class InstanceContainer extends Instance {
int chunkY = y;
int chunkZ = z % 16;
chunkX = ChunkUtils.refreshChunkXZ(chunkX);
chunkZ = ChunkUtils.refreshChunkXZ(chunkZ);
int index = SerializerUtils.chunkCoordToIndex(chunkX, chunkY, chunkZ);
callBlockDestroy(chunk, index, x, y, z);
@ -63,7 +60,7 @@ public class InstanceContainer extends Instance {
blockId = executeBlockPlacementRule(blockId, blockPosition);
chunk.UNSAFE_setBlock(chunkX, chunkY, chunkZ, blockId, data);
chunk.UNSAFE_setBlock(x, y, z, blockId, data);
executeNeighboursBlockPlacementRule(blockPosition);
@ -80,9 +77,6 @@ public class InstanceContainer extends Instance {
int chunkY = y;
int chunkZ = z % 16;
chunkX = ChunkUtils.refreshChunkXZ(chunkX);
chunkZ = ChunkUtils.refreshChunkXZ(chunkZ);
int index = SerializerUtils.chunkCoordToIndex(chunkX, chunkY, chunkZ);
callBlockDestroy(chunk, index, x, y, z);
@ -106,16 +100,8 @@ public class InstanceContainer extends Instance {
public void refreshBlockId(int x, int y, int z, short blockId) {
Chunk chunk = getChunkAt(x, z);
synchronized (chunk) {
int chunkX = x % 16;
int chunkY = y;
int chunkZ = z % 16;
chunk.refreshBlockValue(x, y, z, blockId);
chunkX = ChunkUtils.refreshChunkXZ(chunkX);
chunkZ = ChunkUtils.refreshChunkXZ(chunkZ);
chunk.refreshBlockValue(chunkX, chunkY, chunkZ, blockId);
// TODO instead of sending a block change packet each time, cache changed blocks and flush them every tick with a MultiBlockChangePacket
sendBlockChange(chunk, x, y, z, blockId);
}
}
@ -174,10 +160,7 @@ public class InstanceContainer extends Instance {
int blockY = blockPosition.getY();
int blockZ = blockPosition.getZ();
blockX = ChunkUtils.refreshChunkXZ(blockX);
blockZ = ChunkUtils.refreshChunkXZ(blockZ);
short blockId = chunk.getBlockId((byte) (blockX % 16), blockY, (byte) (blockZ % 16));
short blockId = chunk.getBlockId(blockX, blockY, blockZ);
if (blockId == 0) {
sendChunkSectionUpdate(chunk, ChunkUtils.getSectionAt(blockPosition.getY()), player);
return;

View File

@ -1,6 +1,5 @@
package net.minestom.server.utils;
import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.Instance;
public class ChunkUtils {
@ -13,11 +12,6 @@ public class ChunkUtils {
return Math.floorDiv(xz, 16);
}
public static int refreshChunkXZ(int xz) {
/// suppose CHUNK_SIZE_X == CHUNK_SIZE_Z
return xz = xz < 0 ? Chunk.CHUNK_SIZE_X + xz : xz;
}
public static long getChunkIndex(int chunkX, int chunkZ) {
return (((long) chunkX) << 32) | (chunkZ & 0xffffffffL);
}