feat: add crude regex containercleaner
also works on self inventory btw
This commit is contained in:
parent
12f1ec92a0
commit
add2ea7945
1 changed files with 70 additions and 0 deletions
70
src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java
Normal file
70
src/main/java/ftbsc/bscv/modules/self/ContainerCleaner.java
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue