2727import org .spongepowered .asm .mixin .injection .Inject ;
2828import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2929
30- import java .util .Collections ;
31- import java .util .HashSet ;
30+ import java .util .ArrayList ;
31+ import java .util .Arrays ;
3232import java .util .List ;
33+ import java .util .stream .Collectors ;
3334
3435import static net .minecraft .network .packet .s2c .play .PlayerListS2CPacket .Action .ADD_PLAYER ;
3536import static net .minecraft .network .packet .s2c .play .PlayerListS2CPacket .Action .REMOVE_PLAYER ;
4243public abstract class ServerPlayNetworkHandlerMixin_PacketFaker {
4344
4445 @ Shadow public ServerPlayerEntity player ;
46+
47+ @ Shadow public abstract void sendPacket (Packet <?> packet );
48+
4549 @ Unique
4650 private boolean taterzens$skipCheck ;
4751 @ Unique
48- private final HashSet < PlayerListS2CPacket > taterzens$tablistQueue = new HashSet < >();
52+ private final List < TaterzenNPC > taterzens$tablistQueue = new ArrayList < TaterzenNPC >();
4953 private int taterzens$queueTimer ;
5054
51- @ Shadow public abstract void sendPacket (Packet <?> packet );
52-
5355 /**
5456 * Changes entity type if entity is an instance of {@link TaterzenNPC}.
5557 *
@@ -78,9 +80,7 @@ private void changeEntityType(Packet<?> packet, GenericFutureListener<? extends
7880 PlayerListS2CPacket playerAddPacket = new PlayerListS2CPacket (ADD_PLAYER );
7981 //noinspection ConstantConditions
8082 ((PlayerListS2CPacketAccessor ) playerAddPacket ).setEntries (
81- Collections .singletonList (
82- playerAddPacket .new Entry (profile , 0 , GameMode .SURVIVAL , npc .getName ())
83- )
83+ Arrays .asList (playerAddPacket .new Entry (profile , 0 , GameMode .SURVIVAL , npc .getName ()))
8484 );
8585 taterzens$skipCheck = true ;
8686 this .sendPacket (playerAddPacket );
@@ -91,18 +91,12 @@ playerAddPacket.new Entry(profile, 0, GameMode.SURVIVAL, npc.getName())
9191 this .sendPacket (packet );
9292
9393 PlayerListS2CPacket playerRemovePacket = new PlayerListS2CPacket (REMOVE_PLAYER );
94- //noinspection ConstantConditions
95- ((PlayerListS2CPacketAccessor ) playerRemovePacket ).setEntries (
96- Collections .singletonList (
97- playerRemovePacket .new Entry (profile , 0 , GameMode .SURVIVAL , npc .getName ())
98- )
99- );
10094 // And now we can remove it from tablist
10195 // we must delay the tablist packet so as to allow
10296 // the client to fetch skin.
10397 // If player is immediately removed from the tablist,
10498 // client doesn't care about the skin.
105- this .taterzens$tablistQueue .add (playerRemovePacket );
99+ this .taterzens$tablistQueue .add (npc );
106100 this .taterzens$queueTimer = config .taterzenTablistTimeout ;
107101
108102 this .taterzens$skipCheck = false ;
@@ -123,8 +117,23 @@ playerRemovePacket.new Entry(profile, 0, GameMode.SURVIVAL, npc.getName())
123117 private void removeTaterzenFromTablist (PlayerMoveC2SPacket packet , CallbackInfo ci ) {
124118 if (!this .taterzens$tablistQueue .isEmpty () && --this .taterzens$queueTimer == 0 ) {
125119 this .taterzens$skipCheck = true ;
126- this .taterzens$tablistQueue .forEach (this ::sendPacket );
120+
121+ PlayerListS2CPacket taterzensRemovePacket = new PlayerListS2CPacket (REMOVE_PLAYER );
122+ List <PlayerListS2CPacket .Entry > taterzenList = this .taterzens$tablistQueue
123+ .stream ()
124+ .map (npc -> taterzensRemovePacket .new Entry (
125+ npc .getGameProfile (),
126+ 0 ,
127+ GameMode .SURVIVAL ,
128+ npc .getName ()
129+ )
130+ )
131+ .collect (Collectors .toList ());
132+ //noinspection ConstantConditions
133+ ((PlayerListS2CPacketAccessor ) taterzensRemovePacket ).setEntries (taterzenList );
134+ this .sendPacket (taterzensRemovePacket );
127135 this .taterzens$tablistQueue .clear ();
136+
128137 this .taterzens$skipCheck = false ;
129138 }
130139 }
0 commit comments