Skip to content
/ gimm1q Public

Mim1q's collection of utilities for Fabric modding

License

Notifications You must be signed in to change notification settings

mim1q/gimm1q

Repository files navigation

Gimm1q

Mim1q's common utilities library for Minecraft Fabric mods.
The name is a play on the word "gimmick" and my nickname "Mim1q" 😁

Table of contents

Goals

  • Provide a set of utilities that could be useful in most content-adding mods;
  • Keep the size small to enable inclusion in any mod;
  • Keep the code simple, clean, and well-documented with examples.

Implemented features

The codebase is thoroughly documented, so you can check out the source code (and the Testmod) for more details about any of the features.

Screen shaking effects

Players' screens can be shaken during any event with a simple server-side function call.

public void someExplosionEvent(ServerWorld world, Vec3d explosionPos) {
    // ...
    // Shake the screen of all players in a 10-block radius
    ScreenShakeUtils.shakeAround(
        world,         // The world where the shake happens
        explosionPos,  // The position of the shake's center
        1.0f,          // The maximum intensity of the shake
        20,            // The duration of the shake in ticks
        5.0f,          // The inner radius of the shake in blocks (max intensity)
        10.0f,         // The outer radius of the shake in blocks (0 intensity)
        "explosion"    // The "modifier" of the shake
    );
    // ...
}

The last argument is a "modifier" that can be set during mod initialization to allow players to multiply a screen shake event's intensity using their config files or any other way, for example:

@Override
public void onInitialize() {
    // load the config etc...
    ScreenShakeModifiers.setModifier("explosion", CONFIG.explosionScreenShakeIntensity);
}

Block and entity highlighting

You can register a callback to a Highlight Event that will be called every frame and will let you highlight blocks, entities or arbitrary boxes in the world using your chosen color and logic.

An example of highlighting an entity with a black outline and transparent fill color:

@Override
public void onInitializeClient() {
    HighlightDrawerCallback.register((drawer, context) -> {
        var entity = /* select the entity to highlight */;
        drawer.highlightEntity(
            entity,     // The entity to highlight
            0x00000000, // The color of the highlight (0xAARRGGBB)
            0xFF000000  // The color of the outline (0xAARRGGBB)
        );
    });
}

In-GUI Item Highlighting

You can also highlight items in the player's hotbar and inventory using a similar callback:

@Override
public void onInitializeClient() {
    GuiHighlightDrawerCallback.register((drawer, context) -> {
        var stack = context.stack();
        if (stack.isIn(HIGHLIGHTED_ITEMS_TAG)) {
            // Highlight the item with a custom texture, using a magenta color
            drawer.highlightItem(
                0,                       // Horizontal offset in pixels
                0,                       // Vertical offset in pixels
                32,                      // Highlight size in pixels
                0xFFFF00FF,              // Highlight color (0xAARRGGBB)
                CUSTOM_HIGHLIGHT_TEXTURE // Texture Identifier
            );
        }
    });
}

Crosshair tips

Another feature is the ability to display a little tooltip next to the crosshair using a callback, just like the two above.

@Override
public void onInitializeClient() {
    CrosshairTipDrawerCallback.register((drawer, context) -> {
        var player = context.player();
        if (player.isSneaking()) {
            // Draw a custom tip texture, offset by 16 pixels to the right
            drawer.drawCrosshairTip(
                16,                           // Horizontal offset in pixels
                0,                            // Vertical offset in pixels
                PLAYER_SNEAKING_CROSSHAIR_TIP // Texture Identifier
            );
        }
    });
}

Animation and interpolation utilities

The library provides a set of utilities for creating very simple animations and interpolating values.

The dev.mim1q.interpolation.Easing class provides a set of common easing functions (with more likely to come!).

The dev.mim1q.interpolation.AnimatedProperty class lets you create a single-float-value property that can be changed over time using a specified easing function and duration.

Handheld item model registering

Gimm1q allows you to register items that will have a different model when held in the player's hand from the one they have in the GUI - sort of like the vanilla Spyglass and Trident items.

@Override
public void onInitializeClient() {
    HandheldItemModelRegistry.getInstance().register(
        // The item to register
        SOME_ITEM,                                    
        // The GUI model identifier (without the `item/` prefix!)
        new Identifier("modid", "gui/some_item"),     
        // The handheld model identifier (as above)
        new Identifier("modid", "handheld/some_item") 
    );
}

This will load the declared models for you and automatically render the correct one depending on the context.

Possible future features

(may or may not be implemented in the future)

  • Easier way to create particles with a color parameter
  • Simple camera utils (for cutscenes etc.)

Usage

Gimm1q uses a maven repository for distribution. To use it in your mod, add the following to your build.gradle.kts file's dependencies and repositories sections:

repositories {
    maven("https://maven.mim1q.dev") // Maven repository for Gimm1q
}

dependencies {
    modImplementation(include("com.github.mim1q:gimm1q:${Versions.GIMM1Q}")!!)
}

Replace ${Versions.GIMM1Q} with the version you want to use. The available version can be found here.

Alternatively you can head to the releases page, download the jar manually and figure out how to include it in your project from that point 😉

License

This project is licensed under the MIT License - see the LICENSE file for details.