mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
fix MultiBlockChangePacket again and add util method
This commit is contained in:
parent
664546d25d
commit
0c50164f40
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
@ -23,13 +24,20 @@ public class MultiBlockChangePacket implements ServerPacket {
|
||||
writer.writeVarInt(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
final BlockChange blockChange = blockChanges[i];
|
||||
writer.writeVarInt(blockChange.newBlockId << 12 | ChunkUtils.getLocalBlockPosAsShort(blockChange.positionX, blockChange.positionY, blockChange.positionZ));
|
||||
writer.writeVarLong(blockChange.newBlockId << 12 | getLocalBlockPosAsShort(blockChange.positionX, blockChange.positionY, blockChange.positionZ));
|
||||
}
|
||||
} else {
|
||||
writer.writeVarInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static short getLocalBlockPosAsShort(int x, int y, int z) {
|
||||
x = x % Chunk.CHUNK_SIZE_X;
|
||||
y = y % 16;
|
||||
z = z % Chunk.CHUNK_SIZE_Z;
|
||||
return (short) (x << 8 | z << 4 | y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.MULTI_BLOCK_CHANGE;
|
||||
|
@ -95,6 +95,13 @@ public final class ChunkUtils {
|
||||
return (short) (x << 12 | y << 4 | z);
|
||||
}
|
||||
|
||||
public static BlockPosition getBlockPositionFromLocalShort(short index) {
|
||||
int x = index >> 12 & 0b1111;
|
||||
int y = (index >> 4) & 0b11111111;
|
||||
int z = index & 0b1111;
|
||||
return new BlockPosition(x, y, z);
|
||||
}
|
||||
|
||||
public static int getSectionAt(int y) {
|
||||
return y / Chunk.CHUNK_SECTION_SIZE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user