ModPacketHandler.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  23. public static void sendStats(EntityPlayerMP p, byte action, byte index, String text)
  24. {
  25. INSTANCE.sendTo(new PlayerDisplay(action, index, text), p);
  26. }
  27. public static void sendFunctionKey(int key)
  28. {
  29. INSTANCE.sendToServer(new FunctionKey(key));
  30. }
  31. public static void sendHumanUpdate(EntityPlayerMP p, EntityHuman human)
  32. {
  33. INSTANCE.sendTo(new HumanUpdate(human), p);
  34. }
  35. public static void sendHumanUpdate(EntityHuman human)
  36. {
  37. HumanUpdate update = new HumanUpdate(human);
  38. KajetansMod.server.getPlayerList().getPlayers().forEach(p -> INSTANCE.sendTo(update, p));
  39. }
  40. public static void sendHumanScaleUpdate(EntityHuman human)
  41. {
  42. HumanScaleUpdate update = new HumanScaleUpdate(human);
  43. KajetansMod.server.getPlayerList().getPlayers().forEach(p -> INSTANCE.sendTo(update, p));
  44. }
  45. public static void sendCustomInventory(EntityPlayerMP p, int id, InventoryBase inv)
  46. {
  47. INSTANCE.sendTo(new CustomInventory(id, inv), p);
  48. }
  49. public static void sendCampFireInventory(EntityPlayerMP p, int id, String name)
  50. {
  51. INSTANCE.sendTo(new CampFireInventory(id, name), p);
  52. }
  53. public static void sendSeasonUpdate(EntityPlayerMP p, byte season)
  54. {
  55. INSTANCE.sendTo(new SeasonUpdate(season), p);
  56. }
  57. }