# Custom Generation

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

## Making your own generation

{% hint style="warning" %}
The following content is the recommended way to do it.\
You can also try and play around with classes and `IGenerator`
{% endhint %}

### 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:

{% code lineNumbers="true" %}

```java
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);
    }
}
```

{% endcode %}

### Coding the structure

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

{% code lineNumbers="true" %}

```java
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
    }
}
```

{% endcode %}

### 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:

{% code lineNumbers="true" %}

```java
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);
    }
}
```

{% endcode %}

## 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

{% hint style="warning" %}
The `MazeCore` is still under development and some features from it might change in the future.
{% endhint %}

Taking a new class, we will construct it:

{% code lineNumbers="true" %}

```java
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!
    }
}
```

{% endcode %}

### Generate the maze

In another class, just like in [a previous section](#testing-the-generation), you can simply do `myMazeCore.generate(world, origin)` to generate 5 rooms.
