Ponder Library

repository·mc1.21.1/dev·Indexed 40 days ago

https://github.com/creators-of-create/ponder

A library for Minecraft mod developers to create interactive, in-game tutorials and guides. It provides tools for crafting detailed guides to showcase mod mechanics, including a Gradle plugin for JAR transformation, a rendering API via SuperByteBuffer, animation movement effects through the Force interface, and UI positioning tools with LayoutHelper. Supports Minecraft 1.20.1 and 1.21.1 across Fabric, Forge, and NeoForge.

Tokens
4K
Snippets
23
Records
24
Agent score
100%

What's inside Ponder

  1. Overview of Ponder

    mc1.21.1/dev
    Ponder is a library designed for Minecraft mod developers to create interactive, in-game guides. It allows you to craft detailed, engaging tutorials that showcase mod mechanics directly within the game, helping players learn how to use your mod's content effectively.
  2. Configure Maven repositories for Ponder

    mc1.21.1/dev

    To use Ponder, you must first add the Create maven repository to your repositories block in your Gradle build script.

    repositories {
        maven { url = "https://raw.githubusercontent.com/Fuzss/modresources/main/maven/" }
        maven { url = "https://maven.createmod.net" }
    }
  3. Apply the PonderGradlePlugin

    mc1.21.1/dev

    The PonderGradlePlugin is a Gradle plugin designed to automate the transformation of JAR files during the build process. It specifically handles the re-formatting of JSON and .mcmeta files to ensure consistent formatting and applies ASM transformations to .class files.

    When applied, the plugin hooks into the jar task. After the standard JAR creation is complete, it performs the following:

    1. Reads the existing JAR contents.
    2. Deletes the original JAR.
    3. Re-packages the contents with Deflater.BEST_COMPRESSION.
    4. Re-formats all .json and .mcmeta files using JsonOutput.
    5. Applies ASM transformations to all .class files via ASMTransformer.
    6. Filters out specific Architectury injectable files matching the pattern architectury_inject_${architecturyInjectableName}_common (where architecturyInjectableName is the project name, or rootProject.name_projectName if in a subproject).
    plugins {
        id("net.createmod.pondergradle")
    }
  4. Use SuperByteBuffer for rendering operations

    mc1.21.1/dev

    The SuperByteBuffer interface provides a fluent API for managing rendering state, including transformations, coloring, UV shifting, and lighting, before rendering into a VertexConsumer. It extends TransformStack, allowing for matrix transformations (rotation, translation, etc.) to be applied to the rendering pipeline.

    Key capabilities include:

    • Transformations: Use getTransforms() to access the PoseStack or use inherited transformation methods.
    • Coloring: Set vertex colors using color(int color) or color(int r, int g, int b, int a). It also supports a Color object via a default method.
    • UV Manipulation: Apply sprite shifts using shiftUV, shiftUVScrolling, or shiftUVtoSheet.
    • Lighting: Set manual light levels with light(int packedLight) or enable automatic level lookup from the world using useLevelLight(BlockAndTintGetter level).
    // Example of fluent usage
    superByteBuffer
        .reset()
        .color(Color.RED)
        .rotate(Direction.Axis.Y, 1.57f)
        .shiftUVScrolling(mySpriteEntry, 0.5f)
        .light(packedLightValue)
        .renderInto(poseStack, vertexConsumer);
  5. Use LayoutHelper for UI positioning

    mc1.21.1/dev

    The LayoutHelper interface provides tools for calculating the coordinates of UI elements in a grid or list. It is primarily used to manage the positioning of multiple items (like icons or buttons) within a container, ensuring they are spaced correctly and can be centered.

    To create a layout, use the static factory method centeredHorizontal. This creates a CenteredHorizontalLayoutHelper which distributes items across a specified number of rows, centering the entire block of items relative to a zero-point (often the center of a screen or container).

    Key methods:

    • getX(): Returns the current X coordinate for the next item.
    • getY(): Returns the current Y coordinate for the next item.
    • next(): Advances the internal cursor to the next position in the layout. If the end of the layout is reached, it resets to the start.
    • getArea(): Returns a Rect2i representing the bounding box of the entire layout, centered on (0,0).
    // Create a centered horizontal layout with 10 items, 2 rows, 
    // each item being 18x18 pixels, with 2 pixels of spacing.
    LayoutHelper layout = LayoutHelper.centeredHorizontal(10, 2, 18, 18, 2);
    
    // Iterate through items to get their positions
    for (int i = 0; i < 10; i++) {
        int x = layout.getX();
        int y = layout.getY();
        
        // Render item at (x, y)...
        
        layout.next();
    }
    
    // Get the total area occupied by the layout
    Rect2i bounds = layout.getArea();