package com.github.steveice10.mc.protocol.packet.ingame.server;

import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.With;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Data
@With
@Setter(AccessLevel.NONE)
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
public class ServerDeclareTagsPacket implements Packet {
    private @NonNull Map<String, int[]> blockTags;
    private @NonNull Map<String, int[]> itemTags;
    private @NonNull Map<String, int[]> fluidTags;
    private @NonNull Map<String, int[]> entityTags;

    @Override
    public void read(NetInput in) throws IOException {
        this.blockTags = new HashMap<>();
        this.itemTags = new HashMap<>();
        this.fluidTags = new HashMap<>();
        this.entityTags = new HashMap<>();
        for(Map<String, int[]> tags : Arrays.asList(this.blockTags, this.itemTags, this.fluidTags, this.entityTags)) {
            int tagsCount = in.readVarInt();
            for(int i = 0; i < tagsCount; i++) {
                String name = in.readString();
                int entriesCount = in.readVarInt();
                int[] entries = new int[entriesCount];
                for(int index = 0; index < entriesCount; index++) {
                    entries[index] = in.readVarInt();
                }

                tags.put(name, entries);
            }
        }
    }

    @Override
    public void write(NetOutput out) throws IOException {
        for(Map<String, int[]> tags : Arrays.asList(this.blockTags, this.itemTags, this.fluidTags, this.entityTags)) {
            out.writeVarInt(tags.size());
            for(Map.Entry<String, int[]> tag : tags.entrySet()) {
                out.writeString(tag.getKey());
                out.writeVarInt(tag.getValue().length);
                for(int id : tag.getValue()) {
                    out.writeVarInt(id);
                }
            }
        }
    }

    @Override
    public boolean isPriority() {
        return false;
    }
}

@@ -699,47 +699,8 @@
 ing,
- int%5B%5D%3E blockTags;%0A    private @NonNull
  Map
@@ -718,340 +718,232 @@
 t%5B%5D%3E
- itemTags;%0A    private @NonNull Map%3CString, int%5B%5D%3E fluidTags;%0A    private @NonNull Map%3CString, int%5B%5D%3E entityTags;%0A%0A    @Override%0A    public void read(NetInput in) throws IOException %7B%0A        this.blockTags = new HashMap%3C%3E();%0A        this.itemTags = new HashMap%3C%3E();%0A        this.fluidTags = new HashMap%3C%3E();%0A        this.entityT
+%3E tags = new HashMap%3C%3E();%0A%0A    @Override%0A    public void read(NetInput in) throws IOException %7B%0A        int totalTagCount = in.readVarInt();%0A        for(int i = 0; i %3C totalTagCount; i++) %7B%0A            Map%3CString, int%5B%5D%3E t
 ag
-s
  = n
@@ -970,118 +970,45 @@
     
-for(Map%3CString, int%5B%5D%3E tags : Arrays.asList(this.blockTags, this.itemTags, this.fluidTags, this.entityTags)) %7B
+    String tagName = in.readString();
 %0A   
@@ -1065,32 +1065,32 @@
     for(int 
-i
+j
  = 0; 
-i
+j
  %3C tagsCount
@@ -1087,25 +1087,25 @@
  tagsCount; 
-i
+j
 ++) %7B%0A      
@@ -1412,17 +1412,16 @@
      tag
-s
 .put(nam
@@ -1439,32 +1439,68 @@
 ;%0A            %7D%0A
+            tags.put(tagName, tag);%0A
         %7D%0A    %7D%0A
@@ -1580,20 +1580,76 @@
         
-for(
+out.writeVarInt(tags.size());%0A        for(Map.Entry%3CString, 
 Map%3CStri
@@ -1662,96 +1662,83 @@
 t%5B%5D%3E
+%3E
  tag
-s : Arrays.asList(this.blockTags, this.itemTags, this.fluidTags, this.entityTags)) %7B
+Set : tags.entrySet()) %7B%0A            out.writeString(tagSet.getKey());
 %0A   
@@ -1757,33 +1757,46 @@
 .writeVarInt(tag
-s
+Set.getValue()
 .size());%0A      
@@ -1835,25 +1835,38 @@
 %5D%3E tag : tag
-s
+Set.getValue()
 .entrySet())

Fix tags serialization