package com.missingeye.pixelpainter.client.handlers;

import com.missingeye.pixelpainter.events.network.NetworkPacketEvent;
import com.missingeye.pixelpainter.network.CarrierPacket;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Created by Samuel Agius (Belpois) on 1/15/2015.
 */
public class ClientPacketHandler implements IMessageHandler<CarrierPacket, IMessage>
{
	private static final Logger logger = LogManager.getLogger();

	@Override
	public IMessage onMessage(CarrierPacket carrierPacket, MessageContext messageContext)
	{
		NetworkPacketEvent networkPacketEvent = (NetworkPacketEvent) carrierPacket.getPayload();
		networkPacketEvent.setEntityPlayer(FMLClientHandler.instance().getClient().thePlayer);

		FMLCommonHandler.instance().bus().post(networkPacketEvent);

		return null;
	}
}
