Custom Generation

Generate custom structure anywhere you want using LibuLib

Custom Generation is a pioneer to LibuLib, and here's some deep explanation to it:

Making your own generation

Creating the class

To start making your own generation system, you need to create a class that extends GenerationCore and implements IGenerator. It will be useful for you later on.

Your class should look like this:

import net.minecraft.block.Block;

public class YourClass extends GenerationCore implements IGenerator {
    // The structures are usually houses or square structures
    public YourClass(Block floor, Block walls, Block roof) {
        super(floor, walls, roof);
    }
}

Coding the structure

Once the first step is done, you will need to code the structure by simply doing the following.

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class YourClass extends GenerationCore implements IGenerator{
    public YourClass(Block floor, Block walls, Block roof) {
        super(floor, walls, roof);
    }

    @Override
    public void generate(World world, BlockPos origin) {
        super.generate(world, origin);
        
        // code the structure!
        world.setBlockState(origin.add(0, 1, 0), Blocks.DIAMOND_BLOCK.getDefaultState());
        
        // You can also variables and methods from GenerationCore to spice up your 
        // structure to have a fully configurable structure
    }
}

Testing the generation

After you think you've done something correct, you have to test it somehow. I recommend creating an item that, once right clicked, generates your structure. That's just a preference.

Simply do the following to generate your structure in a method:

import com.lumaa.libulibwiki.YourClass;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class SomeOtherClass {
    public void makeStructure(World world, BlockPos originPoint) {
        YourClass myClass = new YourClass(Blocks.PODZOL, Blocks.STONE, Blocks.BEDROCK);
        
        // Generates the structure you made
        myClass.generate(world, originPoint);
    }
}

Use an existant generation

As of right now, there is currently one default generation called the MazeCore, here's how to use it yourself.

Initiating MazeCore

Taking a new class, we will construct it:

import com.lumaa.libu.generation.MazeCore;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

// hopefully
public class OneLastClass {
    public MazeCore myMazeCore;

    public void initiateMazeCore() {
        // The last parameter (int) is the amount of rooms it should generate
        // It is called "iterations"
        myMazeCore = new MazeCore(Blocks.PODZOL, Blocks.STONE, Blocks.BEDROCK, 5);
        myMazeCore.setSize(13, 13);
        mazeCore.setHeight(3);
        
        // There are many other settings to play around!
    }
}

Generate the maze

In another class, just like in a previous section, you can simply do myMazeCore.generate(world, origin) to generate 5 rooms.

Last updated