TerraformGenerator Minecraft World Generator

repository·master·Indexed 43 days ago

https://github.com/hex27/terraformgenerator

A Minecraft world generator plugin in Alpha designed to provide an enhanced vanilla feel. It supports Paper and Spigot (1.21.9+), offering custom biomes and structures. The plugin includes a suite of diagnostic and testing commands for operators, such as /checkheight for noise map inspection, /biomedistrib for distribution statistics, and various spawning commands for trees and animal farms.

Tokens
12.8K
Snippets
51
Records
67
Agent score
55%

What's inside TerraformGenerator

  1. Build TerraformGenerator from source

    master

    To build the plugin manually using Gradle, clone the repository and run the shadowJar task.

    By default, for Minecraft 1.21.9 and up, the build command targets Paper.

    To build for Spigot, you must:

    1. Run Buildtools with --remapped for --rev 1.21.9 (and subsequent versions).
    2. Use the -PincludeSpigot=true flag in the Gradle command.
    git clone https://github.com/Hex27/TerraformGenerator.git
    cd TerraformGenerator
    # Default build (Paper)
    gradlew buildProj:shadowJar
    
    # Spigot build (requires Buildtools remapped first)
    gradlew buildProj:shadowJar -PincludeSpigot=true
  2. Configure TerraformGenerator via bukkit.yml

    master

    To use TerraformGenerator as the default generator for a specific world, you must manually add a worlds section to your bukkit.yml file. This is the recommended method.

    1. Stop the server.
    2. Open bukkit.yml.
    3. Add the worlds configuration (see example below).
    4. Delete the existing world folder if you want to regenerate it.
    5. Start the server.
    # By default does this section not exist within the bukkit.yml
    # and you have to add it yourself.
    worlds:
        world: # Replace this with the World name you want to use.
            generator: TerraformGenerator
  3. Create a world using Multiverse-Core

    master

    If you use a world management plugin like Multiverse-Core, you can create a new world using TerraformGenerator via in-game commands.

    Note: It is highly recommended to attempt 'Method One' (editing bukkit.yml) before using this method. If the world fails to load with the generator set, newly loaded chunks may revert to vanilla generation.

    1. Ensure the world does not already exist. If it does, delete it using /mvdelete <world> followed by /mvconfirm.
    2. Execute the following command to create the world: /mvcreate <world> normal -g TerraformGenerator
    /mvcreate <world> normal -g TerraformGenerator
  4. Use Schematic arguments in TerraformGenerator commands

    master

    When creating or using custom commands in TerraformGenerator, you can use the SchematicArgument to handle schematic file paths. This argument automatically attempts to load a TerraSchematic from the provided file path, using the sender's current location (if they are a Player) as the reference point for the SimpleBlock used during loading.

    If the file is not found or cannot be loaded, the argument will trigger a stack trace in the plugin logger and return a validation error: Problem loading schematic. Check console for error.

    // Example of how a SchematicArgument might be instantiated in a command definition
    new SchematicArgument("schematic_path", false);
  5. Validate schematic filenames in commands

    master

    When implementing or using commands that accept a schematic filename as an argument, the FilenameArgument class ensures the provided value is a valid file within the plugin's designated schematic folder.

    To be considered valid, the filename must:

    1. Exist within the TerraformGeneratorPlugin data folder under the directory defined by TerraSchematic.SCHEMATIC_FOLDER.
    2. Not contain illegal characters that would allow directory traversal (e.g., it must not attempt to escape the schematic folder via canonical path manipulation).
    3. Not end with a path separator.

    If validation fails, the argument returns the error message: Schematic name contained illegal characters (i.e. periods).

  6. Implement custom command arguments with TerraCommandArgument

    master

    To create custom command arguments for the Terraform generator CLI, extend the TerraCommandArgument<T> abstract class. You must implement the parse and validate methods to define how a string input is converted into your desired type T and how it is validated against business rules.

    Additionally, you can override getTabOptions to provide suggestions for command tab-completion.

    public class MyCustomArgument extends TerraCommandArgument<Integer> {
        public MyCustomArgument(String name, boolean isOptional) {
            super(name, isOptional);
        }
    
        @Override
        @Nullable
        public Integer parse(CommandSender sender, String value) {
            // Logic to convert String to Integer
            return Integer.parseInt(value);
        }
    
        @Override
        public String validate(CommandSender sender, String value) {
            // Logic to validate the value; return error message if invalid
            return ""; 
        }
    
        @Override
        @NotNull
        public ArrayList<String> getTabOptions(String[] args) {
            // Logic to return tab-completion suggestions
            return new ArrayList<>(List.of("option1", "option2"));
        }
    }
  7. Parse and validate command arguments

    master

    Within a TerraCommand implementation, use parseArguments(CommandSender sender, Stack<String> args) to convert raw string arguments into a list of typed objects based on the command's defined parameters.

    This method performs the following:

    1. Iterates through the provided args stack.
    2. Uses the corresponding TerraCommandArgument to parse and validate each input.
    3. Throws an InvalidArgumentException if parsing fails or validation returns a non-empty error string.

    Returns an ArrayList<Object> containing the successfully parsed values.

    @Override
    public void execute(CommandSender sender, Stack<String> args) throws InvalidArgumentException {
        ArrayList<Object> parsedValues = parseArguments(sender, args);
        // Use parsedValues to perform command actions
    }
  8. Send synchronized messages and clickable teleport links

    master

    The TerraCommand class provides protected utility methods for sending feedback to players and logging to the server console:

    • syncSendMessage(UUID uuid, String prefix, String message): Sends a plain text message to a specific player (matching the provided UUID) and logs the message to the TerraformGeneratorPlugin.logger with the specified prefix.
    • syncSendMessageTP(UUID uuid, String prefix, String message, int x, int y, int z): Sends a clickable message to a specific player. Clicking the message will automatically execute the command /tp <x> <y> <z>. The message is also logged to the server console.

    Note: These methods only send the message to the player if they are currently online.

    // Example: Sending a clickable teleport link
    syncSendMessageTP(player.getUniqueId(), "TERRA", "Click here to teleport!", 100, 64, 100);
  9. Implement a custom TerraCommand

    master

    To create a new command for the Terraform Generator, extend the TerraCommand abstract class. You must provide implementations for the following abstract methods:

    • getDefaultDescription(): Returns a String describing the command.
    • canConsoleExec(): Returns a boolean indicating if the command can be executed by the server console.
    • hasPermission(CommandSender sender): Returns a boolean determining if the sender has the required permissions to run the command.
    • execute(CommandSender sender, Stack<String> args): The core logic of the command. It is called when the command is matched and the arguments are valid. It throws an InvalidArgumentException if the arguments are incorrect.

    Commands use an aliases list for identification and a parameters list of TerraCommandArgument<?> to define expected input types and validation rules.

    public class MyCustomCommand extends TerraCommand {
        public MyCustomCommand(TerraformGeneratorPlugin plugin) {
            super(plugin, "mycommand", "mc");
        }
    
        @Override
        public String getDefaultDescription() {
            return "A description of my command";
        }
    
        @Override
        public boolean canConsoleExec() {
            return true;
        }
    
        @Override
        public boolean hasPermission(CommandSender sender) {
            return sender.hasPermission("terraform.command.mycommand");
        }
    
        @Override
        public void execute(CommandSender sender, Stack<String> args) throws InvalidArgumentException {
            // Command logic here
        }
    }
  10. Use Fractal Tree Type arguments in CLI commands

    master

    When constructing or using commands that require a fractal tree type, the FractalTreeTypeArgument class handles the parsing and validation of tree types.

    • Parsing: The argument accepts a string and converts it to a FractalTypes.Tree enum value. The input is case-insensitive (it is converted to uppercase using Locale.ENGLISH).
    • Validation: If an invalid string is provided, the command will return the error message: Tree type does not exist!.
    • Tab Completion: When using command tab-completion, the available options are derived from the FractalTypes.Tree enum values. The completion logic filters options based on the prefix provided in the second argument of the command.
    // The argument parses input into a FractalTypes.Tree enum
    // Example input: "oak" -> FractalTypes.Tree.OAK
    // Invalid input returns: "Tree type does not exist!"