package com.example.addon.modules;
import com.example.addon.QuinnAddon;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.ItemListSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import java.util.List;
/**
* Throws away junk as it piles up.
*
*
Changes from the version this was built from:
*
* - The category. {@code Category} is the class, not the list of them, so
* {@code Category.Misc} does not compile; this uses the addon's own category.
* - It no longer runs while a container is open. Slot indices are read against whatever
* screen handler is active, so dropping with a chest or shulker open throws the
* container's contents instead of yours.
* - The slot you are holding can be left alone, which is on by default — otherwise the
* blocks you are placing with get thrown out of your hand.
*
* The offhand is still not covered: it is outside the 0-35 range this walks.
*/
public class InventoryCleaner extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final Setting> items = sgGeneral.add(new ItemListSetting.Builder()
.name("items")
.description("Items to throw away.")
.defaultValue(
Items.DIRT,
Items.COBBLESTONE,
Items.ANDESITE,
Items.DIORITE,
Items.GRANITE
)
.build()
);
private final Setting delay = sgGeneral.add(new IntSetting.Builder()
.name("delay")
.description("Delay in ticks between throwing items.")
.defaultValue(2)
.min(0)
.build()
);
private final Setting skipSelected = sgGeneral.add(new BoolSetting.Builder()
.name("skip-selected-slot")
.description("Never throw the item you are currently holding.")
.defaultValue(true)
.build()
);
private final Setting skipHotbar = sgGeneral.add(new BoolSetting.Builder()
.name("skip-hotbar")
.description("Only clean the main inventory and leave the whole hotbar alone.")
.defaultValue(false)
.build()
);
private int timer;
public InventoryCleaner() {
super(QuinnAddon.CATEGORY, "inventory-cleaner", "Automatically throws away specified items.");
}
@Override
public void onActivate() {
timer = 0;
}
@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.player == null) return;
// With a container open, slot numbers address that container, not the player's inventory.
if (mc.player.currentScreenHandler != mc.player.playerScreenHandler) return;
if (timer > 0) {
timer--;
return;
}
for (int i = 9; i < 36; i++) {
if (checkAndDrop(i)) return;
}
if (skipHotbar.get()) return;
for (int i = 0; i < 9; i++) {
if (checkAndDrop(i)) return;
}
}
private boolean checkAndDrop(int slot) {
if (mc.player == null) return false;
if (skipSelected.get() && slot == mc.player.getInventory().getSelectedSlot()) return false;
Item item = mc.player.getInventory().getStack(slot).getItem();
if (item != Items.AIR && items.get().contains(item)) {
InvUtils.drop().slot(slot);
timer = delay.get();
return true;
}
return false;
}
}