SHARE
TWEET

Extended_Jamiga

a guest Apr 12th, 2014 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package aJamigaPack1;
  2.  
  3. import java.io.ByteArrayInputStream;
  4. import java.io.DataInputStream;
  5. import java.io.IOException;
  6.  
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.network.INetworkManager;
  9. import net.minecraft.network.packet.Packet250CustomPayload;
  10. import cpw.mods.fml.common.FMLCommonHandler;
  11. import cpw.mods.fml.common.network.IPacketHandler;
  12. import cpw.mods.fml.common.network.Player;
  13.  
  14. public class PacketHandler implements IPacketHandler {
  15.         public static final byte EXTENDED_PROPERTIES = 1, OPEN_SERVER_GUI = 2;
  16.         @Override
  17.         public void onPacketData(INetworkManager manager,
  18.                         Packet250CustomPayload packet, Player player) {
  19.                
  20.                 if (packet.channel.equals("GenericRandom")) {
  21.                         handleRandom(packet);
  22.                 }
  23.         }
  24.        
  25.         private void handleRandom(Packet250CustomPayload packet) {
  26.                 DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
  27.                 byte packetType;
  28.  
  29.                 try {
  30.                 // Read the packet type
  31.                 packetType = inputStream.readByte();
  32.                 } catch (IOException e) {
  33.                 e.printStackTrace();
  34.                 return;
  35.                 }
  36.  
  37.                 // Now we check which channel, in case you have more than one registered
  38.                 if (packet.channel.equals("tutchannel"))
  39.                 {
  40.                 // Handle each case appropriately:
  41.                 switch(packetType) {
  42.                 default: System.out.println("[PACKET][WARNING] Unknown packet type " + packetType);
  43.                 }
  44.                 }
  45.         }
  46.  
  47.         private void handleOpenServerGui(Packet250CustomPayload packet, EntityPlayer player, DataInputStream inputStream)
  48.         {
  49.         int guiID;
  50.         // inputStream is already open, so we don't need to do anything other than continue reading from it:
  51.         try {
  52.         guiID = inputStream.readInt();
  53.         } catch (IOException e) {
  54.         e.printStackTrace();
  55.         return;
  56.         }
  57.         // Now we can open the server gui element:
  58.         player.openGui(mod_Armor_main.instance, guiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
  59.         }
  60.        
  61.        
  62.  
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top