var scriptName = "Relative Rotation"; 
var scriptVersion = 1.0; 
var scriptAuthor = "soulplexis";

var playerRotation = new PlayerRotation();
var playerRotationClient;
var lookpacket = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C05PacketPlayerLook');


function PlayerRotation() {
  var YawAmount = value.createInteger("YawAmount", 0, 0, 360);
  var PitchAmount = value.createInteger("PitchAmount", 0, -90, 90);
  var Yaw = value.createBoolean("Yaw", true);
  var Pitch = value.createBoolean("Pitch", true);
  var Silent = value.createBoolean("Silent", false);
  var Spin = value.createBoolean("Spin", false);
    this.getName = function() {
        return "RelativeRotation";
    };

    this.getDescription = function() {
        return "Forces a relative rotation.";
    };

    this.getCategory = function() {
        return "Fun";
    };
  var spinn = 0;
    this.onMotion = function () { // i threw up while making this 
    if(Spin.get() == false && Silent.get() == true && Yaw.get() == true && Pitch.get() == false) {
      mc.thePlayer.sendQueue.addToSendQueue(new lookpacket(mc.thePlayer.rotationYaw + YawAmount.get(), mc.thePlayer.rotationPitch, mc.thePlayer.onGround));
    }
    if(Spin.get() == false && Silent.get() == true && Yaw.get() == false && Pitch.get() == true) {
      mc.thePlayer.sendQueue.addToSendQueue(new lookpacket(mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch + PitchAmount.get(), mc.thePlayer.onGround));
    }
    if(Spin.get() == false && Silent.get() == true && Yaw.get() == true && Pitch.get() == true) {
      mc.thePlayer.sendQueue.addToSendQueue(new lookpacket(mc.thePlayer.rotationYaw + YawAmount.get(), mc.thePlayer.rotationPitch + PitchAmount.get(), mc.thePlayer.onGround));
    }
    if(Spin.get() == false && Silent.get() == false && Yaw.get() == true && Pitch.get() == true) {
      mc.thePlayer.rotationYaw += YawAmount.get();
      mc.thePlayer.rotationPitch += PitchAmount.get();
    }
    if(Spin.get() == false && Silent.get() == false && Yaw.get() == true && Pitch.get() == false) {
      mc.thePlayer.rotationYaw += YawAmount.get();
      // no pitch
    }
    if(Spin.get() == false && Silent.get() == false && Yaw.get() == false && Pitch.get() == true) {
      // no yaw 
      mc.thePlayer.rotationPitch += PitchAmount.get();
    }
    
    //spinn part
    if(Spin.get() == true && Silent.get() == true) {
      spinn += YawAmount.get() / 10;
      mc.thePlayer.sendQueue.addToSendQueue(new lookpacket(mc.thePlayer.rotationYaw + spinn, mc.thePlayer.rotationPitch, mc.thePlayer.onGround));
    }
      if(Spin.get() == true && Silent.get() == false) {
      mc.thePlayer.rotationYaw += YawAmount.get();
      spinn = 0;
    }
    
  }
  this.onDisable = function() {
    spinn = 0;
  }
  this.addValues = function(values) {
    values.add(Silent);
    values.add(Yaw);
    values.add(YawAmount);
    values.add(Pitch);
    values.add(PitchAmount);
    values.add(Spin);
    }
}

function onLoad() {
};

function onEnable() {
    playerRotationClient = moduleManager.registerModule(playerRotation);
};

function onDisable() {
    moduleManager.unregisterModule(playerRotationClient);
};