diff options
-rw-r--r-- | src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java | 70 |
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 + } + } + } +} |