Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package com.github.wolfiewaffle.solesurvivor.network;
  2.  
  3. import com.github.wolfiewaffle.solesurvivor.capability.ITemperature;
  4.  
  5. import io.netty.buffer.ByteBuf;
  6. import net.minecraftforge.common.capabilities.Capability;
  7. import net.minecraftforge.common.capabilities.CapabilityInject;
  8. import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
  9. import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
  10. import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
  11.  
  12. public class SoleSurvivorTempMessage implements IMessage {
  13.  
  14.     @CapabilityInject(value = ITemperature.class)
  15.     public static Capability<ITemperature> TEMPERATURE = null;
  16.  
  17. //  public SoleSurvivorTempMessage(double temperature) {
  18. //      this(temperature, 0);
  19. //  }
  20.  
  21.     public SoleSurvivorTempMessage(double temperature, double targetTemperature) {
  22.         this.temperature = temperature;
  23.         this.targetTemperature = targetTemperature;
  24.     }
  25.  
  26.     private double temperature;
  27.     private double targetTemperature;
  28.  
  29.     public double getTemperature() {
  30.         return temperature;
  31.     }
  32.  
  33.     public void setTemperature(int newTemp) {
  34.         temperature = newTemp;
  35.     }
  36.  
  37.     public double getTargetTemperature() {
  38.         return targetTemperature;
  39.     }
  40.  
  41.     public void setTargetTemperature(int newTemp) {
  42.         targetTemperature = newTemp;
  43.     }
  44.  
  45.     @Override
  46.     public void toBytes(ByteBuf buf) {
  47.         // Writes the int into the buf
  48.         buf.writeDouble(temperature);
  49.         buf.writeDouble(targetTemperature);
  50.     }
  51.  
  52.     @Override
  53.     public void fromBytes(ByteBuf buf) {
  54.         // Reads the int back from the buf. Note that if you have multiple
  55.         // values, you must read in the same order you wrote.
  56.         temperature = buf.readDouble();
  57.         targetTemperature = buf.readDouble();
  58.     }
  59.  
  60.     // The params of the IMessageHandler are <REQ, REPLY>
  61.     // This means that the first param is the packet you are receiving, and the
  62.     // second is the packet you are returning.
  63.     // The returned packet can be used as a "response" from a sent packet.
  64.     public static class Handler implements IMessageHandler<SoleSurvivorTempMessage, IMessage> {
  65.         // Do note that the default constructor is required, but implicitly
  66.         // defined in this case
  67.        
  68.         @Override
  69.         public IMessage onMessage(SoleSurvivorTempMessage message, MessageContext ctx) {
  70.             ClientPacketHandlers.handleSoleSurvivor(message, ctx);
  71.  
  72.             return null;
  73.         }
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement