Mod

Liby

Quick rating

Liby

No reviews yet

Registration and MultiBlock Library

No Theme
No Genre
API/Library
Mod Loaders
Fabric
Minecraft

Community voices

Reviews

Versions
Loading versions…
Match includes

Click once to include, again to exclude, again to clear

Rating Any
Any 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
Min
Max
Play Status
Reviews
Time Played
hrs+
Verified developers only
Has developer response
List view
Grid view
Compact view
Sort by
Date
Rating
Helpful
Unhelpful
Edited
Sort ascending
Delete this review?

This removes your review from the project. You can write a new review after.

Review submitted for moderation

Your review has been sent to moderators, who will check that it meets our guidelines before it appears publicly.

No reviews yet. Be the first to review this project!

Get it on

Available Platforms

Compatibility

Supported Environments

Dev Environment
Client Required
Server Required

About

Project Details

Type
Mod
License
GNU General Public License v3.0 or later
Latest Version
liby-1.20.1-build-1.0.jar
Authors
CurseForge
Modrinth

For authors

Embed Badge

If you're the author of this project, you can embed a live badge anywhere that supports HTML or Markdown. It updates automatically whenever ratings change.

Custom banner text
ModDex rating badge preview

Use HTML for any page that supports it, or Markdown for README files and Markdown-based descriptions.

Identifiers

Platform IDs

CurseForge ID
Modrinth ID

Resources

External Links

About

Description

This mod serves as a utility for developers and does not add any content on its own. It is a required dependency for other mods.

How to Add Liby to Your Project

Step 1: Add the CurseMaven Repository To download Liby from CurseMaven, you first need to add the repository to your build.gradle file:

repositories {
    maven {
        url "https://cursemaven.com"
    }
}

Step 2: Add the Liby Dependency

  1. Find the Correct Maven Snippet:
  • Navigate to the Files section and find the version compatible with your Minecraft setup.
  • Expand the Curse Maven Snippet for the version you need.
  • Copy the provided Maven snippet.
  1. Add the Dependency:
  • After copying the snippet, add it to the dependencies block in your build.gradle. Here’s an example:
dependencies {
    // Add the Liby dependency using the Maven snippet
    modImplementation "curse.maven:liby-1115157:5783866"

    // Liby dependency
    implementation "org.reflections:reflections:0.10.2"
}

How to Use Liby

To utilize the Liby library for registering your mod's elements, follow these steps:

Define the Package for Registries: Start by specifying the package where Liby will search for your registries.

package group.your_fabric_mod;

import net.fabricmc.api.ModInitializer;
import nazario.liby.registry.auto.LibyRegistryLoader;
import net.minecraft.util.Identifier;

public class YourFabricMod implements ModInitializer {

    public static final String MOD_ID = "your_fabric_mod";

    @Override
    public void onInitialize() {
        LibyRegistryLoader.load("group.your_fabric_mod.registry");
    }

    public static Identifier id(String name) {
        return Identifier.of(MOD_ID, name);
    }
}

Set Up Your Registry: Next, create a registry for blocks.

package group.your_fabric_mod.registry;

//This tells Liby to register this class
@LibyAutoRegister
public class BlockRegistry {
    public static final LibyBlockRegister REGISTER = new LibyBlockRegister(YourFabricMod.MOD_ID);

    public static Block BASIC_BLOCK = REGISTER.registerBlock("basic_block", new Block(AbstractBlock.Settings.create()));
    public static Block BLOCK_WITH_ITEM = REGISTER.registerBlock("block_with_item", new Block(AbstractBlock.Settings.create()), new Item.Settings());

    public static void register() {
     
    }
}

Registering Items: Register items similarly to blocks.

package group.your_fabric_mod.registry;

@LibyAutoRegister
public class ItemRegistry {
    public static final LibyItemRegister REGISTER = new LibyItemRegister(YourFabricMod.MOD_ID);

    public static Item BASIC_ITEM = REGISTER.registerItem("basic_item", new Item(new Item.Settings()));

    public static void register() {
    
    }
}

Setting Registration Priority: If you want blocks to register before items, adjust the @LibyAutoRegister annotation as follows:

