This code defines a Minecraft mod feature called `ChestLooter`, which...

July 2, 2025 at 07:19 PM

package rosegoldclient.features; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.inventory.ClickType; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.Slot; import net.minecraft.util.StringUtils; import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import rosegoldclient.Main; import rosegoldclient.events.SecondEvent; import rosegoldclient.events.TickEndEvent; import rosegoldclient.utils.Utils; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; public class ChestLooter { private long lastClickTime = 0L; private final List<Map.Entry<Slot, Boolean>> items = new ArrayList<>(27); private Set<String> leftClick = Stream.of("Kaian Scroll", "Fairy Powder", "Stolen Goods", "Golden Avia Feather", "Fiery Aura", "Windy Aura", "Watery Aura", "Sought-After Ore", "Ancient Currency", "Glimmering Coin", "Doom Stone", "Lunar Charm", "Nose Ring", "Decaying Heart", "Stolen Pearls", "Antique Metal", "Luxroot Cuttings", "Emerald").collect(Collectors.toSet()); private final Set<String> shiftClick = Stream.of("Fire Powder IV", "Air Powder IV", "Thunder Powder IV", "Water Powder IV", "Earth Powder IV").collect(Collectors.toSet()); @SubscribeEvent public void onGuiOpen(GuiOpenEvent event) { items.clear(); } @SubscribeEvent public void onGuiDraw(GuiScreenEvent.BackgroundDrawnEvent event) { ContainerChest container; if (!Main.configFile.chestLoot || !(event.getGui() instanceof GuiChest)) return; if (((GuiChest) event.getGui()).inventorySlots instanceof ContainerChest && StringUtils.stripControlCodes((container = (ContainerChest) ((GuiChest) event.getGui()).inventorySlots).getLowerChestInventory().getDisplayName().getUnformattedText()).contains("Loot Chest I")) { if (items.isEmpty()) { HashMap<Slot, Boolean> map = new HashMap<>(); List<Slot> chestSlots = container.inventorySlots.subList(0, 27); for (Slot slot : chestSlots) { if (!slot.getHasStack()) continue; String itemName = StringUtils.stripControlCodes(slot.getStack().getDisplayName()); if (leftClick.stream().anyMatch(itemName::contains)) { map.put(slot, false); continue; } if(shiftClick.stream().anyMatch(itemName::contains)) { map.put(slot, true); } } items.addAll(map.entrySet()); } else if (System.currentTimeMillis() - lastClickTime > (long) Main.configFile.chestLootDelay) { Main.mc.playerController.windowClick( Main.mc.player.openContainer.windowId, items.get(0).getKey().slotNumber, 0, items.get(0).getValue() ? ClickType.QUICK_MOVE : ClickType.PICKUP, Main.mc.player ); items.remove(0); lastClickTime = System.currentTimeMillis(); } } } @SubscribeEvent public void onSecond(SecondEvent event) { Set<String> mainStream = Stream.of("Kaian Scroll", "Fairy Powder", "Stolen Goods", "Golden Avia Feather", "Fiery Aura", "Windy Aura", "Watery Aura", "Sought-After Ore", "Ancient Currency", "Glimmering Coin", "Doom Stone", "Lunar Charm", "Nose Ring", "Decaying Heart", "Stolen Pearls", "Antique Metal", "Luxroot Cuttings", "Emerald").collect(Collectors.toSet()); if(Main.configFile.doChestLootFilter) { String[] split = Main.configFile.chestLootFilter.split(","); mainStream.addAll(Stream.of(split).collect(Collectors.toSet())); } leftClick = mainStream; } }

This code defines a Minecraft mod feature called ChestLooter, which automates the process of looting specific items from chests in the game. Here's what the code does:

Purpose:

The ChestLooter class listens for specific events during the game and interacts with in-game chests. It is designed to automatically loot items based on configurable preferences.


Key Behavior:

  1. Core Features:

    • The ChestLooter primarily interacts with a chest (presumably one called "Loot Chest I") when it's detected.
    • It determines which items to pick from the chest based on pre-defined filters (e.g., leftClick and shiftClick sets).
  2. Event Listeners:

    • onGuiOpen:

      • This method is triggered when a GUI (Graphical User Interface) is opened.
      • It clears the items list to reset the looting logic when a chest GUI is opened.
    • onGuiDraw:

      • Triggered when the chest GUI is being drawn.
      • If the chest is valid (identified by its name containing "Loot Chest I"):
        1. It scans the chest's first 27 slots to identify items matching those in the leftClick or shiftClick sets.
          • Items in the leftClick set are added with a flag false for normal pickup clicking.
          • Items in the shiftClick set are flagged with true for faster "shift-click" transfer.
        2. It attempts to automatically loot the identified items, performing either a normal click (ClickType.PICKUP) or quick move (ClickType.QUICK_MOVE).
        3. It enforces a delay between clicks using the lastClickTime variable.
    • onSecond:

      • This method runs periodically (every second).
      • It updates the leftClick set dynamically based on user configuration (chestLootFilter option in the configuration file). This allows adding new items to the looting filter during runtime.
  3. Filters and Item Selection:

    • Items to be looted are divided into two categories:
      • leftClick: These items are picked up using normal clicks.
      • shiftClick: These items are picked up using "shift-click," which instantly transfers them to the player's inventory.
    • Filters are hard-coded initially, but they can be extended dynamically based on the configuration file (Main.configFile).
  4. Configuration Integration:

    • Main.configFile.chestLoot: Enables/disables the looting feature.
    • Main.configFile.chestLootDelay: Specifies the delay between clicks when looting items.
    • Main.configFile.chestLootFilter: A configurable list of additional item names to be looted, separated by commas.
  5. Minecraft-Specific Interactions:

    • The mod heavily uses Minecraft's Forge library and APIs to listen for events (GuiOpenEvent, GuiScreenEvent.BackgroundDrawnEvent, etc.) and perform in-game actions (clicking and interacting with item slots in the chest).

Summary of Workflow:

  1. When a chest GUI opens, the looter resets the internal item list.
  2. Upon detecting a "Loot Chest I":
    • The chest is scanned for desirable items based on predefined filters.
    • Items are flagged for either normal click or shift-click actions.
  3. The looter then clicks on the identified item slots one by one, with a delay, until all items matching the filter are looted.
  4. The filters can dynamically update based on the user's settings for more flexibility.

Use Case:

This mod can save players time during gameplay by automating the looting process for specific chests and only taking desired items (useful for farming loot in games with high repetition).

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node