@@ -484,7 +484,7 @@ void ProcessSetBlockPacket() {
484484 Message ( "&SYou are no longer AFK" ) ;
485485 IsAFK = false ;
486486 oldafkMob = afkMob ;
487- afkMob = Info . Mob ;
487+ afkMob = Info . Model ;
488488 Server . UpdateTabList ( true ) ;
489489 }
490490 ResetIdleTimer ( ) ;
@@ -1182,11 +1182,7 @@ void SendJoinMessage(World oldWorld, World newWorld) {
11821182
11831183 void SendJoinCpeExtensions ( ) {
11841184 SendEnvSettings ( ) ;
1185- SendNow ( SpawnPacket ( Packet . SelfId , Info . Rank . Color + Name , Info . Skin , Position ) ) ;
1186-
1187- if ( Supports ( CpeExt . ChangeModel ) ) {
1188- SendNow ( Packet . MakeChangeModel ( 255 , ! IsAFK ? Info . Mob : AFKModel , HasCP437 ) ) ;
1189- }
1185+ Entities . Spawn ( this , true , this , Packet . SelfId ) ;
11901186
11911187 if ( Supports ( CpeExt . HackControl ) ) {
11921188 SendNow ( PlayerHacks . MakePacket ( this , World . MOTD ) ) ;
@@ -1215,17 +1211,14 @@ void SendJoinCpeExtensions() {
12151211
12161212 internal void RemoveOldEntities ( World world ) {
12171213 if ( world == null ) return ;
1218- foreach ( Entity entity in Entity . Entities . Where ( e => Entity . getWorld ( e ) == world ) ) {
1214+ foreach ( Entity entity in Entity . EntityList . Where ( e => Entity . getWorld ( e ) == world ) ) {
12191215 SendNow ( Packet . MakeRemoveEntity ( entity . ID ) ) ;
12201216 }
12211217 }
12221218
12231219 internal void SendNewEntities ( World world ) {
1224- foreach ( Entity entity in Entity . Entities . Where ( e => Entity . getWorld ( e ) == world ) ) {
1225- SendNow ( SpawnPacket ( entity . ID , entity . Name , entity . Skin , Entity . getPos ( entity ) ) ) ;
1226-
1227- if ( ! entity . Model . CaselessEquals ( "humanoid" ) && Supports ( CpeExt . ChangeModel ) )
1228- SendNow ( Packet . MakeChangeModel ( ( byte ) entity . ID , entity . Model , HasCP437 ) ) ;
1220+ foreach ( Entity entity in Entity . EntityList . Where ( e => Entity . getWorld ( e ) == world ) ) {
1221+ Entities . Spawn ( this , true , entity ) ;
12291222 }
12301223 }
12311224
@@ -1372,17 +1365,6 @@ public void Send(Packet packet) {
13721365 if ( canQueue ) priorityOutputQueue . Enqueue ( packet ) ;
13731366 }
13741367
1375-
1376- /// <summary> Returns an appropriate spawn packet for this player. </summary>
1377- public Packet SpawnPacket ( sbyte id , string name , string skin , Position pos ) {
1378- name = Color . SubstituteSpecialColors ( name , FallbackColors ) ;
1379- if ( Supports ( CpeExt . ExtPlayerList2 ) ) {
1380- return Packet . MakeExtAddEntity2 ( id , name , skin , pos , HasCP437 , supportsExtPositions ) ;
1381- } else {
1382- return Packet . MakeAddEntity ( id , name , pos , HasCP437 , supportsExtPositions ) ;
1383- }
1384- }
1385-
13861368 /// <summary> Returns an appropriate spawn packet for this player. </summary>
13871369 public Packet TeleportPacket ( sbyte id , Position pos ) {
13881370 if ( id == Packet . SelfId ) pos = pos . GetFixed ( ) ;
@@ -1596,9 +1578,13 @@ void UpdateVisibleEntities() {
15961578 }
15971579 }
15981580 }
1581+
15991582 oldskinName = Info . skinName ;
1600- oldMob = Info . Mob ;
1583+ oldMob = Info . Model ;
16011584 oldafkMob = afkMob ;
1585+ oldRotX = RotX ;
1586+ oldRotZ = RotZ ;
1587+
16021588 lock ( entitiesLock )
16031589 RemoveNonRetainedEntities ( ) ;
16041590
@@ -1669,32 +1655,28 @@ void FollowSpectatedEntity() {
16691655 } else if ( spectatePos != Position ) {
16701656 SendNow ( TeleportPacket ( Packet . SelfId , spectatePos ) ) ;
16711657 }
1672- if ( SpectatedPlayer . HeldBlock != HeldBlock && SpectatedPlayer . Supports ( CpeExt . HeldBlock ) )
1673- {
1658+
1659+ if ( SpectatedPlayer . HeldBlock != HeldBlock && SpectatedPlayer . Supports ( CpeExt . HeldBlock ) ) {
16741660 byte block = ( byte ) SpectatedPlayer . HeldBlock ;
16751661 CheckBlock ( ref block ) ;
16761662 SendNow ( Packet . MakeHoldThis ( ( Block ) block , false ) ) ;
16771663 }
16781664 }
16791665
1680- void CheckOwnChange ( sbyte id , Player otherPlayer ) {
1681- if ( oldskinName != Info . skinName && otherPlayer . Supports ( CpeExt . ExtPlayerList2 ) ) {
1682- otherPlayer . Send ( otherPlayer . SpawnPacket ( id , Info . Rank . Color + Name , Info . Skin , Position ) ) ;
1683- //otherPlayer.Send(Packet.MakeTeleport(id, Position));
1684- if ( otherPlayer . Supports ( CpeExt . ChangeModel ) ) {
1685- string thisModel = IsAFK ? AFKModel : Info . Mob ;
1686- if ( otherPlayer . Info . Rank . CanSee ( Info . Rank ) && ( thisModel . CaselessEquals ( "air" ) || thisModel . CaselessEquals ( "0" ) ) ) {
1687- thisModel = "Humanoid" ;
1688- }
1689- otherPlayer . Send ( Packet . MakeChangeModel ( ( byte ) id , thisModel , otherPlayer . HasCP437 ) ) ;
1690- }
1666+ void CheckOwnChange ( sbyte id , Player other ) {
1667+ bool needsUpdate = false ;
1668+ if ( oldskinName != Info . skinName && other . Supports ( CpeExt . ExtPlayerList2 ) ) needsUpdate = true ;
1669+ if ( ( oldRotX != RotX || oldRotZ != RotZ ) && other . Supports ( CpeExt . EntityProperty ) ) needsUpdate = true ;
1670+
1671+ if ( needsUpdate ) {
1672+ Entities . Spawn ( other , false , this , id ) ;
1673+ // need to send teleport packet for correct position
1674+ other . Send ( TeleportPacket ( id , Position ) ) ;
16911675 }
1692- if ( ( oldMob != Info . Mob || oldafkMob != afkMob ) && otherPlayer . Supports ( CpeExt . ChangeModel ) ) {
1693- string thisModel = IsAFK ? AFKModel : Info . Mob ;
1694- if ( otherPlayer . Info . Rank . CanSee ( Info . Rank ) && ( thisModel . CaselessEquals ( "air" ) || thisModel . CaselessEquals ( "0" ) ) ) {
1695- thisModel = "Humanoid" ;
1696- }
1697- otherPlayer . Send ( Packet . MakeChangeModel ( ( byte ) id , thisModel , otherPlayer . HasCP437 ) ) ;
1676+
1677+ if ( ( oldMob != Info . Model || oldafkMob != afkMob ) && other . Supports ( CpeExt . ChangeModel ) ) {
1678+ string model = Entities . ModelFor ( other , this ) ;
1679+ other . Send ( Packet . MakeChangeModel ( id , model , other . HasCP437 ) ) ;
16981680 }
16991681 }
17001682
@@ -1712,16 +1694,8 @@ VisibleEntity AddEntity( [NotNull] Player player ) {
17121694 pos = player . WorldMap . Spawn ;
17131695 }
17141696
1715- Send ( SpawnPacket ( newEntity . Id , player . Info . Rank . Color + player . Name , player . Info . Skin , pos ) ) ;
1697+ Entities . Spawn ( this , false , player , newEntity . Id ) ;
17161698 Send ( TeleportPacket ( newEntity . Id , player . Position ) ) ;
1717-
1718- if ( Supports ( CpeExt . ChangeModel ) ) {
1719- string addedModel = player . IsAFK ? player . AFKModel : player . Info . Mob ;
1720- if ( Info . Rank . CanSee ( player . Info . Rank ) && ( addedModel . CaselessEquals ( "air" ) || addedModel . CaselessEquals ( "0" ) ) ) {
1721- addedModel = "Humanoid" ;
1722- }
1723- Send ( Packet . MakeChangeModel ( ( byte ) newEntity . Id , addedModel , HasCP437 ) ) ;
1724- }
17251699 return newEntity ;
17261700 } else {
17271701 throw new InvalidOperationException ( "Player.AddEntity: Ran out of entity IDs." ) ;
@@ -1757,16 +1731,9 @@ void ReAddEntity( [NotNull] VisibleEntity entity, [NotNull] Player player ) {
17571731 Logger . Log ( LogType . Debug , "ReAddEntity: {0} re-added {1} ({2})" , Name , entity . Id , player . Name ) ;
17581732#endif
17591733 SendNow ( Packet . MakeRemoveEntity ( entity . Id ) ) ;
1760- SendNow ( SpawnPacket ( entity . Id , player . Info . Rank . Color + player . Name , player . Info . Skin , player . WorldMap . Spawn ) ) ;
1761- SendNow ( TeleportPacket ( entity . Id , player . Position ) ) ;
1762-
1763- if ( Supports ( CpeExt . ChangeModel ) ) {
1764- string readdedModel = player . IsAFK ? player . AFKModel : player . Info . Mob ;
1765- if ( Info . Rank . CanSee ( player . Info . Rank ) && ( readdedModel . CaselessEquals ( "air" ) || readdedModel . CaselessEquals ( "0" ) ) ) {
1766- readdedModel = "Humanoid" ;
1767- }
1768- SendNow ( Packet . MakeChangeModel ( ( byte ) entity . Id , readdedModel , HasCP437 ) ) ;
1769- }
1734+ Entities . Spawn ( this , true , player , entity . Id ) ;
1735+ // need to send teleport packet for correct position
1736+ SendNow ( TeleportPacket ( entity . Id , player . Position ) ) ;
17701737 }
17711738
17721739
0 commit comments