ModPacketHandler.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package me.km.networking;
  2. import me.km.KajetansMod;
  3. import me.km.entities.EntityHuman;
  4. import me.km.inventory.InventoryBase;
  5. import net.minecraft.entity.player.EntityPlayerMP;
  6. import net.minecraftforge.fml.common.network.NetworkRegistry;
  7. import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
  8. import net.minecraftforge.fml.relauncher.Side;
  9. public class ModPacketHandler
  10. {
  11. public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(KajetansMod.MODID);
  12. private static int id = 0;
  13. public static void init()
  14. {
  15. INSTANCE.registerMessage(PlayerDisplay.Handler.class, PlayerDisplay.class, id++, Side.CLIENT);
  16. INSTANCE.registerMessage(FunctionKey.Handler.class, FunctionKey.class, id++, Side.SERVER);
  17. INSTANCE.registerMessage(HumanUpdate.Handler.class, HumanUpdate.class, id++, Side.CLIENT);
  18. INSTANCE.registerMessage(HumanScaleUpdate.Handler.class, HumanScaleUpdate.class, id++, Side.CLIENT);
  19. INSTANCE.registerMessage(CustomInventory.Handler.class, CustomInventory.class, id++, Side.CLIENT);
  20. INSTANCE.registerMessage(CampFireInventory.Handler.class, CampFireInventory.class, id++, Side.CLIENT);
  21. INSTANCE.registerMessage(SeasonUpdate.Handler.class, SeasonUpdate.class, id++, Side.CLIENT);
  22. INSTANCE.registerMessage(StatusDisplay.Handler.class, StatusDisplay.class, id++, Side.CLIENT);
  23. }
  24. public static void sendToDisplay(EntityPlayerMP p, byte action, byte index, String text)
  25. {
  26. INSTANCE.sendTo(new PlayerDisplay(action, index, text), p);
  27. }
  28. public static void sendFunctionKey(int key)
  29. {
  30. INSTANCE.sendToServer(new FunctionKey(key));
  31. }
  32. public static void sendHumanUpdate(EntityPlayerMP p, EntityHuman human)
  33. {
  34. INSTANCE.sendTo(new HumanUpdate(human), p);
  35. }
  36. public static void sendHumanUpdate(EntityHuman human)
  37. {
  38. HumanUpdate update = new HumanUpdate(human);
  39. KajetansMod.server.getPlayerList().getPlayers().forEach(p -> INSTANCE.sendTo(update, p));
  40. }
  41. public static void sendHumanScaleUpdate(EntityHuman human)
  42. {
  43. HumanScaleUpdate update = new HumanScaleUpdate(human);
  44. KajetansMod.server.getPlayerList().getPlayers().forEach(p -> INSTANCE.sendTo(update, p));
  45. }
  46. public static void sendCustomInventory(EntityPlayerMP p, int id, InventoryBase inv)
  47. {
  48. INSTANCE.sendTo(new CustomInventory(id, inv), p);
  49. }
  50. public static void sendCampFireInventory(EntityPlayerMP p, int id, String name)
  51. {
  52. INSTANCE.sendTo(new CampFireInventory(id, name), p);
  53. }
  54. public static void sendSeasonUpdate(EntityPlayerMP p, byte season)
  55. {
  56. INSTANCE.sendTo(new SeasonUpdate(season), p);
  57. }
  58. public static void addStatus(EntityPlayerMP p, byte index, String text)
  59. {
  60. INSTANCE.sendTo(new StatusDisplay((byte) 1, index, text), p);
  61. }
  62. public static void addTimedStatus(EntityPlayerMP p, byte index, String text, int time)
  63. {
  64. INSTANCE.sendTo(new StatusDisplay((byte) 1, index, time, text), p);
  65. }
  66. public static void removeStatus(EntityPlayerMP p, byte index)
  67. {
  68. INSTANCE.sendTo(new StatusDisplay((byte) 2, index, ""), p);
  69. }
  70. public static void clearStatus(EntityPlayerMP p)
  71. {
  72. INSTANCE.sendTo(new StatusDisplay((byte) 3, (byte) 0, ""), p);
  73. }
  74. }