From c13aa88bbdb2a395b80a8f00c69b5f4904de5d9a Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 4 Mar 2023 01:24:39 +0100 Subject: [PATCH] feat: allow AutoTool to be invoked from other mods --- .../ftbsc/bscv/modules/self/AutoTool.java | 84 +++++++++++-------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java index 0e68658..2f90985 100644 --- a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java +++ b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java @@ -37,49 +37,67 @@ public class AutoTool extends AbstractModule implements ICommons { && item.getMaxDamage() - item.getDamageValue() <= this.limit.get(); } + public boolean selectBestWeapon() { + List hotbar = Inventory.hotbar(MC.player); + int current_slot = MC.player.inventory.selected; + double current_damage = Inventory.itemDPS(hotbar.get(current_slot).getItem()); + for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { + ItemStack item = hotbar.get(i).getItem(); + if (this.itemIsTooDamaged(item)) { + continue; + } + + double damage = Inventory.itemDPS(item); + if (damage > current_damage) { + current_slot = i; + current_damage = damage; + } + } + if (current_slot != MC.player.inventory.selected) { + MC.player.inventory.selected = current_slot; + MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER + return true; + } + return false; + } + + public boolean selectBestTool() { + List hotbar = Inventory.hotbar(MC.player); + int current_slot = MC.player.inventory.selected; + BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; + BlockState state = MC.level.getBlockState(result.getBlockPos()); + float current_speed = hotbar.get(current_slot).getItem().getDestroySpeed(state); + for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { + ItemStack item = hotbar.get(i).getItem(); + if (this.itemIsTooDamaged(item)) { + continue; + } + float speed = item.getDestroySpeed(state); + if (speed > current_speed) { + current_slot = i; + current_speed = speed; + } + } + if (current_slot != MC.player.inventory.selected) { + MC.player.inventory.selected = current_slot; + MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER + return true; + } + return false; + } + @SubscribeEvent public void onClick(InputEvent.ClickInputEvent event) { if (MC.player == null) return; // TODO this is fired many times consecutively, can we filter out // some without putting a dumb time cooldown?; if (event.isAttack()) { - List hotbar = Inventory.hotbar(MC.player); - int current_slot = MC.player.inventory.selected; switch (MC.hitResult.getType()) { case BLOCK: - BlockRayTraceResult result = (BlockRayTraceResult) MC.hitResult; - BlockState state = MC.level.getBlockState(result.getBlockPos()); - float current_speed = 0.f; - for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { - ItemStack item = hotbar.get(i).getItem(); - if (this.itemIsTooDamaged(item)) { - continue; - } - float speed = item.getDestroySpeed(state); - if (speed > current_speed) { - current_slot = i; - current_speed = speed; - } - } - MC.player.inventory.selected = current_slot; - MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER + selectBestTool(); break; case ENTITY: - double current_damage = 0.f; - for (int i = 0; i < Inventory.HOTBAR_SIZE; i++) { - ItemStack item = hotbar.get(i).getItem(); - if (this.itemIsTooDamaged(item)) { - continue; - } - - double damage = Inventory.itemDamage(item); - if (damage > current_damage) { - current_slot = i; - current_damage = damage; - } - } - MC.player.inventory.selected = current_slot; - MC.gameMode.ensureHasSentCarriedItem(); // ACCESSTRANSFORMER + selectBestWeapon(); break; case MISS: break;