Advertisement
HalestormXV

Untitled

Jul 13th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.45 KB | None | 0 0
  1. package halestormxv.eAngelus.network.packets;
  2.  
  3. import halestormxv.eAngelus.capabilities.Interfaces.IMorality;
  4. import halestormxv.eAngelus.capabilities.MoralityCapability.moralityProvider;
  5. import io.netty.buffer.ByteBuf;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.entity.player.EntityPlayerMP;
  9. import net.minecraft.util.IThreadListener;
  10. import net.minecraft.world.World;
  11. import net.minecraftforge.fml.common.FMLCommonHandler;
  12. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  13. import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
  14. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  15. import net.minecraftforge.fml.relauncher.Side;
  16. import net.minecraftforge.fml.relauncher.SideOnly;
  17.  
  18. /**
  19.  * Created by Blaze on 7/13/2017.
  20.  */
  21. public class SyncMorality implements IMessage
  22. {
  23.     private int moralityValue;
  24.  
  25.     public SyncMorality(){ }
  26.  
  27.     public SyncMorality(int moralityValue)
  28.     {
  29.         this.moralityValue = moralityValue;
  30.     }
  31.  
  32.     @Override
  33.     public void fromBytes(ByteBuf buf)
  34.     {
  35.         this.moralityValue = buf.readInt();
  36.     }
  37.  
  38.     @Override
  39.     public void toBytes(ByteBuf buf)
  40.     {
  41.         buf.writeInt(moralityValue);
  42.     }
  43.  
  44.     public static class Handler implements IMessageHandler<SyncMorality, IMessage>
  45.     {
  46.         @Override
  47.         public IMessage onMessage(SyncMorality message, MessageContext ctx)
  48.         {
  49.             Minecraft.getMinecraft().addScheduledTask(new Runnable()
  50.             {
  51.                 @Override
  52.                 public void run()
  53.                 {
  54.                     Minecraft mc = Minecraft.getMinecraft();
  55.                     World world = mc.world;
  56.                     EntityPlayer player = Minecraft.getMinecraft().player;
  57.                     IMorality morality = player.getCapability(moralityProvider.MORALITY_CAP, null);
  58.                     morality.set(message.moralityValue);
  59.                     System.out.println("The morality has been synced to: " + message.moralityValue);
  60.                 }
  61.             });
  62.  
  63.             return null;
  64.         }
  65.     }
  66. }
  67.  
  68. //=======================================================================================\\
  69. /**THIS IS HOW YOU USE RUNNABLE
  70.  * Using Runnable
  71.  if (ctx.side == Side.SERVER) {
  72.  return null;
  73.  }else {
  74.  
  75.  IThreadListener mainThread = Minecraft.getMinecraft();
  76.  mainThread.addScheduledTask(new Runnable() {
  77. @Override
  78. public void run() {
  79. IMorality morality = Minecraft.getMinecraft().player.getCapability(moralityProvider.MORALITY_CAP, null);
  80. morality.set(message.moralityValue);
  81. System.out.println("The morality has been synced to: " + message.moralityValue);
  82. }
  83. });
  84.  }
  85.  return null;**/
  86. //=======================================================================================\\
  87. /**THIS IS HOW YOU USE LAMBADA
  88.  *     public static class Handler implements IMessageHandler<SyncMorality, IMessage>
  89.  {
  90.  @Override
  91.  public IMessage onMessage(SyncMorality message, MessageContext ctx) {
  92.  EntityPlayerMP player = ctx.getServerHandler().playerEntity;
  93.  player.mcServer.addScheduledTask(() ->
  94.  {
  95.  IMorality morality = player.getCapability(moralityProvider.MORALITY_CAP, null);
  96.  morality.set(message.moralityValue);
  97.  System.out.println("The morality has been synced to: "+message.moralityValue);
  98.  });
  99.  return null;
  100.  }
  101.  }
  102.  */
  103. //=======================================================================================\\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement