2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2017-05-13 18:20:39 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.shared.network;
|
|
|
|
|
|
|
|
import dan200.computercraft.ComputerCraft;
|
|
|
|
import net.minecraft.network.NetHandlerPlayServer;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
|
|
|
|
|
|
|
public class PacketHandler
|
|
|
|
{
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onClientPacket( FMLNetworkEvent.ClientCustomPacketEvent event )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ComputerCraftPacket packet = new ComputerCraftPacket();
|
2017-05-01 13:51:26 +00:00
|
|
|
packet.fromBytes( event.getPacket().payload() );
|
2017-05-01 13:32:39 +00:00
|
|
|
ComputerCraft.handlePacket( packet, null );
|
|
|
|
}
|
|
|
|
catch( Exception e )
|
|
|
|
{
|
2017-05-13 21:26:35 +00:00
|
|
|
ComputerCraft.log.error( "Error handling packet", e );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onServerPacket( FMLNetworkEvent.ServerCustomPacketEvent event )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ComputerCraftPacket packet = new ComputerCraftPacket();
|
2017-05-01 13:51:26 +00:00
|
|
|
packet.fromBytes( event.getPacket().payload() );
|
|
|
|
ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer)event.getHandler()).playerEntity );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
catch( Exception e )
|
|
|
|
{
|
2017-05-13 21:26:35 +00:00
|
|
|
ComputerCraft.log.error( "Error handling packet", e );
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|