@LibyAutoRegister(priority = 1)

Higher priority values ensure that items are registered after blocks.

Handling Item Groups: Liby has a specific way for managing item groups.

@LibyAutoRegister(priority = 2)
public class ItemGroupRegistry {

    public static final LibyItemGroupRegister REGISTER = new LibyItemGroupRegister(ResearchFrontiers.MOD_ID);

    public static final LibyItemGroup ITEM_GROUP = new LibyItemGroup("group", Text.translatable("your_fabric_mod.itemGroup"), new ItemStack(ItemRegistry.BASIC_ITEM));


   public static void register() {
       ITEM_GROUP.addItem(ItemRegistry.BASIC_ITEM, BlockRegistry.BLOCK_WITH_ITEM);

       REGISTER.registerItemGroups(ITEM_GROUP);
   }
}

Since the item group has an icon, ensure items are registered first by setting the priority of ItemGroupRegistry to 2.

Additional Information on Registration

If you prefer not to name each registration method register, you can specify a custom method name directly in the @LibyAutoRegister annotation. This allows for more descriptive method names that can enhance code readability and organization.

@LibyAutoRegister(priority = 2, register = "registerItemGroup")
public class ItemGroupRegistry {
    public static void registerItemGroup() {
        // Registration logic for item groups
    }
}

If you prefer to keep all your registrations within your registry package, and you also want to handle client-side registration there, you need to include a LibyEntrypoint in the @LibyAutoRegister annotation. (The default Entrypoint is MAIN)

@LibyAutoRegister(priority = 0, entrypoint = LibyEntrypoints.CLIENT)
public class ClientRegistry {
    public static void register() {
        
    }
}

Creating Multiblocks with Liby

Liby provides a simple way for creating multiblocks. To get started, you need to define a BlockEntityRegistry.

Step 1: Define the Block Entity Registry

Create a class for your block entities and use the @LibyAutoRegister annotation to register it.

@LibyAutoRegister(priority = 3)
public class BlockEntityRegistry {
    public static final LibyBlockEntityRegister REGISTER = new LibyBlockEntityRegister(ResearchFrontiers.MOD_ID);

    public static BlockEntityType<WorkbenchBlockEntity> WORKBENCH_BLOCK_ENTITY = 
        REGISTER.registerType("workbench", BlockEntityType.Builder.create(WorkbenchBlockEntity::new, BlockRegistry.WORKBENCH).build());

    public static void register() {
        // Additional registration logic can be added here
    }
}

Step 2: Create the Workbench Block

Define the WorkbenchBlock class, which extends LibyMultiBlock. Here, you initialize an array of BlockPos to define the positions that make up the multiblock structure. (Due to minecraft limitations on block model sizes 3x3x3, you should consider using GeckoLib for the model)

public class WorkbenchBlock extends LibyMultiBlock {
    public WorkbenchBlock(Settings settings) {
        super(settings, new BlockPos[]{
            new BlockPos(0, 0, 0), // Parent block position
            new BlockPos(-1, 0, 0)  // Child block position
        });
    }

    @Override
    protected MapCodec<? extends BlockWithEntity> getCodec() {
        return createCodec(WorkbenchBlock::new);
    }

    @Override
    public @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
        return new WorkbenchBlockEntity(pos, state);
    }
}

Step 3: Create the Workbench Block Entity

Next, implement the WorkbenchBlockEntity class, which extends LibyMultiBlockEntity. This class represents the block entity associated with the WorkbenchBlock.

public class WorkbenchBlockEntity extends LibyMultiBlockEntity {
    public WorkbenchBlockEntity(BlockPos pos, BlockState state) {
        super(BlockEntityRegistry.WORKBENCH, pos, state);
    }
}

Key Points

  • In the WorkbenchBlock class, the BlockPos array specifies the positions of the blocks that make up the multiblock structure. The first entry should always represent the parent block.
  • Multiblock structures are from the start horizontal directional.

Step 4: Player interactions

