Qz-Miner Documentation

repository·5.0重构·Indexed 42 days ago

https://github.com/quanhuzeyu/qz-miner

A chain mining mod for Minecraft 1.7.10 Forge/GTNH environments. Features automated mining modes (Chain, Area, Interact, Special), client-side previews, and high compatibility with GregTech-based ecosystems. Includes documentation on configuration semantics, server-side management via CLI, version compatibility boundaries, and installation requirements for Qz-UILib.

Tokens
39.3K
Snippets
37
Records
152
Agent score
52%

What's inside Qz-Miner

  1. Navigate Qz-Miner Documentation

    5.0重构

    The Qz-Miner documentation is organized into four distinct sections based on user needs. Use the following guide to find the information you require:

    • Root README: For users looking for installation instructions, basic operations, operational modes, and system limitations. Access via ../README.md.
    • Usage Documentation: For detailed information on configuration semantics and version compatibility boundaries. Access via 使用文档/README.md.
    • Developer Documentation: For understanding public API boundaries (identifying what is stable vs. unstable). Access via 开发者文档/README.md.
    • Troubleshooting (Pitfall Records): For diagnosing known issues and common faults. Access via 反馈层/errors/.
  2. Manage lifecycle of B0.3 publicationAwaitingConsumption gate patch

    5.0重构

    The publicationAwaitingConsumption consumption gate is a temporary patch for version B0.3.

    Deletion Criteria: This patch must be removed only when:

    1. The B4.1 incremental path is live.
    2. Differential testing has passed.

    The deletion logic/condition is documented in the field comments within ChainPreviewRenderCache.

  3. Understand why the main dev jar SHA256 changes after UILib updates

    5.0重构

    The main development JAR (qz_miner-<version>-dev.jar) acts as a joint fingerprint of both the Miner source code and the referenced UILib symbol surface used during compilation.

    If you replace a dependency (like UILib) with a version that has the same version number but different content (content drift), the main JAR's SHA256 will change if the changes affect symbols actually referenced by Miner.

    Key behaviors to note:

    • Expected Behavior: A change in the main JAR's SHA256 after updating a dependency is expected and does not indicate build instability, GC issues, or timestamp jitter.
    • Non-sensitive Artifacts: The -dev-dev.jar and -sources.jar artifacts are insensitive to UILib content changes and their SHA256 values should remain stable even if the main JAR changes.
    • Symbol Sensitivity: Only changes to symbols (classes/methods) that are actually referenced by the Miner source code will trigger a change in the main JAR's SHA256. Adding new classes or members to UILib that are not used by Miner will not change the main JAR's SHA256.
  4. Prevent Target Unbinding in Asynchronous Transactions

    5.0重构

    To prevent future occurrences of target unbinding and state inconsistency, follow these architectural principles:

    Best Practices

    • Immutable Transaction Chains: Target-driven asynchronous transactions must bind "Input Identity — Candidate — Transaction Expectation" into a single immutable chain. Do not re-read runtime targets mid-transaction.
    • Orthogonal Protocol and Inventory Write Authority: Keep client read-only access and server-side single-ledger authority orthogonal. Any re-matching must not append a normal SWAP onto an old ledger.

    Required Regression Test Cases

    Ensure the following scenarios are covered in testing:

    • Target transitions: A→B→C and A→B→A.
    • In-flight operations: SWAP/RESTORE during transitions.
    • Metadata/Coordinate changes: Same block/meta with different coordinates, or changes in metadata.
    • Timing sensitivity: 1/2 tick ABSENT scenarios.
    • Priority handling: GUI, re-anchor, FROZEN, and reset priorities.
  5. Understand the Four-Level Drop Release Fallback Chain

    5.0重构

    To prevent item loss and infinite loops, the system uses a four-level fallback mechanism when attempting to release drops. If a level fails, the system increments a failure counter and moves to the next level. If all levels fail, the items are discarded to prevent a dead loop.

    The Fallback Hierarchy

    1. Level 1: Current Player Position (releaseAtPlayer): Attempts to spawn drops at the player's current location.
    2. Level 2: Respawn/World Spawn (releaseAtRespawnOrWorldSpawn): Attempts to spawn at the player's respawn point or the world spawn if the current chunk is unavailable.
    3. Level 3: Remembered Target (releaseAtRememberedTarget): Uses a fallback coordinate pre-stored during the initial onHarvestDrops event.
    4. Level 4: Discard (discard): If the failure count reaches DROP_RELEASE_MAX_RETRIES (default: 100), the items are discarded with a diagnostic reason (e.g., "world-tick-release-exhausted" or "world-tick-missing-exhausted") to stop the loop.

    Implementation Details

    • Failure Counting: Failures are tracked via dropReleaseConsecutiveFailures in ChainPlayerState. This counter must be reset using clearRuntimeState when a player respawns, changes dimensions, or relogs to prevent stale counts from affecting new sessions.
    • Retry Limit: The constant DROP_RELEASE_MAX_RETRIES = 100 provides a window of approximately 5 seconds (at 20 TPS) for chunks to load before giving up.
  6. Understand v4 AutoTool takeover and publication boundaries

    5.0重构

    In version 4, the handling of takeover requests and publication synchronization has been redesigned to prevent race conditions.

    Takeover Request Separation

    • TAKEOVER and DECLINE actions are no longer part of the standard actionSequence. They now use a dedicated takeoverRequestId.
    • CLOSE, RESTORE, and ABANDON actions can now retire uncommitted waiting gates only after the standard sequence is precisely validated. They are no longer blocked by request-local deadlines or target drift.

    Publication Synchronization Rules

    • Once a mutation or an ActionResult is in the exact publication pending state, standard lifecycle actions (CLOSE, RESTORE, ABANDON, deadline, release, or IDLE) must not preempt the submission point.
    • These actions must wait for the result to be reliably published. Only hard lifecycle events (disconnection, rebirth, dimension switching, or service shutdown) can directly destroy these records.
    • This prevents the 'inventory modified but result/ledger forgotten' race condition.

    Recovery Behavior

    • When waiting for publication, the target remains at peek and the Coordinator returns WAIT. The system does not publish a fake ExecutionAdvanced.
    • If full inventory synchronization or the ActionResult sender fails, the system performs an exact retry rather than replaying the mutation.
    • For detailed recovery contracts, refer to ERROR-20260725-auto-tool-request-sync-recovery.md.
  7. Understand the retired GTNH baseline mechanism

    5.0重构

    As of 2026-09-11, the multi-baseline matrix mechanism in Qz-Miner has been retired. The project has moved from a matrix-based compatibility commitment to a single-baseline declaration.

    Key Changes:

    • Single Source of Truth: The GTNH baseline is now declared via a single value in dependencies.gradle using the elytraModpackVersion block.
    • Removed Files/Tasks:
      • gradle/gtnh-baselines.json is no longer used.
      • scripts/verify-gtnh-baselines.ps1 has been deleted.
      • The verifyGtnhBaseline task in build.gradle.kts has been deleted.
      • branch-ci.yml no longer contains a baseline matrix or the prepare-baselines step.
      • release-tags.yml no longer parses baseline lists.
    • Removed CLI Parameters: The following parameters are no longer passed during CI:
      • -Pelytra.manifest.version
      • -Pqz.gtnh.*

    Current Compatibility Model: Compatibility is now verified via source-level checks (ensuring zero static linking to GTNH-side components) and dual-baseline testing (compileJava and compileTestJava) for versions like 2.9.0-beta-2/beta-3. Note that runtime verification on actual hardware is not performed.

  8. Prevent tool recovery errors in inventory transactions

    5.0重构

    When designing inventory transactions to avoid lease and anchor mismatches, follow these best practices:

    1. Separate Semantic Comparisons: Do not reuse a single comparison function for different purposes. Explicitly name and test fresh exact (for request freshness) and lease role (for cross-round ownership).
    2. Comprehensive Test Matrix: Ensure tests cover:
      • Dynamic content changes (NBT, etc.).
      • stable subtype changes.
      • Empty slot occupation.
      • sameRole but stale intent.
      • ABANDON identity mismatches and idempotent replays.
    3. Empty Slot Lease Assertions: Tests for empty slot leases must assert that after a swap, the reference sets remain unchanged, and no items are merged, overwritten, or swallowed.
    4. Explicit Termination: Transactions that cannot be safely compensated must have an explicit, auditable, and zero-side-effect termination action. Never rely on a standard CLOSE to implicitly clear a ledger.
  9. Prevent transaction loss in auto-tool release paths

    5.0重构

    To ensure stability in automated tool operations, follow these architectural principles for handling sampling failures:

    1. Distinguish Sampling vs. Lifecycle: Distinguish between "fact is temporarily unsamplable" and "lifecycle has ended". If a sample fails during a key release, do not reset the lifecycle. Instead, preserve the transaction ledger and attempt a retry.
    2. Implement the Recovery Path: For inventory transactions, the release path should follow: null capture $\rightarrow$ RESTORE $\rightarrow$ CLOSE $\rightarrow$ next round.
    3. Monitor via Markers: Look for the following log marker to identify and debug failed capture attempts that are safely retrying: [AutoToolSwap] release fact capture failed; preserving round for retry.
  10. Understand GregTech MetaTile Binding Contracts

    5.0重构

    When working with GregTech (GT) MetaTile entities, you must adhere to specific API contracts regarding bidirectional binding to prevent Tile Entity (TE) failure and crashes.

    Binding Methods

    • setMetaTileEntity(IMetaTileEntity): Performs a unidirectional binding (base $\rightarrow$ meta). Using this alone will result in getBaseMetaTileEntity() returning null, causing NPEs in disconnect()/connect() and making the TE invalid.
    • setBaseMetaTileEntity(IGregTechTileEntity): Performs a bidirectional binding. This is the required method for replacing MetaTile instances to ensure both sides of the relationship are aware of each other.

    Connection State Management

    GT cable and pipe connection states are managed via a public byte mConnections bitmask rather than a complex state machine.

    • To restore connections during a replacement, you should directly copy the mConnections value from the old entity to the new one.
    • After updating the bitmask, you must call GregTechAPI.causeCableUpdate to rebuild the energy network graph (Node/NodePath).
    • Visual synchronization (textures/client-side updates) is handled by updating the mID and calling issueTextureUpdate and issueTileUpdate.
  11. Use TileIdentityToken to ensure identity consistency

    5.0重构

    To prevent identity loss during asynchronous planning, Qz-Miner uses an immutable pure value called TileIdentityToken. This token is designed to capture the identity of a TileEntity at the exact moment of the event.

    Key Characteristics of TileIdentityToken

    • Immutable and Pure: It does not contain references to TileEntity, World, Block, NBT, Class, or coordinates.
    • States: It uses three possible states:
      • PRESENT: The identity was successfully captured.
      • ABSENT: No identity was present.
      • UNRESOLVED: The identity could not be determined (e.g., due to an adapter failure).

    Implementation Requirements for Developers

    • Capture Timing: For BreakEvent, the seed TileEntity must be read on the server's main thread and immediately converted into a token.
    • Right-Click Resolution: For right-click interactions, you must resolve the semantic target before publishing the event:
      • For non-liquid BLOCKs: Use the event coordinates.
      • For AIR: You must use a side-neutral raycast to resolve the BLOCK hit. Never use the placeholder AIR coordinates as a seed.
      • For liquid BLOCKs/AIR: Use a raycast that includes liquids.
    • Propagation: Once captured, the Block, complete non-negative int metadata, and the TileEntityToken must be frozen and propagated through the state machine. The planning bridge must prioritize this frozen triplet over subsequent world reads.
    • Error Handling: If a reading error occurs, the state must be set to UNRESOLVED. Do not attempt to overwrite or guess the value using later world states in the next tick.
  12. Prevent drop loss by decoupling session state from player buffers

    5.0重构

    To prevent the loss of items during mining sessions, ensure that player-asset-level caches are not bound to a single session's runtime state.

    Architectural Best Practices

    • Session Responsibility: A ChainSession should only handle request parameters and a single execution process. It must not be responsible for cross-session asset caching.
    • Resource Lifecycle: When designing mechanisms for delayed settlement, delayed release, or delayed dropping, always attach them to a stable host (such as a player-level or global-level state) rather than a transient runtimeState.
    • Host Identification: When designing delayed resource release, explicitly define "who the host is" and "how to provide a fallback if the host terminates prematurely."