package tv.mapper.roadstuff.network;

import java.util.function.Supplier;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;
import tv.mapper.roadstuff.item.ItemBrush;

public class BrushPacket
{
    private int pattern;
    private int paint;

    public BrushPacket(int pattern, int paint)
    {
        this.pattern = pattern;
        this.paint = paint;
    }

    public static void encode(BrushPacket packet, PacketBuffer buffer)
    {
        buffer.writeInt(packet.pattern);
        buffer.writeInt(packet.paint);
    }
    
    public static BrushPacket decode(PacketBuffer buffer)
    {
        int pattern = buffer.readInt();
        int paint = buffer.readInt();
        BrushPacket instance = new BrushPacket(pattern, paint);
        return instance;
    }
    
    public static void handle(BrushPacket packet, Supplier<NetworkEvent.Context> context)
    {
        context.get().setPacketHandled(true);
        EntityPlayerMP sender = context.get().getSender();
        ItemStack item = sender.getHeldItemMainhand();
        
        if(item.getItem() instanceof ItemBrush)
            sender.getHeldItemMainhand().getTag().setInt("pattern", packet.pattern);
    }
}

@@ -123,45 +123,8 @@
 MP;%0A
-import net.minecraft.item.ItemStack;%0A
 impo
@@ -162,16 +162,16 @@
 Buffer;%0A
+
 import n
@@ -609,37 +609,33 @@
 t.paint);%0A    %7D%0A
-    
 %0A
+
     public stati
@@ -855,21 +855,17 @@
 ;%0A    %7D%0A
-    
 %0A
+
     publ
@@ -1057,24 +1057,25 @@
 nder();%0A
+%0A
         
 ItemStac
@@ -1070,79 +1070,200 @@
     
-ItemStack item = sender.getHeldItemMainhand();%0A        %0A        if(item
+if(sender.getHeldItemMainhand().getItem() instanceof ItemBrush)%0A            sender.getHeldItemMainhand().getTag().setInt(%22pattern%22, packet.pattern);%0A        else if(sender.getHeldItemOffhand()
 .get
@@ -1313,36 +1313,35 @@
 nder.getHeldItem
-Main
+Off
 hand().getTag().

Fix brush settings not saved with offhand.