var scriptName = "KillAura Testing Module"; 
var scriptVersion = 2.0; 
var scriptAuthor = "§lSoulplexis";

var Aura = new Aura();
var AuraClient;
// The workshop
function randomIntFrom(min,max) {
    return Math.floor(Math.random()*(max-min+1)+min);
} 
var PlayerPositionLook = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C06PacketPlayerPosLook');
var PlayerLook = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C05PacketPlayerLook');
var PlayerPosition = Java.type('net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition')
var PlayerPacket = Java.type('net.minecraft.network.play.client.C03PacketPlayer');
var EntityLiving = Java.type('net.minecraft.entity.EntityLivingBase');
var Swords = Java.type('net.minecraft.item.ItemSword');
var BlockPos = Java.type('net.minecraft.util.BlockPos');
var C07PacketPlayerDigging = Java.type('net.minecraft.network.play.client.C07PacketPlayerDigging');
var EnumFacing = Java.type('net.minecraft.util.EnumFacing');
var Fooditems = Java.type('net.minecraft.item.ItemFood');
var Interactpacket = Java.type('net.minecraft.network.play.client.C02PacketUseEntity');
function Aura() {
	var Mode = value.createList("Mode", ["Single", "Switch", "Multi"], "Single"); //need work
	var Delay = value.createInteger("APS", 12, 0, 20);
	var Range = value.createFloat("Range", 4.25, 0, 6.00);
	var AutoBlock = value.createBoolean("AutoBlock", false);
	var BlockMode = value.createList("AutoBlockMode", ["Normal", "Vanilla"], "Normal"); 
	var BlockRange = value.createFloat("AutoBlockRange", 8, 0, 12.00);
	var InteractAutoBlock = value.createBoolean("InteractAutoBlock", false);
	var KeepSprint = value.createBoolean("KeepSprint", true);
	var Aim = value.createBoolean("Aim", false);
	var AimMode = value.createList("AimMode", ["Normal", "LockView"], "Normal");
	var ThroughWalls = value.createBoolean("ThroughWalls", true);
	var NoEatHit = value.createBoolean("NoEatHit", false);
	var Criticals = value.createBoolean("Criticals", false);
	var Correct = value.createBoolean("Correct", false);
	var Crasher = value.createBoolean("Crasher", false);
    this.getName = function() {
        return "Aura";
    };

    this.getDescription = function() {
        return "Attacks enemies around the player.";
    };
    this.getCategory = function() {
        return "Combat";
	};
	var delay = 0;
	var f = 0;
	var cancelz = false;
	var d = 0;
	var e = 0;
	var validTarget = false;
	this.KillAuraz = function() {
		d++;
		delay += 1; 
		var listz = mc.theWorld.loadedEntityList;
     for (var z = 0;z < listz.size(); z++) {
		 switch(Mode.get()) {
			 case "Single":
    		var entity = mc.theWorld.loadedEntityList[z];			 
			 break;
			 case "Switch":
			 var entity = mc.theWorld.loadedEntityList[z];
			 break;
			 case "Multi":
			 var entity = mc.theWorld.loadedEntityList[z];		
			 delay += 999;
			 break;
		 }
		 ///////
		f = mc.thePlayer.getDistanceToEntity(entity);
		if (entity != null && entity != mc.thePlayer && entity instanceof EntityLiving && entity.getHealth() > 0 && ((ThroughWalls.get() == false && mc.thePlayer.canEntityBeSeen(entity)) || ThroughWalls.get() == true)) {
		if(f <= Range.get()) {
			validTarget = true;
		} else {
			validTarget = false;
		}
			/////////////////////////////// 
		    if(AutoBlock.get() == true && mc.thePlayer.getHeldItem().getItem() instanceof Swords && f <= BlockRange.get()) {
				switch(BlockMode.get()) {
					case "Old":
					 if(entity.hurtTime != 0) {
				     mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, mc.thePlayer.getHeldItem());
			         }
			         else {
			    	 mc.gameSettings.keyBindUseItem.pressed = false;
			         }
					break;
					case "Vanilla":
					mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, mc.thePlayer.getHeldItem());
					break;
					case "Hypixel":
					mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, mc.thePlayer.getHeldItem());
					mc.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, new BlockPos(0, 0, 0), EnumFacing.UP));
					break;
					case "Normal":
					mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, mc.thePlayer.getHeldItem());
					break;
					case "AAC":
					if(d >= randomIntFrom(2,8)) {
						mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, mc.thePlayer.getHeldItem());
						d = 0;
					}
					break;
				}
		    } 
			///////////////////////////
		    if(f <= Range.get() && validTarget == true && delay >= 20 / Delay.get() && ((NoEatHit.get() == true && !(mc.thePlayer.getHeldItem().getItem() instanceof Fooditems) && mc.thePlayer.isUsingItem()) || NoEatHit.get() == false)){ // from smsgamer
            mc.playerController.attackEntity(mc.thePlayer, entity);
    		delay = 0;
            }
			///////////////////////////
			if(Crasher.get() && f <= 8) {
				mc.playerController.attackEntity(mc.thePlayer, entity);
				mc.playerController.attackEntity(mc.thePlayer, entity);
				mc.playerController.attackEntity(mc.thePlayer, entity);
			}
			//////////////////////////
		}
	}
	}
	this.onUpdate = function() {
		this.KillAuraz();
	}

    this.onPacket = function(event){
		if(Aim.get()) {			
		var diffX = target.posX - mc.thePlayer.posX;
        var diffZ = target.posZ - mc.thePlayer.posZ;
        var diffY = target.posY + target.getEyeHeight() - mc.thePlayer.posY + mc.thePlayer.getEyeHeight();
        var dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
        var yaw = (Math.atan2(diffZ, diffX) * 180.0 / Math.PI) - 90.0;
        var pitch = -(Math.atan2(diffY, dist) * 180.0 / Math.PI);
		var packet = event.getPacket();
		if((packet instanceof PlayerLook || packet instanceof PlayerPositionLook) && validTarget == true) {
			switch(AimMode.get()) {
				case "Normal":
				packet.yaw = yaw;
				packet.pitch = pitch;
				break;
			}
		}
		}
    }
	this.onAttack = function() {//
	mc.thePlayer.swingItem(); // Moved 
	if(Correct.get() && mc.thePlayer.onGround) {
	mc.thePlayer.motionX /= .60;
	mc.thePlayer.motionZ /= .60;
	}
		if(AutoBlock.get() == true && BlockMode.get() == "Normal") {
			mc.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, new BlockPos(0, 0, 0), EnumFacing.UP));
			//if(InteractAutoBlock.get()) {
		    //    mc.thePlayer.sendQueue.addToSendQueue(new Interactpacket(entity, INTERACT));
			// }
		}
		if(AutoBlock.get() == true && BlockMode.get() == "AAC") {
			mc.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, new BlockPos(0, 0, 0), EnumFacing.UP));
			mc.thePlayer.keyBindUseItem.pressed = false;
		}
		if(KeepSprint.get() == true) { // Appears to function correctly
				 mc.thePlayer.setSprinting(true);
		}
		if(Aim.get() == true && AimMode.get() == "Snap") {
			cancelz = false;
			mc.thePlayer.sendQueue.addToSendQueue(new PlayerPositionLook(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, yaw, pitch, mc.thePlayer.onGround));
			cancelz = true;
		}
		if(Criticals.get() && mc.thePlayer.onGround) {
			mc.thePlayer.sendQueue.addToSendQueue(new PlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY + 0.08, mc.thePlayer.posZ, true));
			mc.thePlayer.sendQueue.addToSendQueue(new PlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, false));
		}
	}

	this.onDisable = function() {
			mc.gameSettings.keyBindUseItem.pressed = false;
			validTarget = false;
			d = 0;
	}
	this.addValues = function(values) {
		values.add(Mode);
		values.add(Delay);
		values.add(Range);
		values.add(KeepSprint);
		values.add(AutoBlock);
		values.add(BlockMode);
		values.add(BlockRange);
	//	values.add(InteractAutoBlock);
		values.add(Aim);
		values.add(AimMode);
		values.add(ThroughWalls);
	//	values.add(NoEatHit);
	//	values.add(Criticals);
	//values.add(Correct);
	//	values.add(Crasher);
	}
}

function onLoad() {
};

function onEnable() {
    AuraClient = moduleManager.registerModule(Aura);
};

function onDisable() {
    moduleManager.unregisterModule(AuraClient);
};
/* Credits:
yorik100 - helped with onPacket and some other minor details
SMS_Gamer - helped a lot with improving 
icewormy3 - emotional support [[][]] 

People on Discord - being xtremely toxic piece of shit 
"Kill yourself you American piece of shit" - Remeku#8640
"Go back to mining coal you inbred shit" - Bunksha#4895
[General harassment, bullying] - Dwaj#0275
*/