package com.pg85.otg.forge.network;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Supplier;

import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;

public class PacketSyncBiomeSettings implements OTGLoginMessage
{
	private Map<String, BiomeSettingSyncWrapper> syncMap = new HashMap<>();
	private int loginIndex;

	private PacketSyncBiomeSettings()
	{
	}

	public PacketSyncBiomeSettings(Map<String, BiomeSettingSyncWrapper> syncMap)
	{
		this.syncMap = syncMap;
	}

	public static void encode(PacketSyncBiomeSettings packet, PacketBuffer buffer)
	{
		buffer.writeInt(packet.syncMap.size());
		for (Entry<String, BiomeSettingSyncWrapper> entry : packet.syncMap.entrySet())
		{
			buffer.writeUtf(entry.getKey());
			entry.getValue().encode(buffer);
		}
	}

	public static PacketSyncBiomeSettings decode(PacketBuffer buffer)
	{
		PacketSyncBiomeSettings packet = new PacketSyncBiomeSettings();
		int size = buffer.readInt();
		for (int i = size; i > 0; i--)
		{
			String key = buffer.readUtf();
			System.out.println(key);
			BiomeSettingSyncWrapper wrapper = new BiomeSettingSyncWrapper(buffer);

			packet.syncMap.putIfAbsent(key, wrapper);
		}
		return packet;
	}

	public static void handleLogin(PacketSyncBiomeSettings packet, Supplier<NetworkEvent.Context> context)
	{
		context.get().enqueueWork(() -> OTGClientSyncManager.getSyncedData().putAll(packet.syncMap));

		// We need to send something as a reply, or the client will hang on login
		// forever.
		OTGClientSyncManager.LOGIN.reply(new AcknowledgeOTGMessage(), context.get());
		context.get().setPacketHandled(true);
	}

	@Override
	public int getLoginIndex()
	{
		return loginIndex;
	}

	@Override
	public void setLoginIndex(int loginIndex)
	{
		this.loginIndex = loginIndex;
	}

}

@@ -143,16 +143,55 @@
 plier;%0A%0A
+import net.minecraft.client.Minecraft;%0A
 import n
@@ -1128,36 +1128,8 @@
 ();%0A
-%09%09%09System.out.println(key);%0A
 %09%09%09B
@@ -1683,16 +1683,73 @@
 (true);%0A
+%09%09%0A%09%09Minecraft.getInstance().levelRenderer.allChanged();%0A
 %09%7D%0A%0A%09@Ov

Remove more dbug printouts Refresh chunks after packet is recieved