This code defines a class `AutoLootRun` that automates the process...

July 2, 2025 at 06:25 PM

package rosegoldclient.features; import net.minecraft.block.Block; import net.minecraft.block.BlockChest; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import rosegoldclient.Main; import rosegoldclient.events.PlayerMoveEvent; import rosegoldclient.events.ScreenClosedEvent; import rosegoldclient.events.SecondEvent; import rosegoldclient.events.TickEndEvent; import rosegoldclient.utils.RotationUtils; import java.util.HashSet; import static rosegoldclient.features.WynncraftChestESP.chests; public class AutoLootRun { public static boolean doing = false; private static final HashSet<BlockPos> allChests = new HashSet<>(); private static final HashSet<BlockPos> chestsInRange = new HashSet<>(); private static BlockPos selectedBlock = null; public static final HashSet<BlockPos> usedBlocks = new HashSet<>(); private static int waitingForChestClose = 0; @SubscribeEvent public void chestsInRange(TickEndEvent event) { if (Main.mc.player == null || Main.mc.world == null) return; if (!doing) return; if(Main.mc.player.ticksExisted % 4 != 0) return; int range = 5; BlockPos playerPosition = Main.mc.player.getPosition(); chestsInRange.clear(); if(selectedBlock == null) { for(BlockPos blockPos : chests) { Main.mc.player.setPosition(blockPos.getX(), blockPos.getY(), blockPos.getZ()); } } for (int x = playerPosition.getX() - range; x < playerPosition.getX() + range; x++) { for (int y = playerPosition.getY() - range; y < playerPosition.getY() + range; y++) { for (int z = playerPosition.getZ() - range; z < playerPosition.getZ() + range; z++) { BlockPos position = new BlockPos(x, y, z); Block block = Main.mc.world.getBlockState(position).getBlock(); if (block instanceof BlockChest) { chestsInRange.add(position); } } } } for (BlockPos chest : chestsInRange) { if (selectedBlock != null) return; if (!canOpenChest(chest)) continue; interactWithChest(chest); usedBlocks.add(chest); } } @SubscribeEvent(priority = EventPriority.NORMAL) public void onUpdatePre(PlayerMoveEvent.Pre pre) { if (selectedBlock != null) { RotationUtils.smoothLook(RotationUtils.getRotationToBlock(selectedBlock), 0, () -> {}); } } @SubscribeEvent public void onSecond(SecondEvent event) { if (Main.mc.player == null) return; if (Main.mc.currentScreen == null) { if(waitingForChestClose > 0) waitingForChestClose--; if(waitingForChestClose == 0) selectedBlock = null; CursorTP.disable = false; } } @SubscribeEvent public void onScreenClosed(ScreenClosedEvent event) { selectedBlock = null; CursorTP.disable = false; waitingForChestClose = 0; } @SubscribeEvent public void onWorldLoad(WorldEvent.Load event) { chestsInRange.clear(); allChests.clear(); usedBlocks.clear(); selectedBlock = null; CursorTP.disable = false; } private static boolean canOpenChest(BlockPos blockPos) { return Main.mc.player.onGround && Main.mc.currentScreen == null && !usedBlocks.contains(blockPos); } private static void interactWithChest(BlockPos block) { doing = false; CursorTP.disable = true; waitingForChestClose = 1; selectedBlock = block; Main.mc.playerController.processRightClickBlock( Main.mc.player, Main.mc.world, block, EnumFacing.fromAngle(Main.mc.player.rotationYaw), new Vec3d(Math.random(), Math.random(), Math.random()), EnumHand.MAIN_HAND ); Main.mc.player.swingArm(EnumHand.MAIN_HAND); } }

This code defines a class AutoLootRun that automates the process of locating and interacting with chests in a Minecraft modding environment using Forge. Here's a breakdown of what the code does:

Key Features and Workflow:

  1. Tracking Chests:

    • Maintains several sets (HashSet) to keep track of all chests (allChests), chests nearby to the player (chestsInRange), and chests that have already been interacted with (usedBlocks).
  2. Handling Player and Chest Interaction:

    • Continuously scans for chests within a specific range (default range 5) of the player’s position in the chestsInRange method.
    • Attempts to interact with any chests found by simulating a player's interaction using the interactWithChest method.
  3. Chest Interaction Logic:

    • Before interacting with a chest, it ensures:
      • The player is on the ground.
      • The player’s screen isn’t currently open.
      • The chest hasn’t been interacted with already.
    • If all conditions are met, it programmatically "opens" the chest by simulating a right-click action and marks the chest as "used."
  4. Smooth Player Rotation:

    • If a chest is selected, the onUpdatePre method uses RotationUtils.smoothLook to adjust the player's rotation smoothly to face the selected chest.
  5. Event Handling: The mod listens to key game events to maintain state and facilitate chest interaction:

    • TickEndEvent: Scans for chests in the player’s range and tries to interact with them.
    • PlayerMoveEvent.Pre: Ensures that if there’s a selected chest, the player rotates towards it.
    • SecondEvent: Handles logic for detecting when chest interaction has ended and resets the state.
    • ScreenClosedEvent: Resets when UI screens are closed (e.g., chest screens).
    • WorldEvent.Load: Clears all data structures and ensures everything is reset when a new world or server is loaded.
  6. Miscellaneous Functionality:

    • The canOpenChest method ensures conditions are met before attempting to open a chest.
    • Uses randomness in Vec3d to introduce slight variation in simulated interactions (likely to avoid detection by anti-cheat systems).
    • Resets the state of the automation when necessary, including clearing selected chests and variables like waitingForChestClose.

Behavior in Summary:

The AutoLootRun class effectively automates a chest-looting process by:

  • Constantly scanning for nearby chests.
  • Interacting with chests when conditions permit.
  • Handling player position, state, and game-world events to ensure smooth and uninterrupted automation.
  • Attempting to rotate the player's view naturally when interacting with objects.

This is likely part of a broader mod for Minecraft aimed at automating repetitive tasks such as loot runs while ensuring the game client behaves naturally to avoid detection by anti-cheat mechanisms.

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