### BaseOperator: Execute Mining Operations (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt The BaseOperator class handles the asynchronous execution of block breaking operations. It processes discovered positions, manages tool durability, and respects chain key state. Dependencies include Manager, BasePositionFounder, and LinkedBlockingQueue. It takes a starting position and a Manager instance as input. ```java public class BaseOperator { public Manager manager; public BasePositionFounder positionFounder; public LinkedBlockingQueue canBreakPositions = new LinkedBlockingQueue<>(); public int operatorCount = 0; public BaseOperator(Vector3i pos, Manager manager) { this.playerMP = manager.player; this.manager = manager; // Create position finder based on current mode this.positionFounder = manager.minerModeState.createPositionFounder( pos, canBreakPositions, playerMP, manager.pConfig ); MyMod.parallelTick.addPreServerTickTask(this.positionFounder); } @SubscribeEvent public void operatorTask(TickEvent.ServerTickEvent event) { if (event.phase != TickEvent.Phase.START) return; if (!manager.inPressChainKey) { this.unRegistry(); return; } if (canBreakPositions.isEmpty()) return; int breakCountInTick = 0; Vector3i pos; while ((pos = canBreakPositions.poll()) != null) { if (!checkCanOperate()) { this.unRegistry(); return; } try { playerMP.theItemInWorldManager.tryHarvestBlock(pos.x, pos.y, pos.z); } catch (Exception e) { LOG.error("Error harvesting block: " + e); } breakCountInTick++; operatorCount++; if (breakCountInTick >= 64) return; // Limit blocks per tick } if (positionFounder.stopped.get()) { this.unRegistry(); } } // Check if operation can continue (chain key pressed and tool has durability) public boolean checkCanOperate() { if (!manager.inPressChainKey) return false; ItemStack equippedItem = playerMP.getCurrentEquippedItem(); if (equippedItem != null && equippedItem.isItemStackDamageable()) { return (equippedItem.getMaxDamage() - equippedItem.getItemDamage() > 1); } return true; } } ``` -------------------------------- ### KeyListener: Handle Client Input for Mining (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt The KeyListener class manages client-side key inputs for activating chain mining and switching between different mining modes. It uses KeyBinding objects for 'tilde' (~) and 'V' keys. Dependencies include InputEvent, Keyboard, Mouse, and various packet classes for server communication. It handles mouse wheel events for sub-mode switching. ```java @SideOnly(Side.CLIENT) public class KeyListener { public static KeyBinding chainSwitch = new KeyBinding( "key.qz_miner.chainSwitch", Keyboard.KEY_GRAVE, "key.categories.qz_miner" ); public static KeyBinding mainModeSwitch = new KeyBinding( "key.qz_miner.mainModeSwitch", Keyboard.KEY_V, "key.categories.qz_miner" ); public boolean onChain = false; @SubscribeEvent public void onInput(InputEvent event) { MinerModeState minerModeState = ((ClientProxy) MyMod.proxy).clientState.minerModeState; // Switch main mode with V key if (mainModeSwitch.isPressed()) { MessageUtils.printSelfMessage("Current mode: " + I18n.format(minerModeState.nextMainMode())); MyMod.networkMain.network.sendToServer(new PacketMinerModeState(minerModeState)); } // Chain key pressed - start chain mining if (chainSwitch.getIsKeyPressed()) { if (!onChain) { MyMod.networkMain.network.sendToServer(new PacketChainSwitcher(true)); ((ClientProxy)MyMod.proxy).minerRenderer.inPressChainKey = true; MyMod.networkMain.network.sendToServer(new PacketMinerConfig(new MinerConfig())); } onChain = true; // Mouse wheel switches sub-modes while chain key held if (event instanceof InputEvent.MouseInputEvent && Mouse.getEventDWheel() != 0) { int dWheel = Mouse.getEventDWheel(); if (dWheel < 0) minerModeState.nextSecondMode(); else if (dWheel > 0) minerModeState.previousSecondMode(); MyMod.networkMain.network.sendToServer(new PacketMinerModeState(minerModeState)); MessageUtils.printSelfMessage("Current sub-mode: " + I18n.format(minerModeState.currentSecondMode())); } } // Chain key released - stop chain mining if (!chainSwitch.getIsKeyPressed() && onChain) { MyMod.networkMain.network.sendToServer(new PacketChainSwitcher(false)); ((ClientProxy)MyMod.proxy).minerRenderer.inPressChainKey = false; onChain = false; } } } ``` -------------------------------- ### Mining Preview Renderer Implementation (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt This Java code implements a 'MinerRenderer' that provides visual feedback for chain mining operations. It subscribes to the 'DrawBlockHighlightEvent' to render highlighted blocks. The renderer manages a 'BaseChainViewer' to display the preview and updates it when the target block changes or when the mining operation starts/stops. ```java public class MinerRenderer { public boolean inPressChainKey = false; public BaseChainViewer viewer; public Vector3i lastTarget = new Vector3i(Integer.MIN_VALUE); @SubscribeEvent public void onBlockHighLight(DrawBlockHighlightEvent event) { if (!Config.usePreview) return; if (!inPressChainKey) { onNotPressChainKey(); return; } // Check if target block changed Vector3i target = new Vector3i(event.target.blockX, event.target.blockY, event.target.blockZ); if (!lastTarget.equals(target)) { lastTarget = target; onPressButChangeTarget(); } previewRender(); } private void previewRender() { if (viewer == null) { viewer = new BaseChainViewer(lastTarget); } } private void onPressButChangeTarget() { if (viewer != null) { viewer.unRegistry(); viewer = new BaseChainViewer(lastTarget); } } private void onNotPressChainKey() { if (viewer != null) { viewer.inPressChainKey = false; viewer.unRegistry(); viewer = null; } } public void registry() { MinecraftForge.EVENT_BUS.register(this); } } ``` -------------------------------- ### Network Packet System Registration and Configuration Sync (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt This snippet demonstrates the registration of network channels and packet handlers for client-server synchronization. It includes the 'PacketMinerConfig' class, which handles the serialization and deserialization of mining configuration data, ensuring consistency between client and server settings. The handler validates and clamps configuration values on the server side. ```java public class NetworkMain { public final SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel(Constant.MODID); public void registry() { int packetID = 0; // Chain key state packet (client -> server) network.registerMessage(PacketChainSwitcher.ChainSwitcherPacketHandler.class, PacketChainSwitcher.class, packetID++, Side.SERVER); // Config sync packet (bidirectional) network.registerMessage(PacketMinerConfig.PacketMinerConfigHandler.class, PacketMinerConfig.class, packetID++, Side.SERVER); network.registerMessage(PacketMinerConfig.PacketMinerConfigHandler.class, PacketMinerConfig.class, packetID++, Side.CLIENT); // Mode state packet (client -> server) network.registerMessage(PacketMinerModeState.PacketMinerModeStateHandler.class, PacketMinerModeState.class, packetID++, Side.SERVER); } } public class PacketMinerConfig implements IMessage { public MinerConfig minerConfig = new MinerConfig(); public void fromBytes(ByteBuf buf) { minerConfig.bigRadius = buf.readInt(); minerConfig.blockLimit = buf.readInt(); minerConfig.smallRadius = buf.readInt(); minerConfig.tunnelWidth = buf.readInt(); minerConfig.useChainDoneMessage = buf.readBoolean(); } public void toBytes(ByteBuf buf) { buf.writeInt(minerConfig.bigRadius); buf.writeInt(minerConfig.blockLimit); buf.writeInt(minerConfig.smallRadius); buf.writeInt(minerConfig.tunnelWidth); buf.writeBoolean(minerConfig.useChainDoneMessage); } public static class PacketMinerConfigHandler implements IMessageHandler { public IMessage onMessage(PacketMinerConfig message, MessageContext ctx) { if (ctx.side.isServer()) { EntityPlayerMP playerMP = ctx.getServerHandler().playerEntity; Manager manager = MyMod.playerManager.managers.get(playerMP.getUniqueID()); // Server validates and clamps config values manager.receiveClientConfig(message.minerConfig); return new PacketMinerConfig(manager.pConfig); // Return validated config } if (ctx.side.isClient()) { // Client receives server-validated config Config.bigRadius = message.minerConfig.bigRadius; Config.blockLimit = message.minerConfig.blockLimit; } return null; } } } ``` -------------------------------- ### Core Configuration Management in Java Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt Manages all mod settings including mining radius, block limits, and client preferences. Configuration is loaded from a file and supports runtime changes through the GUI. It initializes and loads configuration values from a file. ```java public class Config { public static int bigRadius = 8; // Maximum chain mining radius public static int blockLimit = 1024; // Maximum blocks per chain operation public static int smallRadius = 2; // Small area detection radius for connectivity public static int tunnelWidth = 1; // Tunnel mining width public static boolean usePreview = true; // Enable visual mining preview public static boolean useChainDoneMessage = true; // Show completion message public static double addExhaustion = 0.025; // Hunger added per block mined // Initialize configuration from file public void init(File configFile) { if (config == null) { config = new Configuration(configFile); } load(); } // Load configuration values public void load() { bigRadius = config.getInt("bigRadius", Configuration.CATEGORY_GENERAL, 8, 0, Integer.MAX_VALUE, "Maximum chain radius"); blockLimit = config.getInt("blockLimit", Configuration.CATEGORY_GENERAL, 1024, 0, Integer.MAX_VALUE, "Maximum chain block count"); smallRadius = config.getInt("smallRadius", Configuration.CATEGORY_GENERAL, 2, 0, Integer.MAX_VALUE, "Chain small area detection radius"); usePreview = config.getBoolean("usePreview", CLIENT_CATEGORY, true, "Enable chain preview feature"); if (config.hasChanged()) { config.save(); } } } ``` -------------------------------- ### Chain Mining Block Discovery with ChainPositionFounder (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt This Java code defines the ChainPositionFounder class, responsible for discovering connected blocks of the same type. It extends BasePositionFounder and utilizes a recursive or iterative approach to explore blocks within defined radii, checking for block type, material, and connectivity to already found positions. Dependencies include Vector3i, LinkedBlockingQueue, EntityPlayer, MinerConfig, Block, Blocks, and DeterminingIdentical. ```java public class ChainPositionFounder extends BasePositionFounder { public ChainPositionFounder(Vector3i center, LinkedBlockingQueue results, EntityPlayer player, MinerConfig minerConfig) { super(center, results, player, minerConfig); setName("Chain Finder"); } @Override public void run1() { int curRadius = 1; while (curCount < minerConfig.blockLimit && curRadius <= minerConfig.bigRadius) { for (int x = center.x - curRadius; x <= center.x + curRadius; x++) { for (int y = center.y - curRadius; y <= center.y + curRadius; y++) { for (int z = center.z - curRadius; z <= center.z + curRadius; z++) { Vector3i pos = new Vector3i(x, y, z); if (checkCanAdd(pos)) { this.addResult(pos); } if (curCount >= minerConfig.blockLimit) return; waitUntil(); if (Thread.currentThread().isInterrupted()) return; } } } curRadius++; } } @Override public boolean checkCanAdd(Vector3i pos) { if (foundedPositions.contains(pos)) return false; Block block = player.worldObj.getBlock(pos.x, pos.y, pos.z); if (block.equals(Blocks.air) || block.getMaterial().isLiquid() || block.equals(Blocks.bedrock)) return false; Vector3i playerPos = new Vector3i((int) Math.floor(player.posX), (int) Math.floor(player.posY), (int) Math.floor(player.posZ)); if (pos.x == playerPos.x && pos.y == (playerPos.y - 1) && pos.z == playerPos.z) return false; if (!DeterminingIdentical.Identical(sampleBlock, sampleBlockMeta, sampleTileEntity, pos, player)) return false; boolean inRange = false; for (Vector3i position : foundedPositions) { Vector3i offsetDistance = new Vector3i(position).sub(pos); if (Math.abs(offsetDistance.x) <= minerConfig.smallRadius && Math.abs(offsetDistance.y) <= minerConfig.smallRadius && Math.abs(offsetDistance.z) <= minerConfig.smallRadius) { inRange = true; break; } } if (!inRange) return false; if (player.capabilities.isCreativeMode) return true; return block.canHarvestBlock(player, player.worldObj.getBlockMetadata(pos.x, pos.y, pos.z)); } } ``` -------------------------------- ### Individual Player Mining Manager (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt Manages the state and operations for a single player's chain mining. It tracks mining mode, player interactions, and collects dropped items to optimize performance. Key dependencies include `EntityPlayerMP`, `MinerConfig`, `MinerModeState`, `ItemStack`, and Forge's event bus for block events. ```java public class Manager { public EntityPlayerMP player; public final UUID playerUUID; public MinerConfig pConfig = new MinerConfig(); public MinerModeState minerModeState = new MinerModeState(); public boolean inPressChainKey = false; public boolean inOperate = false; public ArrayList drops = new ArrayList<>(); @SubscribeEvent public void onBlockBreakEvent(BlockEvent.BreakEvent event) { if (minerModeState.isInteractMode() || !isSamePlayer_checkOnServer(event.getPlayer(), playerUUID)) return; if (inOperate || !inPressChainKey) return; inOperate = true; Vector3i pos = new Vector3i(event.x, event.y, event.z); player = (EntityPlayerMP) event.getPlayer(); operator = new BaseOperator(pos, this); operator.registry(); } // Collect drops during chain mining to prevent lag from many item entities @SubscribeEvent public void onHarvestDropEvent(BlockEvent.HarvestDropsEvent event) { if (event.harvester == null || !isSamePlayer_checkOnServer(event.harvester, playerUUID)) return; if (!inOperate) return; for (ItemStack drop : event.drops) { // Merge with existing drops or add new boolean merged = false; for (ItemStack container : new ArrayList<>(drops)) { if (DeterminingIdentical.isSame(container, drop)) { container.stackSize += drop.stackSize; drop.stackSize = 0; merged = true; } } if (!merged) drops.add(drop); } event.drops.clear(); // Prevent original drops } } ``` -------------------------------- ### Player Manager Registration and Unregistration (Java) Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt Manages the lifecycle of individual player mining managers. It registers a new `Manager` instance when a player logs in and cleans up resources when a player logs out. Dependencies include `java.util.Map`, `java.util.HashMap`, `java.util.UUID`, and Forge's event bus (`@SubscribeEvent`). ```java public class PlayerManager { public Map managers = new HashMap<>(); @SubscribeEvent public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { if (event.player instanceof EntityPlayerMP playerMP) { Manager manager = new Manager(playerMP); managers.put(playerMP.getUniqueID(), manager); manager.registry(); LOG.info("Registered player: {}: {}", playerMP.getDisplayName(), playerMP.getUniqueID()); } } @SubscribeEvent public void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) { if (event.player instanceof EntityPlayerMP playerMP) { Manager manager = managers.get(playerMP.getUniqueID()); if (manager != null) { manager.unRegistry(); managers.remove(playerMP.getUniqueID()); } } } } ``` -------------------------------- ### Java MinerModeState Class for Mining Mode Management Source: https://context7.com/quanhuzeyu/qz-miner/llms.txt This Java class manages the state of different mining modes (Blast, Chain, Interact) and their sub-modes. It includes methods for cycling through main modes and creating appropriate position founder objects based on the current mode configuration. Dependencies include Vector3i, LinkedBlockingQueue, EntityPlayer, MinerConfig, and various PositionFounder classes. ```java public class MinerModeState { // Main modes: 0=Blast Mode, 1=Chain Mode, 2=Interact Mode public static final String[] MAIN_MODE = { "qz_miner.textTips.rangeMode", // Blast mode "qz_miner.textTips.chainMode", // Chain mode "qz_miner.textTips.interactMode", // Interact mode }; // Blast sub-modes public static final String[] RANGE_MODE = { "qz_miner.textTips.rangeMode.blindBlastMode", // Indiscriminate blast "qz_miner.textTips.rangeMode.screenBlastingMode", // Filtered blast "qz_miner.textTips.rangeMode.tunnelBlastingMode", // Tunnel blast "qz_miner.textTips.rangeMode.oreBlastingMode", // Ore blast "qz_miner.textTips.rangeMode.blastingLoggingMode", // Logging blast }; public int mainMode = 1; // Default to chain mode public int rangeMode = 0; public int chainMode = 0; public int interactMode = 0; // Cycle to next main mode public String nextMainMode() { mainMode = (mainMode + 1) % MAIN_MODE.length; return currentMainMode(); } // Create appropriate position founder based on current mode public BasePositionFounder createPositionFounder(Vector3i center, LinkedBlockingQueue results, EntityPlayer player, MinerConfig config) { switch (mainMode) { case 1: // Chain mode return new ChainPositionFounder(center, results, player, config); case 2: // Interact mode switch (interactMode) { case 3: return new LiquidDetector(center, results, player, config); case 4: return new CropFounder(center, results, player, config); default: return new ChainPositionFounder(center, results, player, config); } default: // Blast mode (0) switch (rangeMode) { case 2: return new TunnelBlastingFounder(center, results, player, config); case 3: return new OreBlastingFounder(center, results, player, config); default: return new BasePositionFounder(center, results, player, config); } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.