Add preciserespawn MOTD flag

This commit is contained in:
Goodlyay 2018-12-30 02:57:30 -08:00
parent 219d8cd7ca
commit f7364a0e63
2 changed files with 28 additions and 17 deletions

View file

@ -33,6 +33,7 @@ namespace ClassicalSharp.Entities {
public bool CanSpeed = true;
public bool CanFly = true;
public bool CanRespawn = true;
public bool CanPreciseRespawn = false;
public bool CanNoclip = true;
public bool CanPushbackBlocks = true;
public bool CanSeeAllNames = true;
@ -138,6 +139,7 @@ namespace ClassicalSharp.Entities {
public void UpdateHacksState() {
SetAllHacks(true);
CanBePushed = true;
CanPreciseRespawn = false;
if (HacksFlags == null) return;
// By default (this is also the case with WoM), we can use hacks.
@ -147,6 +149,7 @@ namespace ClassicalSharp.Entities {
ParseFlag(ref CanNoclip, "noclip");
ParseFlag(ref CanSpeed, "speed");
ParseFlag(ref CanRespawn, "respawn");
ParseFlag(ref CanPreciseRespawn, "preciserespawn");
ParseFlag(ref CanBePushed, "push");
if (UserType == 0x64) ParseAllFlag("ophax");

View file

@ -180,18 +180,20 @@ namespace ClassicalSharp.Entities {
AABB bb;
// Spawn player at highest valid position
if (game.World.IsValidPos(P)) {
bb = AABB.Make(spawn, Size);
for (int y = P.Y; y <= game.World.Height; y++) {
float spawnY = Respawn.HighestFreeY(game, ref bb);
if (spawnY == float.NegativeInfinity) {
BlockID block = game.World.GetPhysicsBlock(P.X, y, P.Z);
float height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0;
spawn.Y = y + height + Entity.Adjustment;
break;
}
bb.Min.Y += 1; bb.Max.Y += 1;
}
if (!Hacks.CanPreciseRespawn) {
if (game.World.IsValidPos(P)) {
bb = AABB.Make(spawn, Size);
for (int y = P.Y; y <= game.World.Height; y++) {
float spawnY = Respawn.HighestFreeY(game, ref bb);
if (spawnY == float.NegativeInfinity) {
BlockID block = game.World.GetPhysicsBlock(P.X, y, P.Z);
float height = BlockInfo.Collide[block] == CollideType.Solid ? BlockInfo.MaxBB[block].Y : 0;
spawn.Y = y + height + Entity.Adjustment;
break;
}
bb.Min.Y += 1; bb.Max.Y += 1;
}
}
}
spawn.Y += 2/16f;
@ -206,7 +208,7 @@ namespace ClassicalSharp.Entities {
}
bool HandleRespawn() {
if (Hacks.CanRespawn) {
if (Hacks.CanRespawn || Hacks.CanPreciseRespawn) {
DoRespawn();
return true;
} else if (!warnedRespawn) {
@ -217,10 +219,16 @@ namespace ClassicalSharp.Entities {
}
bool HandleSetSpawn() {
if (Hacks.CanRespawn) {
Spawn.X = Utils.Floor(Position.X) + 0.5f;
Spawn.Y = Position.Y;
Spawn.Z = Utils.Floor(Position.Z) + 0.5f;
if (Hacks.CanRespawn || Hacks.CanPreciseRespawn) {
if (Hacks.CanPreciseRespawn) {
Spawn.X = Position.X;
Spawn.Y = Position.Y;
Spawn.Z = Position.Z;
} else {
Spawn.X = Utils.Floor(Position.X) + 0.5f;
Spawn.Y = Position.Y;
Spawn.Z = Utils.Floor(Position.Z) + 0.5f;
}
SpawnRotY = RotY;
SpawnHeadX = HeadX;
}