Now we want the player to be able to right click our Workbench, for that you need to override onMultiBlockUse, inside WorkbenchBlock.

    @Override
    public ActionResult onMultiBlockUse(World world, BlockState clickedState, BlockState parentState, BlockPos clickedPos, BlockPos parentPos, PlayerEntity player, BlockHitResult hit) {
        if(world.isClient) return ActionResult.PASS;
        
        player.sendMessage(Text.literal("Hello from Workbench!"));
        
        return ActionResult.SUCCESS;
    }

Notice

When creating multiblock structures larger than the standard 3x3x3 block model limit in vanilla, you may encounter weird lighting issues. These issues arise because the game’s lighting engine thinks your childs blocks are solid, even tho there are invisible and don't render any model at all. To fix these issues we will tell the game that the childs blocks are transparent like glass, this will stop the light engine from drawing shadows on our model texture.

    @Override
    protected int getOpacity(BlockState state, BlockView world, BlockPos pos) {
        return state.get(PARENT)?super.getOpacity(state, world, pos):0;
    }

    @Override
    protected float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
        return state.get(PARENT)?super.getAmbientOcclusionLightLevel(state, world, pos):1;
    }

Networking (Experimental)

If you have a variable that needs to be synced across all players, Liby provides a simple solution for that.

To sync a variable over the network, you need to annotate it with @LibySyncedValue. The class inside the parentheses should correspond to the data type of the variable. (Not all variables are supported—generally, all primitive data types are supported, along with String, BlockPos, Vec3d, Vec3i, Vec2f, and NbtCompound.)

public class SyncedBlock extends Block {

    // Annotates the variable to sync its value across the network, specifying Integer as its data type
    @LibySyncedValue(Integer.class) 
    public int clicksValue;

    public SyncedBlock(Settings settings) {
        super(settings);
    }

    // Called when the block is right-clicked by a player
    @Override
    protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {

        // Sends a message to the player, showing whether the action occurred on the Client or Server, and displays the current clicksValue
        player.sendMessage(Text.literal("<" + (world.isClient ? "Client" : "Server") + "> Value: " + clicksValue));

        // Increases the clicksValue by 1 on the server side and syncs the new value across all players
        if (!world.isClient) {
            this.clicksValue += 1; // Increment the value
            LibyNetworker.syncBlock(world, pos, this); // Sync the updated value with all players
        }

        return super.onUse(state, world, pos, player, hit);
    }
}

GithubLinkImage CurseForgeLinkImage

This mod serves as a utility for developers and does not add any content on its own. It is a required dependency for other mods.

Major version changes like 1.0 to 2.0 will break most mods using the older version, wait for an update from their mod author.

How to Add Liby to Your Project

Step 1: Add the ModrinthMaven Repository To download Liby from ModrinthMaven, you first need to add the repository to your build.gradle file:

repositories {
    maven {
        name = "Modrinth Maven"
        url = "https://api.modrinth.com/maven"
    }
}

Step 2: Add the Liby Dependency

  • Navigate to the Version section and find the version compatible with your Minecraft setup.
  • Copy the version number.
  1. Add the Dependency:
    modImplementation "maven.modrinth:liby:<version>"

After this the snippet, add it to the dependencies block in your build.gradle. Here’s an example:

dependencies {
    // Add the Liby dependency using the Maven snippet
    modImplementation "maven.modrinth:liby:1.21.1-build-2.1.1"

    // Liby dependency
    implementation "org.reflections:reflections:0.10.2"
}

For a full breakdown checkout the wiki

Links

GithubLinkImage CurseForgeLinkImage

Screenshots

Gallery

  • RequiresLibyBadge
    RequiresLibyBadge

Versions

Files

Relations

Project Relations

More like this

Similar Mods

Suggestions use data such as tags, dependencies, dependents, descriptions, titles, and more to rank how much they overlap with this mod.

On ModDex

Community snapshot

0
Ratings
0
Followers
0
In stacks

By the numbers

Statistics

~110,000
Total Downloads
CurseForge
~5,000
Modrinth
~110,000
Last Updated
CurseForge
Created
CurseForge
Modrinth
Last synced
When ModDex last fetched and imported data for this project from CurseForge or Modrinth. High-traffic and active projects are checked more often.
Next pipeline sync