feat: use list of integers (ids) for containerclean
This commit is contained in:
parent
0045af0117
commit
cf69868863
1 changed files with 19 additions and 18 deletions
|
@ -1,16 +1,20 @@
|
||||||
package ftbsc.bscv.modules.self;
|
package ftbsc.bscv.modules.self;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.auto.service.AutoService;
|
import com.google.auto.service.AutoService;
|
||||||
|
|
||||||
import ftbsc.bscv.Boscovicino;
|
|
||||||
import ftbsc.bscv.api.ILoadable;
|
import ftbsc.bscv.api.ILoadable;
|
||||||
import ftbsc.bscv.modules.AbstractModule;
|
import ftbsc.bscv.modules.AbstractModule;
|
||||||
import ftbsc.bscv.tools.Inventory;
|
import ftbsc.bscv.tools.Inventory;
|
||||||
import ftbsc.bscv.tools.Setting;
|
import ftbsc.bscv.tools.Setting;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||||
|
import net.minecraft.command.arguments.ItemArgument;
|
||||||
|
import net.minecraft.command.arguments.ItemInput;
|
||||||
import net.minecraft.inventory.container.ClickType;
|
import net.minecraft.inventory.container.ClickType;
|
||||||
import net.minecraft.inventory.container.Slot;
|
import net.minecraft.inventory.container.Slot;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
@ -18,23 +22,14 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
@AutoService(ILoadable.class)
|
@AutoService(ILoadable.class)
|
||||||
public class ContainerCleaner extends AbstractModule {
|
public class ContainerCleaner extends AbstractModule {
|
||||||
|
|
||||||
public final ForgeConfigSpec.ConfigValue<String> query;
|
|
||||||
public final ForgeConfigSpec.ConfigValue<Integer> cooldown;
|
public final ForgeConfigSpec.ConfigValue<Integer> cooldown;
|
||||||
public final ForgeConfigSpec.ConfigValue<Boolean> limit;
|
public final ForgeConfigSpec.ConfigValue<Boolean> limit;
|
||||||
private Pattern pattern;
|
public final ForgeConfigSpec.ConfigValue<List<? extends Integer>> blacklist;
|
||||||
private int counter;
|
private int counter;
|
||||||
|
|
||||||
public ContainerCleaner() {
|
public ContainerCleaner() {
|
||||||
super();
|
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.counter = 0;
|
||||||
this.cooldown = Setting.Number.builder()
|
this.cooldown = Setting.Number.builder()
|
||||||
.fallback(0)
|
.fallback(0)
|
||||||
|
@ -47,6 +42,13 @@ public class ContainerCleaner extends AbstractModule {
|
||||||
.name("limit")
|
.name("limit")
|
||||||
.comment("limit to one action per tick")
|
.comment("limit to one action per tick")
|
||||||
.build(this);
|
.build(this);
|
||||||
|
|
||||||
|
this.blacklist = new Setting.Many<ItemInput, Integer>(ItemArgument.item(), ItemInput.class)
|
||||||
|
.writer(x -> Item.getId(x.getItem()))
|
||||||
|
.fallback(new ArrayList<Integer>())
|
||||||
|
.name("blacklist")
|
||||||
|
.comment("items to throw away")
|
||||||
|
.build(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
@ -59,12 +61,11 @@ public class ContainerCleaner extends AbstractModule {
|
||||||
}
|
}
|
||||||
ContainerScreen<?> screen = (ContainerScreen<?>) MC.screen;
|
ContainerScreen<?> screen = (ContainerScreen<?>) MC.screen;
|
||||||
for (Slot slot : screen.getMenu().slots) {
|
for (Slot slot : screen.getMenu().slots) {
|
||||||
if (Inventory.matchItem(this.pattern, slot.getItem())) {
|
if (this.blacklist.get().contains(Item.getId(slot.getItem().getItem()))) {
|
||||||
Boscovicino.log("dropping item %s", slot.getItem().getItem());
|
Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW);
|
||||||
Inventory.clickSLot(screen.getMenu().containerId, slot, ClickType.THROW);
|
this.counter = this.cooldown.get();
|
||||||
this.counter = this.cooldown.get();
|
if (this.limit.get()) return; // only throw one item per tick
|
||||||
if (this.limit.get()) return; // only throw one item per tick
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue