aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AutoTool.java44
-rw-r--r--src/main/java/ftbsc/bscv/tools/Inventory.java18
2 files changed, 57 insertions, 5 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java
index a0ef65a..2e26594 100644
--- a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java
+++ b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java
@@ -3,6 +3,7 @@ package ftbsc.bscv.modules.self;
import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.modules.Module;
@@ -10,6 +11,7 @@ import ftbsc.bscv.tools.Inventory;
import net.minecraft.block.BlockState;
import net.minecraft.command.CommandSource;
import net.minecraft.inventory.container.Slot;
+import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.common.ForgeConfigSpec;
@@ -17,8 +19,22 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
public class AutoTool extends Module implements ICommons {
+ public final ForgeConfigSpec.ConfigValue<Integer> limit;
+
public AutoTool(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
super("AutoTool", Group.SELF, builder, dispatcher);
+
+ this.limit = this.option(
+ "limit", "durability limit for tools, set to 0 to destroy them", 1,
+ IntegerArgumentType.integer(0), Integer.class,
+ builder, dispatcher
+ );
+ }
+
+ private boolean itemIsTooDamaged(ItemStack item) {
+ return this.limit.get() > 0
+ && item.getMaxDamage() > 0
+ && item.getMaxDamage() - item.getDamageValue() <= this.limit.get();
}
@SubscribeEvent
@@ -27,15 +43,19 @@ public class AutoTool extends Module implements ICommons {
// 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());
- List<Slot> hotbar = Inventory.hotbar(MC.player);
- int current_slot = MC.player.inventory.selected;
- float current_speed = hotbar.get(current_slot).getItem().getDestroySpeed(state);
- for (int i = 0; i < 9; i++) {
- float speed = hotbar.get(i).getItem().getDestroySpeed(state);
+ 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;
@@ -44,6 +64,20 @@ public class AutoTool extends Module implements ICommons {
MC.player.inventory.selected = current_slot;
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;
break;
case MISS:
break;
diff --git a/src/main/java/ftbsc/bscv/tools/Inventory.java b/src/main/java/ftbsc/bscv/tools/Inventory.java
index af755eb..23eb4a1 100644
--- a/src/main/java/ftbsc/bscv/tools/Inventory.java
+++ b/src/main/java/ftbsc/bscv/tools/Inventory.java
@@ -1,13 +1,31 @@
package ftbsc.bscv.tools;
+import java.util.Collection;
import java.util.List;
import ftbsc.bscv.ICommons;
import net.minecraft.client.entity.player.ClientPlayerEntity;
+import net.minecraft.entity.ai.attributes.AttributeModifier;
+import net.minecraft.entity.ai.attributes.Attributes;
+import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.inventory.container.Slot;
+import net.minecraft.item.ItemStack;
public class Inventory implements ICommons {
+
+ public static final int HOTBAR_SIZE = 9;
+
public static List<Slot> hotbar(ClientPlayerEntity player) {
return player.inventoryMenu.slots.subList(36, 45);
}
+
+ // TODO ????????????? wtf is this is there an easier way?
+ public static double itemDamage(ItemStack item) {
+ Collection<AttributeModifier> attrs =
+ item.getAttributeModifiers(EquipmentSlotType.MAINHAND)
+ .get(Attributes.ATTACK_DAMAGE);
+ if (attrs.isEmpty()) return 0.;
+ return Math.abs(attrs.iterator().next().getAmount());
+
+ }
}