feat: add crude regex containercleaner

also works on self inventory btw
This commit is contained in:
əlemi 2023-11-12 06:03:18 +01:00
parent 12f1ec92a0
commit add2ea7945
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -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
}
}
}
}