aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author alemi <me@alemi.dev>2023-11-12 06:03:18 +0100
committer alemi <me@alemi.dev>2023-11-12 06:03:18 +0100
commitadd2ea794516533b80db830eab34bc4e8dfc620b (patch)
tree139ffb24af53a9ddb3a7d9f593c40e092b21ddb6 /src
parent12f1ec92a0c04ac35ad81370c2183ecd2827af02 (diff)
feat: add crude regex containercleaner
also works on self inventory btw
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java
new file mode 100644
index 0000000..d08d832
--- /dev/null
+++ b/src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java
@@ -0,0 +1,70 @@
+package ftbsc.bscv.modules.self;
+
+import java.util.regex.Pattern;
+import com.google.auto.service.AutoService;
+
+import ftbsc.bscv.Boscovicino;
+import ftbsc.bscv.api.ILoadable;
+import ftbsc.bscv.modules.AbstractModule;
+import ftbsc.bscv.tools.Inventory;
+import ftbsc.bscv.tools.Setting;
+import net.minecraft.client.gui.screen.inventory.ContainerScreen;
+import net.minecraft.inventory.container.ClickType;
+import net.minecraft.inventory.container.Slot;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.event.TickEvent.ClientTickEvent;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+
+@AutoService(ILoadable.class)
+public class ContainerCleaner extends AbstractModule {
+
+ public final ForgeConfigSpec.ConfigValue<String> query;
+ public final ForgeConfigSpec.ConfigValue<Integer> cooldown;
+ public final ForgeConfigSpec.ConfigValue<Boolean> limit;
+ private Pattern pattern;
+ private int counter;
+
+ public ContainerCleaner() {
+ super();
+
+ this.pattern = Pattern.compile("");
+ this.query = Setting.Str.builder()
+ .fallback("")
+ .name("query")
+ .comment("search query for dropping items")
+ .callback(to -> this.pattern = Pattern.compile(to))
+ .build(this);
+
+ this.counter = 0;
+ this.cooldown = Setting.Number.builder()
+ .fallback(0)
+ .name("cooldown")
+ .comment("ticks before throwing next item")
+ .build(this);
+
+ this.limit = Setting.Bool.builder()
+ .fallback(true)
+ .name("limit")
+ .comment("limit to one action per tick")
+ .build(this);
+ }
+
+ @SubscribeEvent
+ public void onTick(ClientTickEvent event) {
+ if (MC.screen == null) return;
+ if (!(MC.screen instanceof ContainerScreen)) return;
+ if (this.counter > 0) {
+ this.counter -= 1;
+ return;
+ }
+ ContainerScreen<?> screen = (ContainerScreen<?>) MC.screen;
+ for (Slot slot : screen.getMenu().slots) {
+ if (Inventory.matchItem(this.pattern, slot.getItem())) {
+ Boscovicino.log("dropping item %s", slot.getItem().getItem());
+ Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW);
+ this.counter = this.cooldown.get();
+ if (this.limit.get()) return; // only throw one item per tick
+ }
+ }
+ }
+}