11package org .powernukkitx .anyversion .handler .handlers ;
22
33import org .cloudburstmc .protocol .bedrock .data .inventory .ItemData ;
4+ import org .cloudburstmc .protocol .bedrock .data .payload .creative .CreativeGroupInfoPayload ;
45import org .cloudburstmc .protocol .bedrock .data .payload .creative .CreativeItemEntryPayload ;
56import org .cloudburstmc .protocol .bedrock .packet .CreativeContentPacket ;
67import org .powernukkitx .anyversion .handler .PacketHandler ;
78import org .powernukkitx .anyversion .manager .ProtocolPlayer ;
89import org .powernukkitx .anyversion .registries .Registries ;
910
10- import java .util .Iterator ;
11+ import java .util .ArrayList ;
12+ import java .util .List ;
1113
1214public class CreativeContentHandler extends PacketHandler <CreativeContentPacket > {
1315
1416 @ Override
1517 public void handle (ProtocolPlayer player , CreativeContentPacket packet ) {
16- Iterator <CreativeItemEntryPayload > iterator = packet .getEntries (). iterator ( );
17- while ( iterator . hasNext ()) {
18- CreativeItemEntryPayload data = iterator . next ();
18+ List <CreativeItemEntryPayload > c = new ArrayList <>( packet .getEntries ());
19+ packet . getEntries (). clear ();
20+ for ( CreativeItemEntryPayload data : c ) {
1921 if (data .getItemInstance ().getDefinition () == null ) {
22+ packet .getEntries ().add (data );
2023 continue ;
2124 }
2225 ItemData itemData = Registries .ITEM .downgrade (player .getVersion (), data .getItemInstance ());
23- if (itemData .getDefinition () == null || Registries .ITEM .getOutdated (itemData ).getDefinition () == null ) {
26+ if (itemData .getDefinition () == null || Registries .ITEM .getOutdated (itemData ).getDefinition () == null ) {
27+ packet .getEntries ().add (data );
2428 continue ;
2529 }
26- if (itemData .getDefinition ().getIdentifier ().equals (Registries .ITEM .getOutdated (itemData ).getDefinition ().getIdentifier ())) {
27- iterator .remove ();
28- continue ;
29- }
30- data .setItemInstance (itemData );
30+ if (itemData .getDefinition ().getIdentifier ().equals (Registries .ITEM .getOutdated (itemData ).getDefinition ().getIdentifier ())) continue ;
31+ CreativeItemEntryPayload newData = new CreativeItemEntryPayload ();
32+ newData .setItemInstance (itemData );
33+ newData .setCreativeNetId (data .getCreativeNetId ());
34+ newData .setGroupIndex (data .getGroupIndex ());
35+ packet .getEntries ().add (newData );
3136 }
32- }
3337
34- }
38+ for (CreativeGroupInfoPayload data : packet .getGroups ()) {
39+ ItemData itemData = Registries .ITEM .downgrade (player .getVersion (), data .getGroupIconItem ());
40+ data .setGroupIconItem (itemData );
41+ }
42+ }
43+ }
0 commit comments