From 9d25a9e7995ab006f4007343ca86d6ede5bcc42a Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Sun, 28 Sep 2025 23:49:42 +0200 Subject: [PATCH 1/8] Rewrite JumpAnimationBit in Kotlin --- build.gradle | 17 ++++ .../animation/bit/biped/JumpAnimationBit.java | 88 ------------------- .../animation/bit/biped/JumpAnimationBit.kt | 79 +++++++++++++++++ 3 files changed, 96 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.java create mode 100644 src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt diff --git a/build.gradle b/build.gradle index 3afa0632..3f7835aa 100644 --- a/build.gradle +++ b/build.gradle @@ -6,12 +6,14 @@ buildscript { } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:3.+' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72" } } apply plugin: 'net.minecraftforge.gradle' // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. apply plugin: 'eclipse' +apply plugin: 'kotlin' apply plugin: 'maven-publish' version = "${mod_version}-${getDate()}" @@ -21,6 +23,18 @@ archivesBaseName = "MoBends_${minecraft_version}" // Need this here so eclipse task generates correctly. sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' +// Kotlin configuration +compileKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} +compileTestKotlin { + kotlinOptions { + jvmTarget = "1.8" + } +} + minecraft { // The mappings can be changed at any time, and must be in the following format. // snapshot_YYYYMMDD Snapshot are built nightly. @@ -81,6 +95,9 @@ dependencies { // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html // http://www.gradle.org/docs/current/userguide/dependency_management.html + // Kotlin support + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72" + testCompile "junit:junit:4.11" } diff --git a/src/main/java/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.java b/src/main/java/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.java deleted file mode 100644 index d9ea316f..00000000 --- a/src/main/java/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.java +++ /dev/null @@ -1,88 +0,0 @@ -package goblinbob.mobends.standard.animation.bit.biped; - -import goblinbob.mobends.core.animation.bit.AnimationBit; -import goblinbob.mobends.standard.data.BipedEntityData; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.math.MathHelper; - -public class JumpAnimationBit> extends AnimationBit -{ - private static final String[] ACTIONS = new String[] { "jump" }; - - @Override - public String[] getActions(T entityData) - { - return ACTIONS; - } - - @Override - public void onPlay(T data) - { - data.renderRotation.identity(); - data.centerRotation.identity(); - data.body.rotation.orientInstantX(20F); - data.rightLeg.rotation.orientInstantX(0F); - data.leftLeg.rotation.orientInstantX(0F); - data.rightForeLeg.rotation.orientInstantX(0F); - data.leftForeLeg.rotation.orientInstantX(0F); - data.rightArm.rotation.orientInstantZ(2F); - data.leftArm.rotation.orientInstantZ(-2F); - data.rightForeArm.rotation.orientInstantX(-20F); - data.leftForeArm.rotation.orientInstantX(-20F); - } - - @Override - public void perform(T data) - { - if (data.getPrevMotionY() < 0 && data.getMotionY() > 0) - { - /* - * Restarting the animation if the player is going back up again after falling - * down. - */ - this.onPlay(data); - } - - EntityLivingBase biped = data.getEntity(); - - data.globalOffset.slideToZero(0.3F); - data.renderRotation.setSmoothness(.3F).orientZero(); - data.centerRotation.setSmoothness(.7F).orientZero(); - data.renderRightItemRotation.setSmoothness(.3F).orientZero(); - data.renderLeftItemRotation.setSmoothness(.3F).orientZero(); - - float bodyRotationX = Math.max(1.0F - data.getTicksInAir() * 0.1F, 0.0F); - data.body.rotation.setSmoothness(0.2F).orientX(bodyRotationX); - data.rightArm.rotation.setSmoothness(0.05F).orientZ(45F); - data.leftArm.rotation.setSmoothness(0.05F).orientZ(-45F); - data.rightForeArm.rotation.setSmoothness(0.3F).orientX(0); - data.leftForeArm.rotation.setSmoothness(0.3F).orientX(0); - - data.head.rotation.orientX(data.headPitch.get() - bodyRotationX) - .rotateY(data.headYaw.get()); - - if (!data.isStillHorizontally()) - { - final float PI = (float) Math.PI; - float limbSwing = data.limbSwing.get() * 0.6662F; - float limbSwingAmount = 0.7F * data.limbSwingAmount.get() / PI * 180F; - data.rightLeg.rotation.setSmoothness(1.0F).orientX(-5F + MathHelper.cos(limbSwing) * limbSwingAmount); - data.leftLeg.rotation.setSmoothness(1.0F).orientX(-5F + MathHelper.cos(limbSwing + PI) * limbSwingAmount); - - float var = (limbSwing / PI) % 2; - data.leftForeLeg.rotation.setSmoothness(0.3F).orientX((var > 1 ? 45 : 0)); - data.rightForeLeg.rotation.setSmoothness(0.3F).orientX((var > 1 ? 0 : 45)); - data.leftForeArm.rotation.setSmoothness(0.3F).orientX((MathHelper.cos(limbSwing + PI/2) / 2F + 0.5F) * -20F); - data.rightForeArm.rotation.setSmoothness(0.3F).orientX((MathHelper.cos(limbSwing) / 2F + 0.5F) * -20F); - } - else - { - data.rightLeg.rotation.setSmoothness(0.1F).orientZ(10); - data.rightLeg.rotation.setSmoothness(0.3F).rotateX(-45); - data.leftLeg.rotation.setSmoothness(0.1F).orientZ(-10); - data.leftLeg.rotation.setSmoothness(0.3F).rotateX(-17); - data.rightForeLeg.rotation.setSmoothness(0.3F).orientX(70); - data.leftForeLeg.rotation.setSmoothness(0.3F).orientX(17); - } - } -} diff --git a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt new file mode 100644 index 00000000..df898dd7 --- /dev/null +++ b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt @@ -0,0 +1,79 @@ +package goblinbob.mobends.standard.animation.bit.biped + +import goblinbob.mobends.core.animation.bit.AnimationBit +import goblinbob.mobends.standard.data.BipedEntityData +import net.minecraft.entity.EntityLivingBase +import net.minecraft.util.math.MathHelper +import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.max + +class JumpAnimationBit> : AnimationBit() { + companion object { + private val ACTIONS = arrayOf("jump") + } + + override fun getActions(entityData: T): Array = ACTIONS + + override fun onPlay(data: T) { + data.renderRotation.identity() + data.centerRotation.identity() + data.body.rotation.orientInstantX(20f) + data.rightLeg.rotation.orientInstantX(0f) + data.leftLeg.rotation.orientInstantX(0f) + data.rightForeLeg.rotation.orientInstantX(0f) + data.leftForeLeg.rotation.orientInstantX(0f) + data.rightArm.rotation.orientInstantZ(2f) + data.leftArm.rotation.orientInstantZ(-2f) + data.rightForeArm.rotation.orientInstantX(-20f) + data.leftForeArm.rotation.orientInstantX(-20f) + } + + override fun perform(data: T) { + if (data.prevMotionY < 0 && data.motionY > 0) { + /* + * Restarting the animation if the player is going back up again after falling + * down. + */ + onPlay(data) + } + + data.globalOffset.slideToZero(0.3f) + data.renderRotation.setSmoothness(0.3f).orientZero() + data.centerRotation.setSmoothness(0.7f).orientZero() + data.renderRightItemRotation.setSmoothness(0.3f).orientZero() + data.renderLeftItemRotation.setSmoothness(0.3f).orientZero() + + val bodyRotationX = max(1.0f - data.ticksInAir * 0.1f, 0.0f) + data.body.rotation.setSmoothness(0.2f).orientX(bodyRotationX) + data.rightArm.rotation.setSmoothness(0.05f).orientZ(45f) + data.leftArm.rotation.setSmoothness(0.05f).orientZ(-45f) + data.rightForeArm.rotation.setSmoothness(0.3f).orientX(0f) + data.leftForeArm.rotation.setSmoothness(0.3f).orientX(0f) + + data.head.rotation.orientX(data.headPitch.get() - bodyRotationX).rotateY(data.headYaw.get()) + + if (!data.isStillHorizontally()) { + val limbSwing = data.limbSwing.get() * 0.6662f + val limbSwingAmount = 0.7f * data.limbSwingAmount.get() / PI.toFloat() * 180f + + data.rightLeg.rotation.setSmoothness(1.0f).orientX(-5f + MathHelper.cos(limbSwing) * limbSwingAmount) + data.leftLeg.rotation.setSmoothness(1.0f) + .orientX(-5f + MathHelper.cos(limbSwing + PI.toFloat()) * limbSwingAmount) + + val limbSwingVar = (limbSwing / PI.toFloat()) % 2 + data.leftForeLeg.rotation.setSmoothness(0.3f).orientX(if (limbSwingVar > 1) 45f else 0f) + data.rightForeLeg.rotation.setSmoothness(0.3f).orientX(if (limbSwingVar > 1) 0f else 45f) + data.leftForeArm.rotation.setSmoothness(0.3f) + .orientX((MathHelper.cos(limbSwing + PI.toFloat() / 2) / 2f + 0.5f) * -20f) + data.rightForeArm.rotation.setSmoothness(0.3f).orientX((MathHelper.cos(limbSwing) / 2f + 0.5f) * -20f) + } else { + data.rightLeg.rotation.setSmoothness(0.1f).orientZ(10f) + data.rightLeg.rotation.setSmoothness(0.3f).rotateX(-45f) + data.leftLeg.rotation.setSmoothness(0.1f).orientZ(-10f) + data.leftLeg.rotation.setSmoothness(0.3f).rotateX(-17f) + data.rightForeLeg.rotation.setSmoothness(0.3f).orientX(70f) + data.leftForeLeg.rotation.setSmoothness(0.3f).orientX(17f) + } + } +} From 32c4646d683da2231c594f76a090d28f87cf0636 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 00:19:37 +0200 Subject: [PATCH 2/8] Docs --- .../standard/animation/bit/biped/JumpAnimationBit.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt index df898dd7..cad4cef8 100644 --- a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt +++ b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt @@ -8,7 +8,13 @@ import kotlin.math.PI import kotlin.math.cos import kotlin.math.max +/** + * Represents a jump animation bit for biped entities. + */ class JumpAnimationBit> : AnimationBit() { + /* + * Holds values that are constant across bits of this type. + */ companion object { private val ACTIONS = arrayOf("jump") } From 4054c87bfff280af77de0a983d85e74e44cb8feb Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 00:34:47 +0200 Subject: [PATCH 3/8] Docs --- .../standard/animation/bit/biped/JumpAnimationBit.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt index cad4cef8..c3c52cda 100644 --- a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt +++ b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt @@ -12,10 +12,11 @@ import kotlin.math.max * Represents a jump animation bit for biped entities. */ class JumpAnimationBit> : AnimationBit() { - /* - * Holds values that are constant across bits of this type. - */ companion object { + /* + * Holds the actions that the bits of this type perform. + * TODO: Used by bends-packs, but not sure for purpose exactly. + */ private val ACTIONS = arrayOf("jump") } From bedcd7005d6a04fe9729d92919c57f5e0bd44d7e Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 01:02:58 +0200 Subject: [PATCH 4/8] Bring back docs of the companion object --- .../mobends/standard/animation/bit/biped/JumpAnimationBit.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt index c3c52cda..7ef944c1 100644 --- a/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt +++ b/src/main/kotlin/goblinbob/mobends/standard/animation/bit/biped/JumpAnimationBit.kt @@ -12,6 +12,9 @@ import kotlin.math.max * Represents a jump animation bit for biped entities. */ class JumpAnimationBit> : AnimationBit() { + /** + * All constants that are shared across all bits of this type. + */ companion object { /* * Holds the actions that the bits of this type perform. From 1babba76cb054765f88975cce1dd30fb5390f327 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 01:19:59 +0200 Subject: [PATCH 5/8] Bundling the Kotlin standard library along with the mod --- build.gradle | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 3f7835aa..9ec30cc8 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,10 @@ buildscript { } } +plugins { + id("com.github.johnrengelman.shadow") version "4.0.4" +} + apply plugin: 'net.minecraftforge.gradle' // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. apply plugin: 'eclipse' @@ -123,7 +127,7 @@ sourceSets {main { output.resourcesDir = output.classesDir }} // Example configuration to allow publishing using the maven-publish task // This is the preferred method to reobfuscate your jar file -jar.finalizedBy('reobfJar') +shadowJar.finalizedBy('reobfJar') // However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing //publish.dependsOn('reobfJar') @@ -149,7 +153,7 @@ processResources { publishing { publications { mavenJava(MavenPublication) { - artifact jar + artifact shadowJar } } repositories { @@ -159,6 +163,13 @@ publishing { } } +// Bundling the Kotlin standard library along with the mod +shadowJar { + dependencies { + include(dependency('org.jetbrains.kotlin:kotlin-stdlib-jdk8')) + } +} + def getDate() { return new Date().format('dd.MM.yy') } From 3fc25ede3324cd77d4ebbde455b2fb8634452227 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 03:26:17 +0200 Subject: [PATCH 6/8] More robust bundling --- .gitignore | 6 ++++-- build.gradle | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 5bc1827a..507921c0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,7 @@ !/src !/misc !/gradle -!gradlew -!gradlew.bat +!/gradlew +!/gradlew.bat +!/README.md +!/LICENSE diff --git a/build.gradle b/build.gradle index 9ec30cc8..447f5146 100644 --- a/build.gradle +++ b/build.gradle @@ -3,22 +3,21 @@ buildscript { maven { url = 'https://files.minecraftforge.net/maven' } jcenter() mavenCentral() + gradlePluginPortal() } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:3.+' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72" + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72' + classpath 'com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:4.0.4' } } -plugins { - id("com.github.johnrengelman.shadow") version "4.0.4" -} - apply plugin: 'net.minecraftforge.gradle' // Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. apply plugin: 'eclipse' apply plugin: 'kotlin' apply plugin: 'maven-publish' +apply plugin: 'com.github.johnrengelman.shadow' version = "${mod_version}-${getDate()}" group = "goblinbob.mobends" // http://maven.apache.org/guides/mini/guide-naming-conventions.html @@ -100,7 +99,10 @@ dependencies { // http://www.gradle.org/docs/current/userguide/dependency_management.html // Kotlin support - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72" + implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72' + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72' + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72' + implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.72' testCompile "junit:junit:4.11" } @@ -123,13 +125,19 @@ jar { // Temporary fix for resources not being available during testing // Comment this out upon publishing -sourceSets {main { output.resourcesDir = output.classesDir }} +// sourceSets {main { output.resourcesDir = output.classesDir }} // Example configuration to allow publishing using the maven-publish task // This is the preferred method to reobfuscate your jar file -shadowJar.finalizedBy('reobfJar') +// Configure reobf to work on shadowJar instead of regular jar +reobf { + shadowJar { + // This will create a reobfuscated shadow jar + } +} +shadowJar.finalizedBy('reobfShadowJar') // However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing -//publish.dependsOn('reobfJar') +//publish.dependsOn('reobfShadowJar') processResources { // this will ensure that this task is redone when the versions change. @@ -150,6 +158,16 @@ processResources { } } +// Bundling the Kotlin standard library along with the mod +shadowJar { + dependencies { + include(dependency('org.jetbrains.kotlin:kotlin-stdlib')) + include(dependency('org.jetbrains.kotlin:kotlin-stdlib-jdk7')) + include(dependency('org.jetbrains.kotlin:kotlin-stdlib-jdk8')) + include(dependency('org.jetbrains.kotlin:kotlin-reflect')) + } +} + publishing { publications { mavenJava(MavenPublication) { @@ -163,13 +181,6 @@ publishing { } } -// Bundling the Kotlin standard library along with the mod -shadowJar { - dependencies { - include(dependency('org.jetbrains.kotlin:kotlin-stdlib-jdk8')) - } -} - def getDate() { return new Date().format('dd.MM.yy') } From c3f2bbd76628dc24d6ae864af0e6d7e38995a5ce Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 03:34:44 +0200 Subject: [PATCH 7/8] Relocate kotlin std lib to avoid conflicts --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 447f5146..e0f0471b 100644 --- a/build.gradle +++ b/build.gradle @@ -162,10 +162,9 @@ processResources { shadowJar { dependencies { include(dependency('org.jetbrains.kotlin:kotlin-stdlib')) - include(dependency('org.jetbrains.kotlin:kotlin-stdlib-jdk7')) include(dependency('org.jetbrains.kotlin:kotlin-stdlib-jdk8')) - include(dependency('org.jetbrains.kotlin:kotlin-reflect')) } + relocate 'kotlin', 'goblinbob.mobends.kotlin' } publishing { From e5d23a8fa7e8019d88cd694732471c63f110b735 Mon Sep 17 00:00:00 2001 From: Iwo Plaza Date: Mon, 29 Sep 2025 03:36:29 +0200 Subject: [PATCH 8/8] Only publishing the shadowJar artifact in CI --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d716e279..4401143e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,8 +38,8 @@ jobs: uses: actions/upload-artifact@v4 if: success() with: - name: mod-jars - path: build/libs/*.jar + name: mobends-ci-build + path: build/libs/*-all.jar retention-days: 30 - name: Comment PR with artifact URLs