Advertisement
HalestormXV

Untitled

Mar 20th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  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.  
  13. public class OpenGuiPacketAlt implements IMessage {
  14.     // this will store the id of the gui to open
  15.     private int id;
  16.  
  17.     // The basic, no-argument constructor MUST be included to use the new automated handling
  18.     public OpenGuiPacketAlt() {}
  19.  
  20.     // if there are any class fields, be sure to provide a constructor that allows
  21.     // for them to be initialized, and use that constructor when sending the packet
  22.     public OpenGuiPacketAlt(int id) {
  23.         this.id = id;
  24.     }
  25.  
  26.     @Override
  27.     public void fromBytes(ByteBuf buffer) {
  28.         // basic Input/Output operations, very much like DataInputStream
  29.         id = buffer.readInt();
  30.     }
  31.  
  32.     @Override
  33.     public void toBytes(ByteBuf buffer) {
  34.         // basic Input/Output operations, very much like DataOutputStream
  35.         buffer.writeInt(id);
  36.     }
  37.  
  38.     public static class Handler extends AbstractServerMessageHandler<OpenGuiPacketAlt>
  39.     {
  40.         @Override
  41.         public IMessage handleServerMessage(EntityPlayer player, OpenGuiPacketAlt message, MessageContext ctx)
  42.         {
  43.             for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++)
  44.             {
  45.                 if (player.inventory.getStackInSlot(slot) != null)
  46.                 {
  47.                     if (player.inventory.getStackInSlot(slot).getItem() == CelestialCraft_items.keyPouch)
  48.                     {
  49.                         System.out.println("Congratulations you finally created a frigen packet that works!");
  50.                         player.openGui(MainRegistry.modInstance, message.id, player.worldObj, slot, 0, 0);
  51.                     }
  52.                 }
  53.             }
  54.             return null;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement