HalestormXV

Untitled

Jul 13th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.87 KB | None | 0 0
  1. package halestormxv.eAngelus.network;
  2.  
  3. import halestormxv.eAngelus.network.packets.ChatUtil;
  4. import halestormxv.eAngelus.main.Reference;
  5. import halestormxv.eAngelus.network.packets.FetchMorality;
  6. import halestormxv.eAngelus.network.packets.SyncMorality;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.entity.player.EntityPlayerMP;
  9. import net.minecraft.tileentity.TileEntity;
  10. import net.minecraft.util.math.BlockPos;
  11. import net.minecraftforge.fml.common.network.NetworkRegistry;
  12. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  13. import net.minecraftforge.fml.relauncher.Side;
  14.  
  15. /**
  16.  * Created by Blaze on 7/7/2017.
  17.  */
  18. public class eAngelusPacketHandler
  19. {
  20.  
  21.     public static final ThreadedNetworkWrapper INSTANCE = new ThreadedNetworkWrapper(Reference.NAME);
  22.  
  23.     private static int ID = 0;
  24.     private static int nextID()
  25.     {
  26.         return ID++;
  27.     }
  28.  
  29.     /**
  30.      The first parameter is messageHandler, which is the class that handles your packet. This class must always have a default constructor, and should
  31.      have type bound REQ that matches the next argument. The second parameter is requestMessageType which is the actual packet class. This class must
  32.      also have a default constructor and match the REQ type bound of the previous param. The third parameter is the discriminator for the packet.
  33.      This is a per-channel unique ID for the packet. We recommend you use a static variable to hold the ID, and then call registerMessage using id++.
  34.      This will guarantee 100% unique IDs. The fourth and final parameter is the side that your packet will be received on.
  35.      If you are planning to send the packet to both sides, it must be registered twice with a different discriminator.
  36.      **/
  37.     public static void init()
  38.     {
  39.         INSTANCE.registerMessage(ChatUtil.PacketNoSpamChat.Handler.class, ChatUtil.PacketNoSpamChat.class, nextID(), Side.CLIENT);
  40.         INSTANCE.registerMessage(FetchMorality.class, FetchMorality.class, nextID(), Side.SERVER); //Key Bind Fetch Morality
  41.         INSTANCE.registerMessage(SyncMorality.Handler.class, SyncMorality.class, nextID(), Side.CLIENT);
  42.     }
  43.  
  44.     public static void sendToAllAround(IMessage message, TileEntity te, int range)
  45.     {
  46.         BlockPos p = te.getPos();
  47.         INSTANCE.sendToAllAround(message, new NetworkRegistry.TargetPoint(te.getWorld().provider.getDimension(), p.getX(), p.getY(), p.getZ(), range));
  48.     }
  49.  
  50.     public static void sendToAll(IMessage message)
  51.     {
  52.         INSTANCE.sendToAll(message);
  53.     }
  54.  
  55.     public static void sendTo(IMessage message, EntityPlayerMP player) { INSTANCE.sendTo(message, player); }
  56.  
  57.     //Only use if you plan on sending the pack to the server. Has nothing to do with the player. There is only one server.
  58.     public static void sendToServer(IMessage message)
  59.     {
  60.         INSTANCE.sendToServer(message);
  61.     }
  62. }
Add Comment
Please, Sign In to add comment