Advertisement
HalestormXV

Untitled

Mar 19th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 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.  
  6. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  7. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  8. import io.netty.buffer.ByteBuf;
  9. import net.minecraft.entity.player.EntityPlayer;
  10.  
  11. public class OpenGuiPacketAlt implements IMessage {
  12. // this will store the id of the gui to open
  13. private int id;
  14.  
  15. // The basic, no-argument constructor MUST be included to use the new automated handling
  16. public OpenGuiPacketAlt() {}
  17.  
  18. // if there are any class fields, be sure to provide a constructor that allows
  19. // for them to be initialized, and use that constructor when sending the packet
  20. public OpenGuiPacketAlt(int id) {
  21. this.id = id;
  22. }
  23.  
  24. @Override
  25. public void fromBytes(ByteBuf buffer) {
  26. // basic Input/Output operations, very much like DataInputStream
  27. id = buffer.readInt();
  28. }
  29.  
  30. @Override
  31. public void toBytes(ByteBuf buffer) {
  32. // basic Input/Output operations, very much like DataOutputStream
  33. buffer.writeInt(id);
  34. }
  35.  
  36. public static class Handler extends AbstractServerMessageHandler<OpenGuiPacketAlt> {
  37. @Override
  38. public IMessage handleServerMessage(EntityPlayer player, OpenGuiPacketAlt message,
  39. MessageContext ctx) {
  40. // because we sent the gui's id with the packet, we can handle all cases with one line:
  41. System.out.println("Congratulations you finally created a frigen packet that works!");
  42. player.openGui(MainRegistry.modInstance, message.id, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
  43. return null;
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement