var scriptName = "PacketManipulator";
var scriptVersion = 1.1;
var scriptAuthor = "Soulplexis";

var velocity = Java.type("net.minecraft.network.play.server.S12PacketEntityVelocity");
var explode = Java.type("net.minecraft.network.play.server.S27PacketExplosion");
var potioneffect = Java.type("net.minecraft.network.play.server.S1DPacketEntityEffect");
var Potion = Java.type("net.minecraft.potion.Potion");
var PotionEffect = Java.type("net.minecraft.potion.PotionEffect");
var Discon = Java.type("net.minecraft.network.play.client.C0CPacketInput");
var PlayerPositionLook = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C06PacketPlayerPosLook');
var PlayerLook = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C05PacketPlayerLook');
var Player = Java.type('net.minecraft.network.play.client.C03PacketPlayer');
var C04PacketPlayerPosition = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition');
var EntityLiving = Java.type('net.minecraft.entity.EntityLivingBase');
var MathHelper = Java.type("net.minecraft.util.MathHelper");
var BlockPlace = Java.type("net.minecraft.network.play.client.C08PacketPlayerBlockPlacement");
var BlockPos = Java.type("net.minecraft.util.BlockPos");
var PlayerPosition = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition')

   function getYawFromPosition(x, z, y) {
        var xDiff = x - mc.thePlayer.posX;
        var zDiff = z - mc.thePlayer.posZ;
        var yDiff = y - mc.thePlayer.posY + mc.thePlayer.getEyeHeight();
        var dist = MathHelper.sqrt_double(xDiff * xDiff + zDiff * zDiff);
        var yaw = (Math.atan2(zDiff, xDiff) * 180.0 / 3.141592653589793) - 90.0;
        return yaw;
    }
	   function getPitchFromPosition(x, z, y) {
        var xDiff = x - mc.thePlayer.posX;
        var zDiff = z - mc.thePlayer.posZ;
        var yDiff = y - mc.thePlayer.posY + mc.thePlayer.getEyeHeight();
        var dist = MathHelper.sqrt_double(xDiff * xDiff + zDiff * zDiff);
        var pitch = (- Math.atan2(yDiff, dist) * 180.0 / 3.141592653589793);
        return pitch;
    }
function randomIntFrom(min,max) {
    return Math.floor(Math.random()*(max-min+1)+min);
} 
function Module() {
	var look = value.createBoolean("Look", true);
	var position = value.createBoolean("Position", false);
	var ground = value.createBoolean("ground", false);
	var sprint = value.createBoolean("sprint", false);
    this.getName = function () {
        return "PacketManipulator";
    };

    this.getDescription = function () {
        return "Manipulate packets to not be silent anymore. No more false rotations!";
    };

    this.getCategory = function () {
        return "Render";
    };    
    this.onEnable = function() {
    }
	this.onPacket = function(event) {
		var packet = event.getPacket();
		if(look.get()) {
			if(packet instanceof PlayerLook || packet instanceof PlayerPositionLook) {
			mc.thePlayer.rotationYaw = packet.getYaw();
			mc.thePlayer.rotationPitch = packet.getPitch();
			}
		}
		if(position.get()) {
			if(packet instanceof PlayerPositionLook || packet instanceof PlayerPosition) {
				mc.thePlayer.setPosition(packet.x, packet.y, packet.z);
			}
		}
		if(ground.get()) {
			if(packet instanceof Player) {
				mc.thePlayer.onGround = packet.onGround;
			}
		}
	}
    this.addValues = function(values) {
		values.add(look);
		values.add(position);
		values.add(ground);
    }
}
var Module = new Module();
var ModuleClient;

function onEnable() {
    ModuleClient = moduleManager.registerModule(Module);
};

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