From add2ea794516533b80db830eab34bc4e8dfc620b Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 12 Nov 2023 06:03:18 +0100 Subject: feat: add crude regex containercleaner also works on self inventory btw --- .../ftbsc/bscv/modules/self/ContainerCleaner.java | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java (limited to 'src/main') 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 query; + public final ForgeConfigSpec.ConfigValue cooldown; + public final ForgeConfigSpec.ConfigValue 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 + } + } + } +} -- cgit v1.2.3-56-ga3b1