Advertisement
Guest User

Untitled

a guest
May 26th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package fr.plaigon.plaig4sounds.common.packet;
  2.  
  3. import io.netty.buffer.ByteBuf;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.entity.player.EntityPlayerMP;
  6. import cpw.mods.fml.common.network.ByteBufUtils;
  7. import cpw.mods.fml.common.network.simpleimpl.IMessage;
  8. import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
  9. import cpw.mods.fml.common.network.simpleimpl.MessageContext;
  10. import cpw.mods.fml.relauncher.Side;
  11. import cpw.mods.fml.relauncher.SideOnly;
  12.  
  13. public class PacketPLS implements IMessage
  14. {
  15. private String fileName;
  16.  
  17. public PacketPLS()
  18. {
  19. }
  20.  
  21. public PacketPLS(String fileName)
  22. {
  23. this.fileName = fileName;
  24. }
  25.  
  26. @Override
  27. public void fromBytes(ByteBuf buf)
  28. {
  29. // this.fileName = ByteBufUtils.readUTF8String(buf);
  30. System.out.println(ByteBufUtils.readUTF8String(buf));
  31. }
  32.  
  33. @Override
  34. public void toBytes(ByteBuf buf)
  35. {
  36. ByteBufUtils.writeUTF8String(buf, fileName);
  37. }
  38.  
  39. public static class Handler implements IMessageHandler<PacketPLS, IMessage>
  40. {
  41. @SideOnly(Side.CLIENT)
  42. @Override
  43. public IMessage onMessage(PacketPLS message, MessageContext ctx)
  44. {
  45. System.out.println("string: " + message.fileName);
  46. Minecraft.getMinecraft().thePlayer.sendChatMessage("well received on client side, with string: " + message.fileName);//The string is null in game
  47. return null;
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement