Initial work on larger player positions

This commit is contained in:
UnknownShadow200 2017-04-10 16:49:07 +10:00
parent f9d011af6e
commit 787a6a2a5a
5 changed files with 28 additions and 13 deletions

View File

@ -14,13 +14,14 @@ namespace ClassicalSharp.Network {
internal int ServerExtensionsCount;
internal bool sendHeldBlock, useMessageTypes;
internal int envMapVer = 2, blockDefsExtVer = 2;
internal bool needD3Fix;
internal bool needD3Fix, extEntityPos;
public void Reset(Game game) {
ServerExtensionsCount = 0;
sendHeldBlock = false; useMessageTypes = false;
envMapVer = 2; blockDefsExtVer = 2;
needD3Fix = false; game.UseCPEBlocks = false;
needD3Fix = false; extEntityPos = false;
game.UseCPEBlocks = false;
NetworkProcessor net = (NetworkProcessor)game.Server;
net.Reset();
@ -51,6 +52,9 @@ namespace ClassicalSharp.Network {
blockDefsExtVer = version;
if (version == 1) return;
net.packetSizes[(byte)Opcode.CpeDefineBlockExt] = 88;
} else if (ext == "ExtEntityPositions") {
//extEntityPos = true;
// TODO: need to increase packet sizes accordingly
}
}
@ -59,7 +63,7 @@ namespace ClassicalSharp.Network {
"EnvColors", "SelectionCuboid", "BlockPermissions", "ChangeModel", "EnvMapAppearance",
"EnvWeatherType", "HackControl", "MessageTypes", "PlayerClick", "FullCP437",
"LongerMessages", "BlockDefinitions", "BlockDefinitionsExt", "BulkBlockUpdate", "TextColors",
"EnvMapAspect", "EntityProperty",
"EnvMapAspect", "EntityProperty", "ExtEntityPositions",
};
}
}

View File

@ -53,7 +53,7 @@ namespace ClassicalSharp.Network {
game.LocalPlayer.UpdateName();
}
if (!readPosition) return;
if (!readPosition) return;
classic.ReadAbsoluteLocation(id, false);
if (id != EntityList.SelfID) return;

View File

@ -257,16 +257,12 @@ namespace ClassicalSharp.Network.Protocols {
}
internal void ReadAbsoluteLocation(byte id, bool interpolate) {
float x = reader.ReadInt16() / 32f;
float y = (reader.ReadInt16() - 51) / 32f; // We have to do this.
if (id == EntityList.SelfID) y += 22/32f;
float z = reader.ReadInt16() / 32f;
Vector3 P = reader.ReadPosition(id);
float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8());
float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8());
if (id == EntityList.SelfID) net.receivedFirstPosition = true;
LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, rotY, headX, false);
LocationUpdate update = LocationUpdate.MakePosAndOri(P, rotY, headX, false);
net.UpdateLocation(id, update, interpolate);
}
#endregion
@ -287,9 +283,7 @@ namespace ClassicalSharp.Network.Protocols {
writer.WriteUInt8((byte)Opcode.EntityTeleport);
writer.WriteUInt8((byte)payload); // held block when using HeldBlock, otherwise just 255
writer.WriteInt16((short)(pos.X * 32));
writer.WriteInt16((short)((int)(pos.Y * 32) + 51));
writer.WriteInt16((short)(pos.Z * 32));
writer.WritePosition(pos);
writer.WriteUInt8((byte)Utils.DegreesToPacked(rotY));
writer.WriteUInt8((byte)Utils.DegreesToPacked(headX));
net.SendPacket();

View File

@ -1,6 +1,8 @@
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
using System;
using System.Net.Sockets;
using ClassicalSharp.Entities;
using OpenTK;
namespace ClassicalSharp.Network {
@ -71,6 +73,14 @@ namespace ClassicalSharp.Network {
index += length;
return data;
}
public Vector3 ReadPosition(byte id) {
float x = ReadInt16() / 32f;
float y = (ReadInt16() - 51) / 32f; // We have to do this.
if (id == EntityList.SelfID) y += 22/32f;
float z = ReadInt16() / 32f;
return new Vector3(x, y, z);
}
public string ReadString() {
int length = GetString(Utils.StringLength);

View File

@ -1,6 +1,7 @@
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
using System;
using System.Net.Sockets;
using OpenTK;
namespace ClassicalSharp.Network {
@ -37,6 +38,12 @@ namespace ClassicalSharp.Network {
index += Utils.StringLength;
}
public void WritePosition(Vector3 pos) {
WriteInt16((short)(pos.X * 32));
WriteInt16((short)((int)(pos.Y * 32) + 51));
WriteInt16((short)(pos.Z * 32));
}
public void WriteUInt8(byte value) {
buffer[index++] = value;
}