summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-02-16 00:21:41 +0100
committer alemi <me@alemi.dev>2023-02-16 00:21:41 +0100
commit82b57f4de98710eea54a251779808d2c7304115c (patch)
treeaf575a2296ab3294ed06443e7b97d07288129a57 /src
parentd517ad0923e92d2dca6eb7775934fa09530d1186 (diff)
feat: added super basic autotool
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ftbsc/bscv/BoSCoVicino.java1
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/AutoTool.java53
-rw-r--r--src/main/java/ftbsc/bscv/tools/Inventory.java13
3 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/BoSCoVicino.java b/src/main/java/ftbsc/bscv/BoSCoVicino.java
index 4603d3f..2e5f6c5 100644
--- a/src/main/java/ftbsc/bscv/BoSCoVicino.java
+++ b/src/main/java/ftbsc/bscv/BoSCoVicino.java
@@ -65,6 +65,7 @@ public class BoSCoVicino implements ICommons {
BoSCoVicino.mods.add(new Fullbright(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new AntiHunger(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new AutoFish(cfg, dp).done(cfg));
+ BoSCoVicino.mods.add(new AutoTool(cfg, dp).done(cfg));
BoSCoVicino.mods.add(new Freecam(cfg, dp).done(cfg));
BoSCoVicino.spec = cfg.build();
diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoTool.java b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java
new file mode 100644
index 0000000..a0ef65a
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/modules/self/AutoTool.java
@@ -0,0 +1,53 @@
+package ftbsc.bscv.modules.self;
+
+import java.util.List;
+
+import com.mojang.brigadier.CommandDispatcher;
+
+import ftbsc.bscv.ICommons;
+import ftbsc.bscv.modules.Module;
+import ftbsc.bscv.tools.Inventory;
+import net.minecraft.block.BlockState;
+import net.minecraft.command.CommandSource;
+import net.minecraft.inventory.container.Slot;
+import net.minecraft.util.math.BlockRayTraceResult;
+import net.minecraftforge.client.event.InputEvent;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+public class AutoTool extends Module implements ICommons {
+
+ public AutoTool(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) {
+ super("AutoTool", Group.SELF, builder, dispatcher);
+ }
+
+ @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()) {
+ 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);
+ if (speed > current_speed) {
+ current_slot = i;
+ current_speed = speed;
+ }
+ }
+ MC.player.inventory.selected = current_slot;
+ break;
+ case ENTITY:
+ break;
+ case MISS:
+ break;
+ }
+ }
+ }
+}
diff --git a/src/main/java/ftbsc/bscv/tools/Inventory.java b/src/main/java/ftbsc/bscv/tools/Inventory.java
new file mode 100644
index 0000000..af755eb
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/tools/Inventory.java
@@ -0,0 +1,13 @@
+package ftbsc.bscv.tools;
+
+import java.util.List;
+
+import ftbsc.bscv.ICommons;
+import net.minecraft.client.entity.player.ClientPlayerEntity;
+import net.minecraft.inventory.container.Slot;
+
+public class Inventory implements ICommons {
+ public static List<Slot> hotbar(ClientPlayerEntity player) {
+ return player.inventoryMenu.slots.subList(36, 45);
+ }
+}