Advertisement
HalestormXV

Untitled

Jul 13th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 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.entity.player.EntityPlayerMP;
  7. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  8. import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
  9. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  10. import net.minecraftforge.fml.relauncher.Side;
  11. import net.minecraftforge.fml.relauncher.SideOnly;
  12.  
  13. /**
  14.  * Created by Blaze on 7/13/2017.
  15.  */
  16. public class SyncMorality implements IMessage
  17. {
  18.     private int moralityValue;
  19.  
  20.     public SyncMorality(){ }
  21.  
  22.     public SyncMorality(int moralityValue)
  23.     {
  24.         this.moralityValue = moralityValue;
  25.     }
  26.  
  27.     @Override
  28.     public void fromBytes(ByteBuf buf)
  29.     {
  30.         this.moralityValue = buf.readInt();
  31.     }
  32.  
  33.     @Override
  34.     public void toBytes(ByteBuf buf)
  35.     {
  36.         buf.writeInt(moralityValue);
  37.     }
  38.  
  39.     public static class Handler implements IMessageHandler<SyncMorality, IMessage>
  40.     {
  41.         @Override
  42.         public IMessage onMessage(SyncMorality message, MessageContext ctx) {
  43.             EntityPlayerMP player = ctx.getServerHandler().playerEntity;
  44.             player.mcServer.addScheduledTask(() ->
  45.             {
  46.                 IMorality morality = player.getCapability(moralityProvider.MORALITY_CAP, null);
  47.                 morality.set(message.moralityValue);
  48.                 System.out.println("The morality has been synced to: "+message.moralityValue);
  49.             });
  50.             return null;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement