summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AutoTool.java84
1 files 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<Slot> 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<Slot> 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<Slot> 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;