Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated gradle script, Ukrainian & Belarusian translation, some 1.21 blocks logging, smaller jar size, etc. #301

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.gradle/
build/
out/
.kotlin/

# idea
.idea/
Expand Down
139 changes: 64 additions & 75 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.loom)
alias(libs.plugins.detekt)
alias(libs.plugins.git.hooks)
alias(libs.plugins.shadow)
`maven-publish`
}

val props = properties

val modId: String by project
val modName: String by project
val modVersion: String by project
val mavenGroup: String by project

base.archivesBaseName = modId
base.archivesName.set(modId)
version = "$modVersion${getVersionMetadata()}"
group = mavenGroup

Expand All @@ -38,8 +37,6 @@ loom {
}
}

configurations.implementation.get().extendsFrom(configurations.shadow.get())

fun DependencyHandlerScope.modImplementationAndInclude(dep: Any) {
modImplementation(dep)
include(dep)
Expand All @@ -54,6 +51,10 @@ repositories {
mavenLocal()
}

val includeImplementation: Configuration by configurations.creating {
configurations.implementation.configure { extendsFrom(this@creating) }
}

dependencies {
// To change the versions see the libs.versions.toml

Expand All @@ -75,22 +76,21 @@ dependencies {
modImplementation(libs.fabric.kotlin)

// Database
shadow(libs.exposed.core)
shadow(libs.exposed.dao)
shadow(libs.exposed.jdbc)
shadow(libs.exposed.java.time)
shadow(libs.sqlite.jdbc)
includeImplementation(libs.exposed.core)
includeImplementation(libs.exposed.dao)
includeImplementation(libs.exposed.java.time)
includeImplementation(libs.exposed.jdbc)
includeImplementation(libs.exposed.migration)
includeImplementation(libs.sqlite.jdbc)

// Config
shadow(libs.konf.core)
shadow(libs.konf.toml)
includeImplementation(libs.konf.core)
includeImplementation(libs.konf.toml)

detektPlugins(libs.detekt.formatting)
}

tasks {
val javaVersion = JavaVersion.VERSION_21

processResources {
inputs.property("id", modId)
inputs.property("name", modName)
Expand All @@ -110,70 +110,20 @@ tasks {
}
}

withType<JavaCompile> {
options.encoding = "UTF-8"
sourceCompatibility = javaVersion.toString()
targetCompatibility = javaVersion.toString()
options.release.set(javaVersion.toString().toInt())
}

compileKotlin {
kotlinOptions {
jvmTarget = javaVersion.toString()
}
}

jar {
from("LICENSE")
}
}

java {
toolchain { languageVersion.set(JavaLanguageVersion.of(javaVersion.toString())) }
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
withSourcesJar()
}

remapJar {
dependsOn(shadowJar)
input.set(shadowJar.get().archiveFile)
}

shadowJar {
from("LICENSE")

configurations = listOf(
project.configurations.shadow.get()
)
archiveClassifier.set("dev-all")

exclude("kotlin/**", "kotlinx/**", "javax/**")
exclude("org/checkerframework/**", "org/intellij/**", "org/jetbrains/annotations/**")
exclude("com/google/gson/**")
exclude("net/kyori/**")
exclude("org/slf4j/**")

val relocPath = "com.github.quiltservertools.libs."
relocate("com.fasterxml", relocPath + "com.fasterxml")
relocate("com.moandjiezana.toml", relocPath + "com.moandjiezana.toml")
relocate("javassist", relocPath + "javassist")
// Relocate each apache lib separately as just org.apache.commons will relocate things that aren't shadowed and break stuff
relocate("org.apache.commons.lang3", relocPath + "org.apache.commons.lang3")
relocate("org.apache.commons.text", relocPath + "org.apache.commons.text")
relocate("org.reflections", relocPath + "org.reflections")
// it appears you cannot relocate sqlite due to the native libraries
// relocate("org.sqlite", relocPath + "org.sqlite")
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
}

compileKotlin {
kotlinOptions {
jvmTarget = javaVersion.toString()
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = javaVersion.toString()
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
}
}

Expand All @@ -194,7 +144,7 @@ publishing {
detekt {
buildUponDefaultConfig = true
autoCorrect = true
config = rootProject.files("detekt.yml")
config.setFrom(rootProject.files("detekt.yml"))
}

gitHooks {
Expand All @@ -219,3 +169,42 @@ fun getVersionMetadata(): String {
// No tracking information could be found about the build
return "+local"
}

afterEvaluate {
dependencies {
handleIncludes(includeImplementation)
}
}

/* Thanks to https://github.com/jakobkmar for original script */
fun DependencyHandlerScope.includeTransitive(
dependencies: Set<ResolvedDependency>,
minecraftLibs: Set<ResolvedDependency>,
kotlinDependency: ResolvedDependency,
checkedDependencies: MutableSet<ResolvedDependency> = HashSet()
) {
dependencies.forEach {
if (checkedDependencies.contains(it) || it.moduleGroup == "org.jetbrains.kotlin" || it.moduleGroup == "org.jetbrains.kotlinx") return@forEach

if (kotlinDependency.children.any { dep -> dep.name == it.name }) {
println("Skipping -> ${it.name} (already in fabric-language-kotlin)")
} else if (minecraftLibs.any { dep -> dep.moduleGroup == it.moduleGroup && dep.moduleName == it.moduleName }) {
println("Skipping -> ${it.name} (already in minecraft)")
} else {
include(it.name)
println("Including -> ${it.name}")
}
checkedDependencies += it

includeTransitive(it.children, minecraftLibs, kotlinDependency, checkedDependencies)
}
}

fun DependencyHandlerScope.handleIncludes(configuration: Configuration) {
includeTransitive(
configuration.resolvedConfiguration.firstLevelModuleDependencies,
configurations.minecraftLibraries.get().resolvedConfiguration.firstLevelModuleDependencies,
configurations.modImplementation.get().resolvedConfiguration.firstLevelModuleDependencies
.first { it.moduleGroup == "net.fabricmc" && it.moduleName == "fabric-language-kotlin" },
)
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
25 changes: 10 additions & 15 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ fabric-loader = "0.16.9"
fabric-api = "0.110.5+1.21.4"

# Kotlin
kotlin = "2.0.0"
kotlin = "2.1.0"
# Also modrinth version in gradle.properties
fabric-kotlin = "1.11.0+kotlin.2.0.0"
fabric-kotlin = "1.13.0+kotlin.2.1.0"

fabric-permissions = "0.3.3"
translations = "2.4.0+1.21.2-rc1"

exposed = "0.46.0"
sqlite-jdbc = "3.44.1.0"
exposed = "0.58.0"
sqlite-jdbc = "3.47.2.0"

konf = "1.1.2"

wdmcf = "1.0.2"

detect = "1.23.6"
detekt = "1.23.7"

[libraries]
minecraft = { module = "net.minecraft:minecraft", version.ref = "minecraft" }
Expand All @@ -35,20 +33,17 @@ translations = { module = "xyz.nucleoid:server-translations-api", version.ref =

exposed-core = { module = "org.jetbrains.exposed:exposed-core", version.ref = "exposed" }
exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exposed" }
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
exposed-java-time = { module = "org.jetbrains.exposed:exposed-java-time", version.ref = "exposed" }
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
exposed-migration = { module = "org.jetbrains.exposed:exposed-migration", version.ref = "exposed" }
sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite-jdbc" }

konf-core = { module = "com.uchuhimo:konf-core", version.ref = "konf"}
konf-toml = { module = "com.uchuhimo:konf-toml", version.ref = "konf"}
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detect" }

wdmcf = { module = "me.bymartrixx:wdmcf", version.ref = "wdmcf" }
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detect" }
loom = { id = "fabric-loom", version = "1.7.+" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
loom = { id = "fabric-loom", version = "1.9.+" }
git_hooks = { id = "com.github.jakemarsden.git-hooks", version = "0.0.2" }
# https://github.com/johnrengelman/shadow/issues/894
shadow = { id = "io.github.goooler.shadow", version = "8.1.7" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemUsageContext;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -24,6 +25,7 @@ private static void logHoeInteraction(BlockState state, ItemConvertible itemConv
log(state, context);
}

@Unique
private static void log(BlockState state, ItemUsageContext context) {
var player = context.getPlayer();
if (player != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

@Mixin(Slot.class)
public abstract class SlotMixin implements HandledSlot {
@Unique
private ScreenHandler handler = null;
@Unique
private ItemStack oldStack = null;

@Shadow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
import com.github.quiltservertools.ledger.utility.Sources;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BedBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.enums.BedPart;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
Expand All @@ -16,20 +16,19 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(BedBlock.class)
public abstract class BedBlockMixin {
@Unique
private BlockEntity oldBlockEntity = null;

@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void storeBlockEntity(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir, BedPart bedPart, BlockPos blockPos, BlockState blockState) {
@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void storeBlockEntity(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir, @Local(ordinal = 1) BlockPos blockPos) {
oldBlockEntity = world.getBlockEntity(blockPos);
}

@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void logBedBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir, BedPart bedPart, BlockPos blockPos, BlockState blockState) {
@Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER))
public void logBedBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable<BlockState> cir, @Local(ordinal = 1) BlockPos blockPos, @Local(ordinal = 1) BlockState blockState) {
BlockBreakCallback.EVENT.invoker().breakBlock(world, blockPos, blockState, oldBlockEntity, player);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.quiltservertools.ledger.mixin.blocks;

import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback;
import net.minecraft.block.BlockState;
import net.minecraft.block.ButtonBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(ButtonBlock.class)
public abstract class ButtonBlockMixin {
@Unique
private PlayerEntity activePlayer;

@Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/ButtonBlock;powerOn(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;)V"))
public void logButtonClick(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir) {
activePlayer = player;
}

@ModifyArgs(method = "powerOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void logLeverUse(Args args, BlockState state, World world, BlockPos pos, PlayerEntity playerEntity) {
if (activePlayer == null) return;

BlockState newState = args.get(1);
BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, newState, null, null, activePlayer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
import com.github.quiltservertools.ledger.utility.Sources;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.CarvedPumpkinBlock;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.block.pattern.CachedBlockPosition;
Expand All @@ -10,12 +11,11 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(CarvedPumpkinBlock.class)
public abstract class CarvedPumpkinBlockMixin {
@Inject(method = "breakPatternBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private static void logStatueBreak(World world, BlockPattern.Result patternResult, CallbackInfo ci, int i, int j, CachedBlockPosition cachedBlockPosition) {
@Inject(method = "breakPatternBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER))
private static void logStatueBreak(World world, BlockPattern.Result patternResult, CallbackInfo ci, @Local CachedBlockPosition cachedBlockPosition) {
if (cachedBlockPosition.getBlockState().isAir()) {
return;
}
Expand Down
Loading
Loading