переход на BlockLocationSerializer
This commit is contained in:
@@ -25,18 +25,4 @@ public class CompactedCoords {
|
|||||||
int i = (int)value;
|
int i = (int)value;
|
||||||
return value < (double)i ? i - 1 : i;
|
return value < (double)i ? i - 1 : i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long compressXYZ(double x, double y, double z) {
|
|
||||||
return ((floor_double(x) & 0x3FFFFFF) << 38)
|
|
||||||
| ((floor_double(y) & 0xFFF) << 26)
|
|
||||||
| (floor_double(z) & 0x3FFFFFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double[] uncompressXYZ(long compactValue) {
|
|
||||||
return new double[]{
|
|
||||||
compactValue >> 38,
|
|
||||||
(compactValue >> 26) & 0x0FFF,
|
|
||||||
compactValue << 38 >> 38 // is normal?
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package mc.core.utils;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -24,20 +23,4 @@ public class TestCompactedCoords {
|
|||||||
assertEquals(z, xz[1]);
|
assertEquals(z, xz[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void testXYZSimple() {
|
|
||||||
for (int z = -100; z <= 100; z++) {
|
|
||||||
for (int x = -100; x <= 100; x++) {
|
|
||||||
for (int y = -100; y <= 100; y++) {
|
|
||||||
long compressXYZ = CompactedCoords.compressXYZ(x, y, z);
|
|
||||||
double[] xyz = CompactedCoords.uncompressXYZ(compressXYZ);
|
|
||||||
|
|
||||||
assertEquals(x, xyz[0], 0.001d);
|
|
||||||
assertEquals(y, xyz[1], 0.001d);
|
|
||||||
assertEquals(z, xyz[2], 0.001d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package mc.core.network.proto_1_12_2.packets;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import mc.core.network.proto_1_12_2.serializers.BlockLocationSerializer;
|
||||||
import mc.core.world.block.BlockLocation;
|
import mc.core.world.block.BlockLocation;
|
||||||
import mc.core.network.CSPacket;
|
import mc.core.network.CSPacket;
|
||||||
import mc.core.network.NetInputStream;
|
import mc.core.network.NetInputStream;
|
||||||
@@ -20,8 +21,7 @@ public class PlayerBlockPlacementPacket implements CSPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void readSelf(NetInputStream netStream) {
|
public void readSelf(NetInputStream netStream) {
|
||||||
long compactedCoords = netStream.readLong();
|
long compactedCoords = netStream.readLong();
|
||||||
double[] xyz = CompactedCoords.uncompressXYZ(compactedCoords);
|
location = BlockLocationSerializer.fromLong(compactedCoords);
|
||||||
location = new BlockLocation((int)xyz[0], (int)xyz[1], (int)xyz[2]); //FIXME
|
|
||||||
face = Direction.getById(netStream.readVarInt());
|
face = Direction.getById(netStream.readVarInt());
|
||||||
hand = (netStream.readVarInt() == 1);
|
hand = (netStream.readVarInt() == 1);
|
||||||
cursorX = netStream.readFloat();
|
cursorX = netStream.readFloat();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mc.core.network.proto_1_12_2.packets;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import mc.core.network.proto_1_12_2.serializers.BlockLocationSerializer;
|
||||||
import mc.core.world.block.BlockLocation;
|
import mc.core.world.block.BlockLocation;
|
||||||
import mc.core.network.CSPacket;
|
import mc.core.network.CSPacket;
|
||||||
import mc.core.network.NetInputStream;
|
import mc.core.network.NetInputStream;
|
||||||
@@ -49,8 +50,7 @@ public class PlayerDiggingPacket implements CSPacket {
|
|||||||
public void readSelf(NetInputStream netStream) {
|
public void readSelf(NetInputStream netStream) {
|
||||||
status = Status.getById(netStream.readVarInt());
|
status = Status.getById(netStream.readVarInt());
|
||||||
long compactCoord = netStream.readLong();
|
long compactCoord = netStream.readLong();
|
||||||
double[] xyz = CompactedCoords.uncompressXYZ(compactCoord);
|
location = BlockLocationSerializer.fromLong(compactCoord);
|
||||||
location = new BlockLocation((int)xyz[0], (int)xyz[1], (int)xyz[2]); //FIXME
|
|
||||||
face = Direction.getById(netStream.readByte());
|
face = Direction.getById(netStream.readByte());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user