package org.cyclops.integrateddynamics.core.network.packet;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.cyclops.cyclopscore.network.CodecField;
import org.cyclops.cyclopscore.network.PacketCodec;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.core.persist.world.LabelsWorldStorage;

import java.util.Map;

/**
 * Packet for notifying onLabelPacket changes.
 * @author rubensworks
 *
 */
public class AllLabelsPacket extends PacketCodec {

	@CodecField
	private Map<Integer, String> labels;

    public AllLabelsPacket() {

    }

    public AllLabelsPacket(Map<Integer, String> labels) {
        this.labels = labels;
    }

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

	@Override
	@SideOnly(Side.CLIENT)
	public void actionClient(World world, EntityPlayer player) {
        for(Map.Entry<Integer, String> entry : labels.entrySet()) {
            LabelsWorldStorage.getInstance(IntegratedDynamics._instance).putUnsafe(entry.getKey(), entry.getValue());
        }
	}

	@Override
	public void actionServer(World world, EntityPlayerMP player) {

	}
	
}
@@ -1019,24 +1019,58 @@
 r player) %7B%0A
+        if (labels != null) %7B%0A    
         for(
@@ -1068,16 +1068,17 @@
      for
+ 
 (Map.Ent
@@ -1122,24 +1122,28 @@
 trySet()) %7B%0A
+    
             
@@ -1248,16 +1248,30 @@
 lue());%0A
+            %7D%0A
         

Make rare client crash when invalid labels are received, Closes #645