rewrite aura and autotool logic and also close #501

This commit is contained in:
Bella 2020-04-06 09:59:34 -04:00
parent db65e1d56f
commit ea0e687664
No known key found for this signature in database
GPG Key ID: 815562EA23BFE344
2 changed files with 50 additions and 149 deletions

View File

@ -2,30 +2,25 @@ package me.zeroeightsix.kami.module.modules.combat;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.module.ModuleManager;
import me.zeroeightsix.kami.module.modules.misc.AutoTool;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.util.EntityUtil;
import me.zeroeightsix.kami.util.Friends;
import me.zeroeightsix.kami.util.LagCompensator;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemSword;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import java.util.Iterator;
/**
* Created by 086 on 12/12/2017.
* Updated by hub on 31 October 2019
* Updated by S-B99 on 22/02/20
* Updated by S-B99 on 06/04/20
*/
@Module.Info(name = "Aura", category = Module.Category.COMBAT, description = "Hits entities around you")
public class Aura extends Module {
@ -34,47 +29,35 @@ public class Aura extends Module {
private Setting<Boolean> attackAnimals = register(Settings.b("Animals", false));
private Setting<Double> hitRange = register(Settings.d("Hit Range", 5.5d));
private Setting<Boolean> ignoreWalls = register(Settings.b("Ignore Walls", true));
private Setting<HitMode> hitMode = register(Settings.e("Tool", HitMode.SWORD));
private Setting<SwitchMode> switchMode = register(Settings.e("Auto Switch", SwitchMode.ENCHANTED));
private Setting<WaitMode> delayMode = register(Settings.e("Delay Mode", WaitMode.SPAM));
private Setting<Double> waitTick = register(Settings.doubleBuilder("Spam Delay").withMinimum(0.1).withValue(2.0).withMaximum(20.0).withVisibility(v -> delayMode.getValue().equals(WaitMode.SPAM)).build());
private Setting<HitMode> prefer = register(Settings.e("Prefer", HitMode.SWORD));
private Setting<Boolean> autoTool = register(Settings.b("Auto Tool", true));
private Setting<WaitMode> delayMode = register(Settings.e("Mode", WaitMode.DELAY));
private Setting<Boolean> autoSpamDelay = register(Settings.booleanBuilder("Auto Spam Delay").withValue(true).withVisibility(v -> delayMode.getValue().equals(WaitMode.SPAM)).build());
private Setting<Boolean> autoTool = register(Settings.booleanBuilder("AutoTool").withValue(true).withVisibility(v -> switchMode.getValue().equals(SwitchMode.NONE)));
private Setting<Boolean> infoMsg = register(Settings.b("Info Message", true));
private Setting<Double> waitTick = register(Settings.doubleBuilder("Spam Delay").withMinimum(0.1).withValue(2.0).withMaximum(20.0).withVisibility(v -> !autoSpamDelay.getValue() && delayMode.getValue().equals(WaitMode.SPAM)).build());
private Setting<Boolean> infoMsg = register(Settings.booleanBuilder("Info Message").withValue(true).withVisibility(v -> false));
private int waitCounter;
private enum SwitchMode {
NONE, ENCHANTED, Only32k
}
public enum HitMode {
SWORD, AXE
}
private enum WaitMode {
DELAY, SPAM
}
public enum HitMode { SWORD, AXE, NONE }
private enum WaitMode { DELAY, SPAM }
@Override
public void onEnable() {
if (mc.player == null) return;
if (autoSpamDelay.getValue() && infoMsg.getValue()) Command.sendWarningMessage("[Aura] When Auto Tick Delay is turned on whatever you give Tick Delay doesn't matter, it uses the current TPS instead");
if (autoSpamDelay.getValue() && infoMsg.getValue()) {
infoMsg.setValue(false);
Command.sendWarningMessage("[Aura] When Auto Tick Delay is turned on whatever you give Tick Delay doesn't matter, it uses the current TPS instead");
}
}
@Override
public void onUpdate() {
if (mc.player == null || mc.player.isDead) return;
double autoWaitTick = 0;
if (mc.player.isDead) return;
if (autoSpamDelay.getValue()) {
//String tpsString = Double.toString(Math.round(LagCompensator.INSTANCE.getTickRate() * 10) / 10.0);
autoWaitTick = 20 - (Math.round(LagCompensator.INSTANCE.getTickRate() * 10) / 10.0);
//String autoWaitString = Double.toString(autoWaitTick);
//Command.sendWarningMessage(tpsString);
//Command.sendWarningMessage(autoWaitString);
}
boolean shield = mc.player.getHeldItemOffhand().getItem().equals(Items.SHIELD) && mc.player.getActiveHand() == EnumHand.OFF_HAND;
@ -111,98 +94,38 @@ public class Aura extends Module {
}
}
Iterator<Entity> entityIterator = Minecraft.getMinecraft().world.loadedEntityList.iterator();
while (entityIterator.hasNext()) {
Entity target = entityIterator.next();
if (!EntityUtil.isLiving(target)) continue;
if (target == mc.player) continue;
if (mc.player.getDistance(target) > hitRange.getValue()) continue;
if (((EntityLivingBase) target).getHealth() <= 0) continue;
if (delayMode.getValue().equals(WaitMode.DELAY) && ((EntityLivingBase) target).hurtTime != 0) continue;
if (!ignoreWalls.getValue() && (!mc.player.canEntityBeSeen(target) && !canEntityFeetBeSeen(target))) continue; // If walls is on & you can't see the feet or head of the target, skip. 2 raytraces needed
for (Entity target : mc.world.loadedEntityList) {
if (!EntityUtil.isLiving(target))
continue;
if (target == mc.player)
continue;
if (mc.player.getDistance(target) > hitRange.getValue())
continue;
if (((EntityLivingBase) target).getHealth() <= 0)
continue;
if (delayMode.getValue().equals(WaitMode.DELAY) && ((EntityLivingBase) target).hurtTime != 0)
continue;
if (!ignoreWalls.getValue() && (!mc.player.canEntityBeSeen(target) && !canEntityFeetBeSeen(target)))
continue; // If walls is on & you can't see the feet or head of the target, skip. 2 raytraces needed
if (attackPlayers.getValue() && target instanceof EntityPlayer && !Friends.isFriend(target.getName())) {
attack(target);
return;
} else {
if (EntityUtil.isPassive(target) ? attackAnimals.getValue() : (EntityUtil.isMobAggressive(target) && attackMobs.getValue())) {
// We want to skip this if switchTo32k.getValue() is true,
// because it only accounts for tools and weapons.
// Maybe someone could refactor this later? :3
if ((!switchMode.getValue().equals(SwitchMode.Only32k) || switchMode.getValue().equals(SwitchMode.ENCHANTED)) && ModuleManager.isModuleEnabled("AutoTool") || autoTool.getValue()) {
AutoTool.equipBestWeapon(hitMode.getValue());
if ((autoTool.getValue())) {
AutoTool.equipBestWeapon(prefer.getValue());
}
if (mc.player.getHeldItemMainhand().getItem() instanceof ItemSword || mc.player.getHeldItemMainhand().getItem() instanceof ItemAxe) {
attack(target);
}
attack(target);
return;
}
}
}
}
private boolean checkSharpness(ItemStack stack) {
if (stack.getTagCompound() == null) return false;
if (stack.getItem().equals(Items.DIAMOND_AXE) && hitMode.getValue().equals(HitMode.SWORD)) return false;
if (stack.getItem().equals(Items.DIAMOND_SWORD) && hitMode.getValue().equals(HitMode.AXE)) return false;
NBTTagList enchants = (NBTTagList) stack.getTagCompound().getTag("ench");
// IntelliJ marks (enchants == null) as always false but this is not correct.
// In case of a Hotbar Slot without any Enchantment on the Stack it contains,
// this will throw a NullPointerException if not accounted for!
//noinspection ConstantConditions
if (enchants == null) {
return false;
}
for (int i = 0; i < enchants.tagCount(); i++) {
NBTTagCompound enchant = enchants.getCompoundTagAt(i);
if (enchant.getInteger("id") == 16) {
int lvl = enchant.getInteger("lvl");
if (switchMode.getValue().equals(SwitchMode.Only32k)) {
if (lvl >= 42) { // dia sword against full prot 5 armor is deadly somehere >= 34 sharpness iirc
return true;
}
} else if (switchMode.getValue().equals(SwitchMode.ENCHANTED)) {
if (lvl >= 4) {
return true;
}
} else if (switchMode.getValue().equals(SwitchMode.NONE)) {
return true;
}
break;
}
}
return false;
}
private void attack(Entity e) {
boolean holding32k = false;
if (checkSharpness(mc.player.getHeldItemMainhand())) holding32k = true;
if ((switchMode.getValue().equals(SwitchMode.Only32k) || switchMode.getValue().equals(SwitchMode.ENCHANTED)) && !holding32k) {
int newSlot = -1;
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack == ItemStack.EMPTY) continue;
if (checkSharpness(stack)) {
newSlot = i;
break;
}
}
if (newSlot != -1) {
mc.player.inventory.currentItem = newSlot;
holding32k = true;
}
}
if (switchMode.getValue().equals(SwitchMode.Only32k) && !holding32k) return;
mc.playerController.attackEntity(mc.player, e);
mc.player.swingArm(EnumHand.MAIN_HAND);

View File

@ -19,20 +19,17 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
/**
* Created by 086 on 2/10/2018.
* Updated by S-B99 on 06/04/20
*/
@Module.Info(name = "AutoTool", description = "Automatically switch to the best tools when mining or attacking", category = Module.Category.MISC)
public class AutoTool extends Module {
private Setting<Aura.HitMode> preferTool = register(Settings.e("Prefer Tool", Aura.HitMode.SWORD));
private Setting<Aura.HitMode> preferTool = register(Settings.e("Prefer", Aura.HitMode.NONE));
@EventHandler
private Listener<PlayerInteractEvent.LeftClickBlock> leftClickListener = new Listener<>(event -> {
equipBestTool(mc.world.getBlockState(event.getPos()));
});
private Listener<PlayerInteractEvent.LeftClickBlock> leftClickListener = new Listener<>(event -> equipBestTool(mc.world.getBlockState(event.getPos())));
@EventHandler
private Listener<AttackEntityEvent> attackListener = new Listener<>(event -> {
equipBestWeapon();
});
private Listener<AttackEntityEvent> attackListener = new Listener<>(event -> equipBestWeapon(preferTool.getValue()));
private void equipBestTool(IBlockState blockState) {
int bestSlot = -1;
@ -53,47 +50,29 @@ public class AutoTool extends Module {
if (bestSlot != -1) equip(bestSlot);
}
public void equipBestWeapon() {
int bestSlot = -1;
double maxDamage = 0;
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack.isEmpty) continue;
if (!(stack.getItem() instanceof ItemSword) && preferTool.getValue().equals(Aura.HitMode.SWORD) ||
!(stack.getItem() instanceof ItemAxe && preferTool.getValue().equals(Aura.HitMode.AXE))) continue;
if (stack.getItem() instanceof ItemTool) {
double damage = (((ItemTool) stack.getItem()).attackDamage + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED));
if (damage > maxDamage) {
maxDamage = damage;
bestSlot = i;
}
} else if (stack.getItem() instanceof ItemSword) {
double damage = (((ItemSword) stack.getItem()).getAttackDamage() + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED));
if (damage > maxDamage) {
maxDamage = damage;
bestSlot = i;
}
}
}
if (bestSlot != -1) equip(bestSlot);
}
public static void equipBestWeapon(Aura.HitMode hitMode) {
int bestSlot = -1;
double maxDamage = 0;
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack.isEmpty) continue;
if (!(stack.getItem() instanceof ItemSword) && hitMode.equals(Aura.HitMode.SWORD) ||
!(stack.getItem() instanceof ItemAxe && hitMode.equals(Aura.HitMode.AXE))) continue;
if (stack.getItem() instanceof ItemTool) {
if (!(stack.getItem() instanceof ItemAxe) && hitMode.equals(Aura.HitMode.AXE)) continue;
if (!(stack.getItem() instanceof ItemSword) && hitMode.equals(Aura.HitMode.SWORD)) continue;
if (stack.getItem() instanceof ItemSword && (hitMode.equals(Aura.HitMode.SWORD) || hitMode.equals(Aura.HitMode.NONE))) {
double damage = (((ItemSword) stack.getItem()).getAttackDamage() + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED));
if (damage > maxDamage) {
maxDamage = damage;
bestSlot = i;
}
} else if (stack.getItem() instanceof ItemAxe && (hitMode.equals(Aura.HitMode.AXE) || hitMode.equals(Aura.HitMode.NONE))) {
double damage = (((ItemTool) stack.getItem()).attackDamage + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED));
if (damage > maxDamage) {
maxDamage = damage;
bestSlot = i;
}
} else if (stack.getItem() instanceof ItemSword) {
double damage = (((ItemSword) stack.getItem()).getAttackDamage() + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED));
} else if (stack.getItem() instanceof ItemTool) {
double damage = (((ItemTool) stack.getItem()).attackDamage + (double) EnchantmentHelper.getModifierForCreature(stack, EnumCreatureAttribute.UNDEFINED));
if (damage > maxDamage) {
maxDamage = damage;
bestSlot = i;
@ -107,5 +86,4 @@ public class AutoTool extends Module {
mc.player.inventory.currentItem = slot;
mc.playerController.syncCurrentPlayItem();
}
}