Applied-Energistics-2-tiler.../src/main/java/appeng/core/sync/network/AppEngClientPacketHandler.java

82 lines
2.4 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-02-09 02:34:52 +01:00
package appeng.core.sync.network;
2015-06-16 02:44:59 +02:00
import java.lang.reflect.InvocationTargetException;
2015-12-24 02:07:03 +01:00
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
2014-02-09 02:34:52 +01:00
import net.minecraft.entity.player.EntityPlayer;
2015-06-16 02:44:59 +02:00
import net.minecraft.network.INetHandler;
import net.minecraft.network.PacketThreadUtil;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
2015-12-24 02:07:03 +01:00
2014-02-09 02:34:52 +01:00
import appeng.core.AELog;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.AppEngPacketHandlerBase;
2015-06-16 02:44:59 +02:00
import appeng.core.sync.PacketCallState;
2014-02-09 02:34:52 +01:00
2014-02-09 02:34:52 +01:00
public class AppEngClientPacketHandler extends AppEngPacketHandlerBase implements IPacketHandler
{
@Override
public void onPacketData( final INetworkInfo manager, final INetHandler handler, final FMLProxyPacket packet, final EntityPlayer player )
2014-02-09 02:34:52 +01:00
{
2015-09-30 14:24:40 +02:00
final ByteBuf stream = packet.payload();
2014-02-09 02:34:52 +01:00
try
{
2015-09-30 14:24:40 +02:00
final int packetType = stream.readInt();
final AppEngPacket pack = PacketTypes.getPacket( packetType ).parsePacket( stream );
2015-06-16 02:44:59 +02:00
final PacketCallState callState = new PacketCallState(){
2015-12-24 02:03:16 +01:00
@Override
public void call( final AppEngPacket appEngPacket )
{
appEngPacket.clientPacketData( manager, appEngPacket, Minecraft.getMinecraft().thePlayer );
}
};
2015-12-24 02:03:16 +01:00
pack.setCallParam( callState );
2015-06-16 02:44:59 +02:00
PacketThreadUtil.checkThreadAndEnqueue( pack, handler, Minecraft.getMinecraft() );
callState.call( pack );
2014-02-09 02:34:52 +01:00
}
2015-09-30 14:24:40 +02:00
catch( final InstantiationException e )
2014-02-09 02:34:52 +01:00
{
AELog.debug( e );
2014-02-09 02:34:52 +01:00
}
2015-09-30 14:24:40 +02:00
catch( final IllegalAccessException e )
2014-02-09 02:34:52 +01:00
{
AELog.debug( e );
2014-02-09 02:34:52 +01:00
}
2015-09-30 14:24:40 +02:00
catch( final IllegalArgumentException e )
2014-02-09 02:34:52 +01:00
{
AELog.debug( e );
2014-02-09 02:34:52 +01:00
}
2015-09-30 14:24:40 +02:00
catch( final InvocationTargetException e )
2014-02-09 02:34:52 +01:00
{
AELog.debug( e );
2014-02-09 02:34:52 +01:00
}
}
}