LotsOfPixelsStudios / Monstera

A library and dev environment designed to streamline the development of Minecraft addons.
https://monstera.lotsofpixelsstudios.com/
GNU General Public License v3.0
2 stars 1 forks source link
kotlin-dsl minecraft minecraft-addons minecraft-bedrock-edition

Monstera 🌱

Status: We are still migrating, although we are mainly looking for bugs. For smaller projects, this project is usable in production.

A library and environment designed to streamline the development of Minecraft addons.

Licence Notice 🎫

We have released this library under the GPL-3.0 licence, we are aware of the limitations of this licence, so we want to clarify what we want to achieve with this licence:

Getting Started

See the template project at https://github.com/LotsOfPixelsStudios/MonsteraTemplate

If you have already a kotlin project add the dependency

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.lotsofpixelsstudios:monstera:0.4.3")
}

Goal 🏆

Contributing

Note to all contributors: We may wish to change the licence as stated in the Licence section, therefore we as Lots of Pixels Studios reserves the right to change the licence as we see fit without consulting you independently.

Files 📁

In this package we reconstruct Minecraft files as they end up in the addon using a DSL.

For each type of file you will find a class that usually contains the format version in the inner class FileHeader, most of these classes extend the open class MonsteraRawFile. This class contains a simple map where a developer can add missing keys that are needed. To prevent Gson from parsing the map name additionalKeys, a custom JsonSerializer was written and applied to the defined Gson instance in the MonsteraBuilder object.

Different types of files you might encounter:

class SomeFile : MonsteraBuildableFile, MonsteraRawFile() {

    //default for basic buildable files, returns the path where the final file was built to
    override fun build(filename: String, path: Path?, version: String?): Result<Path> { }

    data class FileHeader(

        //gson will take this name as the key for the json element
        @SerializedName("format_version")

        //gson is set to exlude every field that is missing this annotation
        @Expose

        //basic information for minecraft - is contained in the json output
        var formatVersion: String = "1.10.0",

        @SerializedName("minecraft:some_file")
        @Expose

        //this type adapter annotation tells gson to parse the additional keys seperatly
        @JsonAdapter(MonsteraRawFileTypeAdapter::class)
        var myFile: SomeFile
    ) : MonsteraRawFile()
}
class SomeFile {
    override fun build(filename: String, path: Path?, version: String?): Result<Path> {  }

    @SerializedName("format_version")
    @Expose
    var formatVersion: String = "1.14.0"

    @SerializedName("some_defs")
    @Expose
    var myDefs: MutableMap<String, MyDataClass> = mutableMapOf()
        @MonsteraBuildSetter set
}

//To ensure that the developer can still modify keys, this class is open so that the developer
//can inherit and modify the class with more keys.
open class MyDataClass {  }

Addon specific files: files are seperated in the packages beh and res for behaviour and resource alike. Exceptions are files that can live in both behaviour and resource pack:

Addon

In this package we define higher level functionality for addons in general.

This should give the developer a more user friendly interface to use, the developer should still be able to access raw file object as this might be necessary when creating files with different format versions.