Coder Social home page Coder Social logo

registrate's Introduction

Registrate Build Status License Maven Version Minecraft Version Discord

A powerful wrapper for creating and registering objects in your mod.

Why Registrate?

  • Allows you to organize your mod content however you like, rather than having pieces of each object defined in scattered places
  • Simple fluent API
  • Open to extension, build and register custom objects and data
  • Automatic data generation with sane defaults
  • Shadeable, contains no mod, only code

How to Use

First, create a Registrate object which will be used across your entire project.

public static final Registrate REGISTRATE = Registrate.create(MOD_ID);

Using a constant field is not necessary, it can be passed around and thrown away after registration is setup.

Next, begin adding objects.

If you have a block class such as

public class MyBlock extends Block {

    public MyBlock(Block.Properties properties) {
        super(properties);
    }
    
    ...
}

then register it like so,

public static final RegistryEntry<MyBlock> MY_BLOCK = REGISTRATE.object("my_block")
        .block(MyBlock::new)
        .register();

Registrate will create a block, with a default simple blockstate, model, loot table, and lang entry. However, all of these facets can be configured easily to use whatever custom data you may want. Example:

public static final RegistryEntry<MyStairsBlock> MY_STAIRS = REGISTRATE.object("my_block")
        .block(MyStairsBlock::new)
            .defaultItem()
            .tag(BlockTags.STAIRS)
            .blockstate(ctx -> ctx.getProvider()
                .stairsBlock(ctx.getEntry(), ctx.getProvider().modLoc(ctx.getName())))
            .lang("Special Stairs")
            .register();

This customized version will create a BlockItem (with its own default model and lang entry), add the block to a tag, configure the blockstate for stair properties, and add a custom localization.

To get an overview of the different APIs and methods, check out the Javadocs. For more advanced usage, read the wiki (WIP).

Project Setup

Registrate can be installed in the mods folder as a typical dependency, but since it does not have a mod, it can also be shaded. Shading is the recommended way to include Registrate (at least until Forge jar-in-jar is working again).

This is easiest with the Gradle Shadow plugin. Add the plugin to your buildscript like so:

plugins {
    id 'com.github.johnrengelman.shadow' version '5.2.0'
}

Note: Shadow 5.1+ requires Gradle 5.x. I recommend 5.6 as I know this version works with both Shadow and FG3.

Once you have the plugin, it needs to be configured. First add a shade configuration,

configurations {
    shade
}

configure the shadowJar task use it, and repackage Registrate classes.

shadowJar {
    configurations = [project.configurations.shade]
    relocate 'com.tterrag.registrate', 'com.mymod.repack.registrate'
}

Finally, the dependency itself must be added. First add my maven repository,

repositories {
    maven { // Registrate
        url "http://maven.tterrag.com/"
    }
    mavenLocal()
}

and then the Registrate dependency to the implementation and shade configurations.

dependencies {
    minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" // This should already be here
    
    def registrate = "com.tterrag.registrate:Registrate:MC${minecraft_version}-${registrate_version}"
    implementation fg.deobf(registrate)
    shade registrate
}

Note: Registrate will not function properly on the classpath unless you use Forge 28.1.104+

To build the jar containing shaded dependencies, use the shadowJar task.

registrate's People

Contributors

tterrag1098 avatar coffeecatrailway avatar dliberalesso avatar noobanidus avatar rosaqq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.