Skip to content

Commit

Permalink
rewrite in kotlin and reorient entirely for temporary worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jun 23, 2023
1 parent 29acfd0 commit e025fd8
Show file tree
Hide file tree
Showing 25 changed files with 775 additions and 837 deletions.
104 changes: 54 additions & 50 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,94 +1,98 @@
plugins {
id 'java'
id 'eclipse'
id 'idea'
//file:noinspection All

plugins {
id 'java-library'
id 'maven-publish'
id 'idea'
id 'org.jetbrains.kotlin.jvm'

id 'fabric-loom' version '1.2-SNAPSHOT'
}

def ENV = System.getenv()
import groovy.json.JsonOutput
import groovy.json.JsonSlurper

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
tasks.withType(JavaCompile).configureEach { it.options.release = 17 }
version = mod_version
group = maven_group

String ver = "${project.version_id}+${project.major_version}-fabric"
version = ENV.GITHUB_ACTIONS ? "${ver}.build.${ENV.GITHUB_RUN_NUMBER}" : ver
compileKotlin.kotlinOptions.jvmTarget = "17"

archivesBaseName = project.mod_id
group = project.maven_group
dependencies {
minecraft "com.mojang:minecraft:$minecraft_version"
mappings "net.fabricmc:yarn:$minecraft_version+build.$yarn_build:v2"
modImplementation "net.fabricmc:fabric-loader:$loader_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:$fabric_version"
include modImplementation ("net.fabricmc:fabric-language-kotlin:$fabric_kotlin_version")

repositories {
maven {
name = 'Terraformers'
url = 'https://maven.terraformersmc.com/releases/'
}
testImplementation sourceSets.main.output
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2"
modApi "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
sourceSets {
test
}

sourceSets {
test {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
processResources {
inputs.property "version", version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": version
}

doLast {
println("Minifying json")
def start = System.currentTimeMillis()
def minified = 0
def bytes = 0
fileTree(dir: outputs.files.asPath, include: '**/*.json').each {
def oldLength = it.length()
it.text = JsonOutput.toJson(new JsonSlurper().parse(it))
bytes += oldLength - it.length()
minified++
}
def ms = System.currentTimeMillis() - start
println("Minified $minified json files. Saved $bytes bytes. Took $ms ms.")
}
}

tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

loom {
runs {
testClient {
name "Minecraft Client (Test)"
client()
source sourceSets.test
}
accessWidenerPath = file("src/main/resources/${mod_id}.accesswidener")

runs {
testServer {
name "Minecraft Server (Test)"
server()

name = "Minecraft Server (Test)"
source sourceSets.test
}
}
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
jar {
from("LICENSE") {
rename { "${it}_${archivesBaseName}" }
}
}

loom {
splitEnvironmentSourceSets()
}

/* Publishing */

java { withSourcesJar() }

publishing {
setupRepositories(repositories)

publications {
mavenJava(MavenPublication) {
artifact(remapJar) {
builtBy(remapJar)
}

artifact(sourcesJar) {
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
}
}
}

static void setupRepositories(RepositoryHandler repositories) {

def ENV = System.getenv()
if (ENV.MAVEN_URL) {
repositories.maven {
Expand Down
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.parallel=true

minecraft_version=1.20-rc1
yarn_build=2
minecraft_version=1.20.1
yarn_build=5
loader_version=0.14.21

version_id=0.1.2
mod_version=0.1.2

mod_id=bubble
maven_group=dev.andante
major_version=1.20

fabric_api_version=0.83.0+1.20
fabric_version=0.84.0+1.20.1

kotlin_version=1.8.22
fabric_kotlin_version=1.9.5+kotlin.1.8.22
5 changes: 4 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ pluginManagement {
}

gradlePluginPortal()
mavenLocal()
}

plugins {
id "org.jetbrains.kotlin.jvm" version kotlin_version
}
}

Expand Down
94 changes: 58 additions & 36 deletions src/main/java/dev/andante/bubble/Bubble.kt
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
package dev.andante.bubble;

import dev.andante.bubble.command.BubbleCommand;
import dev.andante.bubble.world.VoidChunkGenerator;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.dimension.DimensionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Bubble implements ModInitializer {
public static final String MOD_ID = "bubble";
public static final String MOD_NAME = "Bubble";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

public static final RegistryKey<DimensionType> DEFAULT_DIMENSION_TYPE = RegistryKey.of(RegistryKeys.DIMENSION_TYPE, new Identifier(MOD_ID, "default"));

@Override
public void onInitialize() {
LOGGER.info("Initializing {}", MOD_NAME);

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
BubbleCommand.register(dispatcher);
});

Registry.register(Registries.CHUNK_GENERATOR, new Identifier(MOD_ID, "void"), VoidChunkGenerator.CODEC);

ServerTickEvents.START_SERVER_TICK.register(BubbleManager::tick);
ServerLifecycleEvents.SERVER_STOPPING.register(BubbleManager::onServerStopping);
package dev.andante.bubble

import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.suggestion.Suggestions
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import dev.andante.bubble.command.BubbleCommand
import dev.andante.bubble.world.BubbleWorld
import dev.andante.bubble.world.property.VoidChunkGenerator
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
import net.minecraft.command.CommandSource
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.registry.RegistryKey
import net.minecraft.registry.RegistryKeys
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.util.Identifier
import net.minecraft.world.dimension.DimensionType
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.concurrent.CompletableFuture

/**
* The Bubble entry point.
*/
object Bubble : ModInitializer {
const val MOD_ID = "bubble"
const val MOD_NAME = "Bubble"

val LOGGER: Logger = LoggerFactory.getLogger(MOD_ID)
val DEFAULT_DIMENSION_TYPE: RegistryKey<DimensionType> = RegistryKey.of(RegistryKeys.DIMENSION_TYPE, Identifier(MOD_ID, "default"))

override fun onInitialize() {
LOGGER.info("Initializing $MOD_NAME")

// chunk generator
Registry.register(Registries.CHUNK_GENERATOR, Identifier(MOD_ID, "void"), VoidChunkGenerator.CODEC)

// initialize
BubbleManager

// register commands
CommandRegistrationCallback.EVENT.register { dispatcher, _, _ -> BubbleCommand.register(dispatcher) }
}

/**
* Suggests bubble worlds to a command context.
*/
fun suggestBubbleDimensions(context: CommandContext<ServerCommandSource>, builder: SuggestionsBuilder): CompletableFuture<Suggestions> {
CommandSource.suggestIdentifiers(
context.source.server.worlds
.filterValues { it is BubbleWorld }
.keys
.map(RegistryKey<*>::getValue),
builder
)

return builder.buildFuture()
}
}

0 comments on commit e025fd8

Please sign in to comment.