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

151 lines
4.5 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>.
*/
package appeng.core.sync;
2014-02-09 02:34:52 +01:00
import io.netty.buffer.ByteBuf;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
2014-07-07 04:04:58 +02:00
import appeng.core.sync.packets.PacketAssemblerAnimation;
import appeng.core.sync.packets.PacketClick;
import appeng.core.sync.packets.PacketCompassRequest;
import appeng.core.sync.packets.PacketCompassResponse;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketCraftRequest;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.sync.packets.PacketLightning;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketMatterCannon;
import appeng.core.sync.packets.PacketMockExplosion;
import appeng.core.sync.packets.PacketMultiPart;
import appeng.core.sync.packets.PacketNEIRecipe;
import appeng.core.sync.packets.PacketNewStorageDimension;
import appeng.core.sync.packets.PacketPaintedEntity;
import appeng.core.sync.packets.PacketPartPlacement;
import appeng.core.sync.packets.PacketPartialItem;
2014-04-17 06:38:43 +02:00
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.core.sync.packets.PacketProgressBar;
import appeng.core.sync.packets.PacketSwapSlots;
2014-01-26 07:44:50 +01:00
import appeng.core.sync.packets.PacketSwitchGuis;
2014-02-14 05:27:15 +01:00
import appeng.core.sync.packets.PacketTransitionEffect;
import appeng.core.sync.packets.PacketValueConfig;
public class AppEngPacketHandlerBase
{
public static final Map<Class, PacketTypes> reverseLookup = new HashMap<Class, AppEngPacketHandlerBase.PacketTypes>();
public enum PacketTypes
{
PACKET_COMPASS_REQUEST(PacketCompassRequest.class),
PACKET_COMPASS_RESPONSE(PacketCompassResponse.class),
PACKET_INVENTORY_ACTION(PacketInventoryAction.class),
PACKET_ME_INVENTORY_UPDATE(PacketMEInventoryUpdate.class),
PACKET_CONFIG_BUTTON(PacketConfigButton.class),
PACKET_MULTIPART(PacketMultiPart.class),
PACKET_PART_PLACEMENT(PacketPartPlacement.class),
PACKET_LIGHTNING(PacketLightning.class),
PACKET_MATTER_CANNON(PacketMatterCannon.class),
PACKET_MOCK_EXPLOSION(PacketMockExplosion.class),
2014-01-26 07:44:50 +01:00
PACKET_VALUE_CONFIG(PacketValueConfig.class),
2014-02-14 05:27:15 +01:00
PACKET_TRANSITION_EFFECT(PacketTransitionEffect.class),
PACKET_PROGRESS_VALUE(PacketProgressBar.class),
PACKET_CLICK(PacketClick.class),
PACKET_NEW_STORAGE_DIMENSION(PacketNewStorageDimension.class),
PACKET_SWITCH_GUIS(PacketSwitchGuis.class),
2014-04-17 06:38:43 +02:00
PACKET_SWAP_SLOTS(PacketSwapSlots.class),
PACKET_PATTERN_SLOT(PacketPatternSlot.class),
PACKET_RECIPE_NEI(PacketNEIRecipe.class),
PACKET_PARTIAL_ITEM(PacketPartialItem.class),
2014-07-07 04:04:58 +02:00
PACKET_CRAFTING_REQUEST(PacketCraftRequest.class),
PACKET_ASSEMBLER_ANIMATION(PacketAssemblerAnimation.class),
PACKET_COMPRESSED_NBT(PacketCompressedNBT.class),
PACKET_PAINTED_ENTITY(PacketPaintedEntity.class);
final public Class pc;
final public Constructor con;
private PacketTypes(Class c) {
2014-12-29 15:13:47 +01:00
this.pc = c;
Constructor x = null;
try
{
2014-12-29 15:13:47 +01:00
x = this.pc.getConstructor( ByteBuf.class );
}
catch (NoSuchMethodException ignored)
{
}
catch (SecurityException ignored)
{
}
2014-12-29 15:13:47 +01:00
this.con = x;
AppEngPacketHandlerBase.reverseLookup.put( this.pc, this );
2014-12-29 15:13:47 +01:00
if ( this.con == null )
throw new RuntimeException( "Invalid Packet Class, must be constructable on DataInputStream" );
}
2014-02-09 02:34:52 +01:00
public AppEngPacket parsePacket(ByteBuf in) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
2014-12-29 15:13:47 +01:00
return (AppEngPacket) this.con.newInstance( in );
}
public static PacketTypes getPacket(int id)
{
return (values())[id];
}
public static PacketTypes getID(Class<? extends AppEngPacket> c)
{
return AppEngPacketHandlerBase.reverseLookup.get( c );
}
2014-09-28 00:50:06 +02:00
}
}