Advertisement
HalestormXV

PacketFinal

Mar 21st, 2016
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.halestormxv.Main.handler.network.packets;
  2.  
  3. import com.halestormxv.Main.MainRegistry;
  4. import com.halestormxv.Main.handler.network.AbstractServerMessageHandler;
  5. import com.halestormxv.item.CelestialCraft_items;
  6.  
  7. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  8. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  9. import io.netty.buffer.ByteBuf;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.inventory.IInventory;
  12. import net.minecraft.item.ItemStack;
  13.  
  14. public class OpenGuiPacketAlt implements IMessage {
  15.     // this will store the id of the gui to open
  16.     private int id;
  17.  
  18.     // The basic, no-argument constructor MUST be included to use the new automated handling
  19.     public OpenGuiPacketAlt() {}
  20.  
  21.     // if there are any class fields, be sure to provide a constructor that allows
  22.     // for them to be initialized, and use that constructor when sending the packet
  23.     public OpenGuiPacketAlt(int id) {
  24.         this.id = id;
  25.     }
  26.  
  27.     @Override
  28.     public void fromBytes(ByteBuf buffer) {
  29.         // basic Input/Output operations, very much like DataInputStream
  30.         id = buffer.readInt();
  31.     }
  32.  
  33.     @Override
  34.     public void toBytes(ByteBuf buffer) {
  35.         // basic Input/Output operations, very much like DataOutputStream
  36.         buffer.writeInt(id);
  37.     }
  38.  
  39.     public static class Handler extends AbstractServerMessageHandler<OpenGuiPacketAlt>
  40.     {
  41.         @Override
  42.         public IMessage handleServerMessage(EntityPlayer player, OpenGuiPacketAlt message, MessageContext ctx)
  43.         {
  44.             for (int i = 0; i < player.inventory.getSizeInventory(); i++)
  45.             {
  46.                 if (player.inventory.getStackInSlot(i) != null)
  47.                 {
  48.                     if (player.inventory.getStackInSlot(i).getItem() == CelestialCraft_items.keyPouch &&  i != player.inventory.currentItem)
  49.                     {
  50.                         System.out.println("Congratulations you finally created a frigen packet that works!");
  51.                         player.openGui(MainRegistry.modInstance, message.id, player.worldObj, i, 0, 0);
  52.                     }
  53.                     if (player.inventory.getStackInSlot(i).getItem() == CelestialCraft_items.keyPouch &&  i == player.inventory.currentItem)
  54.                     {
  55.                         System.out.println("Congratulations you finally created a frigen packet that works!");
  56.                         player.openGui(MainRegistry.modInstance, message.id, player.worldObj, player.inventory.currentItem, 0, 0);
  57.                     }
  58.                 }
  59.             }
  60.             return null;
  61.         }
  62.     }
  63. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement