diff --git a/.github/workflows/build-commit.yml b/.github/workflows/build-commit.yml index f59db9a..dd116f5 100644 --- a/.github/workflows/build-commit.yml +++ b/.github/workflows/build-commit.yml @@ -2,38 +2,45 @@ # This makes use of caching for faster builds and uploads the resulting artifacts name: build-commit -on: [ push ] +on: + push: + paths-ignore: + - "readme.md" + - "LICENSE" + - ".gitignore" + - "changelog.md" + - ".editorconfig" + - "src/*/resources/lang/*" + pull_request: + paths-ignore: + - "readme.md" + - "LICENSE" + - ".gitignore" + - "changelog.md" + - ".editorconfig" + - "src/*/resources/lang/*" + workflow_dispatch: jobs: build: runs-on: ubuntu-latest + name: Build with Gradle + steps: - - name: Extract current branch name - shell: bash - # bash pattern expansion to grab branch name without slashes - run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT - id: ref - - name: Checkout sources - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - name: Set up JDK uses: actions/setup-java@v4 with: - distribution: 'temurin' java-version: 21 - - name: Initialize caches - uses: actions/cache@v4 + distribution: temurin + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Build with Gradle + uses: Wandalen/wretry.action@master with: - path: | - ~/.gradle/caches - ~/.gradle/loom-cache - ~/.gradle/wrapper - key: ${{ runner.os }}-build-commit-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-build-commit- - - name: Build artifacts - run: ./gradlew build - - name: Upload artifacts - uses: actions/upload-artifact@v4 + command: ./gradlew buildAllVersions --stacktrace + - uses: actions/upload-artifact@v4 with: - name: telekinesis-artifacts-${{ steps.ref.outputs.branch }} - path: build/libs/*.jar + path: versions/**/build/libs/*.jar diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml deleted file mode 100644 index 451643a..0000000 --- a/.github/workflows/build-pull-request.yml +++ /dev/null @@ -1,29 +0,0 @@ -# Used when building external pull requests -# We don't want to publish build artifacts or expose our other caches to possibly untrusted code -name: build-pull-request - -on: [ pull_request ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout sources - uses: actions/checkout@v4 - - name: Initialize caches - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/loom-cache - ~/.gradle/wrapper - key: ${{ runner.os }}-build-external-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-build-external- - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 21 - - name: Build artifacts - run: ./gradlew build diff --git a/.github/workflows/ktlint-commit.yml b/.github/workflows/ktlint-commit.yml deleted file mode 100644 index 260731a..0000000 --- a/.github/workflows/ktlint-commit.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: ktlint-commit - -on: [ push ] - -jobs: - ktlint: - name: Check Code Quality - runs-on: ubuntu-latest - - steps: - - name: Clone repo - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - name: ktlint - uses: ScaCap/action-ktlint@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-check - filter_mode: nofilter - level: info - fail_on_error: true diff --git a/.github/workflows/ktlint-pull-request.yml b/.github/workflows/ktlint-pull-request.yml deleted file mode 100644 index 174805d..0000000 --- a/.github/workflows/ktlint-pull-request.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: ktlint-pull-request - -on: [ pull_request ] - -jobs: - ktlint: - name: Check Code Quality - runs-on: ubuntu-latest - - steps: - - name: Clone repo - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - name: ktlint - uses: ScaCap/action-ktlint@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reporter: github-pr-review - level: info diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cd58a72 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,35 @@ +name: release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + name: Release + permissions: write-all + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: temurin + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Release with Gradle + uses: Wandalen/wretry.action@master + with: + command: ./gradlew releaseAllVersions --stacktrace + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MODRINTH_API_KEY: ${{ secrets.MODRINTH_API_KEY }} + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + NYON_USERNAME: ${{ secrets.NYON_USERNAME }} + NYON_PASSWORD: ${{ secrets.NYON_PASSWORD }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SECRET_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SECRET_KEY_PASSWORD }} + GPG_SECRET_KEY_ID: ${{ secrets.GPG_SECRET_KEY_ID }} diff --git a/build.gradle.kts b/build.gradle.kts index 18780aa..4a92d56 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,12 +1,15 @@ plugins { - kotlin("jvm") version "1.9.23" - kotlin("plugin.serialization") version "1.9.23" - id("com.modrinth.minotaur") version "2.8.7" apply (false) - id("com.github.breadmoirai.github-release") version "2.5.2" apply (false) + kotlin("jvm") version "1.9.24" + kotlin("plugin.serialization") version "1.9.24" + + id("me.modmuss50.mod-publish-plugin") version "0.5.+" id("fabric-loom") version "1.6-SNAPSHOT" apply (false) id("io.papermc.paperweight.userdev") version "1.5.5" apply (false) + + `maven-publish` + signing } repositories { diff --git a/changelog.md b/changelog.md index 009d339..95cf704 100644 --- a/changelog.md +++ b/changelog.md @@ -1,2 +1 @@ -- update to 1.20.5 - - no config screen cause of yacl at the moment \ No newline at end of file +- support 1.20.1, 1.20.4, 1.20.6 diff --git a/settings.gradle.kts b/settings.gradle.kts index 1cfdacb..640c9fd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,5 @@ +import dev.kikugie.stonecutter.gradle.StonecutterSettings + rootProject.name = "telekinesis" pluginManagement { @@ -7,8 +9,23 @@ pluginManagement { maven("https://server.bbkr.space/artifactory/libs-release/") maven("https://maven.quiltmc.org/repository/release/") maven("https://repo.papermc.io/repository/maven-public/") + maven("https://maven.kikugie.dev/releases") } } +plugins { + id("dev.kikugie.stonecutter") version "0.3.5" +} + //include("telekinesis-paper") -include("telekinesis-fabric") \ No newline at end of file +include("telekinesis-fabric") + +extensions.configure { + kotlinController = true + centralScript = "build.gradle.kts" + shared { + versions("1.20.1", "1.20.4", "1.20.6") + vcsVersion = "1.20.6" + } + create(project(":telekinesis-fabric")) +} diff --git a/telekinesis-fabric/build.gradle.kts b/telekinesis-fabric/build.gradle.kts index 0229582..4a99bf2 100644 --- a/telekinesis-fabric/build.gradle.kts +++ b/telekinesis-fabric/build.gradle.kts @@ -4,27 +4,44 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import kotlin.io.path.readText plugins { - kotlin("jvm") - kotlin("plugin.serialization") + kotlin("jvm") version "1.9.24" + kotlin("plugin.serialization") version "1.9.24" + id("fabric-loom") version "1.6-SNAPSHOT" - id("com.modrinth.minotaur") - id("com.github.breadmoirai.github-release") - - id("fabric-loom") + id("me.modmuss50.mod-publish-plugin") version "0.5.+" `maven-publish` signing } +val featureVersion = "2.4.1" +val mcVersion = property("mcVersion")!!.toString() +val mcVersionRange = property("mcVersionRange")!!.toString() +version = "$featureVersion-$mcVersion" + group = "dev.nyon" -val majorVersion = "2.4.0" -val mcVersion = "1.20.5-pre4" -val supportedMcVersions = listOf(mcVersion) -version = "$majorVersion-$mcVersion" -description = "Adds a telekinesis enchantment to minecraft" val projectAuthors = listOf("btwonion") val githubRepo = "btwonion/telekinesis" +loom { + if (stonecutter.current.isActive) { + runConfigs.all { + ideConfigGenerated(true) + runDir("../../run") + } + + project.tasks.register("runActive") { + group = "mod" + + dependsOn(tasks.named("runClient")) + } + } + + mixin { useLegacyMixinAp = false } + + accessWidenerPath = file("../../src/main/resources/telekinesis.accesswidener") +} + repositories { mavenCentral() exclusiveContent { @@ -35,29 +52,30 @@ repositories { includeGroup("maven.modrinth") } } + maven("https://maven.terraformersmc.com") + maven("https://maven.parchmentmc.org") + maven("https://repo.nyon.dev/releases") maven("https://maven.isxander.dev/releases") - maven("https://maven.terraformersmc.com/releases") - maven("https://maven.parchmentmc.org/") - maven("https://jitpack.io") maven("https://oss.sonatype.org/content/repositories/snapshots/") - maven("https://maven.isxander.dev/snapshots") // remove in stable release + maven("https://jitpack.io") } dependencies { minecraft("com.mojang:minecraft:$mcVersion") mappings( loom.layered { - parchment("org.parchmentmc.data:parchment-1.20.4:2024.04.14@zip") + parchment("org.parchmentmc.data:parchment-${property("deps.parchment")}@zip") officialMojangMappings() } ) - implementation("org.vineflower:vineflower:1.9.3") - modImplementation("net.fabricmc:fabric-loader:0.15.10") - modImplementation("net.fabricmc:fabric-language-kotlin:1.10.19+kotlin.1.9.23") - modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.3+1.20.4+update.1.20.5-SNAPSHOT+update.1.20.5-SNAPSHOT") - modImplementation("com.terraformersmc:modmenu:10.0.0-alpha.3") - modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:0.97.3+1.20.5") + implementation("org.vineflower:vineflower:1.10.1") + modImplementation("net.fabricmc:fabric-loader:0.15.11") + modImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")!!}") + modImplementation("net.fabricmc:fabric-language-kotlin:1.10.20+kotlin.1.9.24") + + modImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}") + modImplementation("com.terraformersmc:modmenu:${property("deps.modMenu")!!}") include(implementation(annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:0.1.1")!!)!!) @@ -69,88 +87,83 @@ dependencies { // modCompileOnly("maven.modrinth:EFtixeiF:Gcai736Z") // levelz by Globox1997 wait for 1.20.5 } +val javaVersion = property("javaVer")!!.toString() tasks { processResources { val modId = "telekinesis" - val modName = "Telekinesis" - val modDescription = "Adds an telekinesis enchantment" - - inputs.property("id", modId) - inputs.property("group", project.group) - inputs.property("name", modName) - inputs.property("description", modDescription) - inputs.property("version", project.version) - inputs.property("github", githubRepo) - - filesMatching(listOf("fabric.mod.json")) { - expand( + val modName = "telekinesis" + val modDescription = "Adds a telekinesis enchantment to minecraft" + + val props = + mapOf( "id" to modId, - "group" to project.group, "name" to modName, "description" to modDescription, "version" to project.version, - "github" to githubRepo + "github" to githubRepo, + "mc" to mcVersionRange ) + + props.forEach(inputs::property) + + filesMatching("fabric.mod.json") { + expand(props) } } register("releaseMod") { group = "publishing" - dependsOn("modrinth") - dependsOn("modrinthSyncBody") - dependsOn("githubRelease") + dependsOn("publishMods") dependsOn("publish") } - withType { - kotlinOptions.jvmTarget = "21" - } - withType { - options.release.set(21) + options.release = javaVersion.toInt() } - loom { - accessWidenerPath = file("src/main/resources/telekinesis.accesswidener") + withType { + kotlinOptions.jvmTarget = javaVersion } } val changelogText = buildString { append("# v${project.version}\n") - rootDir.toPath().resolve("changelog.md").readText().also { append(it) } + file("../../../changelog.md").readText().also { append(it) } } -modrinth { - token.set(findProperty("modrinth.token")?.toString()) - projectId.set("LLfA8jAD") - versionNumber.set("v${project.version}") - versionName.set("v${project.version}") - versionType.set("release") - uploadFile.set(tasks["remapJar"]) - gameVersions.set(supportedMcVersions) - loaders.set(listOf("fabric", "quilt")) - dependencies { - required.project("fabric-language-kotlin") - required.project("yacl") - required.project("modmenu") +val supportedMcVersions: List = property("supportedMcVersions")!!.toString().split(',').map(String::trim).filter(String::isNotEmpty) + +publishMods { + displayName = "v${project.version}" + file = tasks.remapJar.get().archiveFile + changelog = changelogText + type = STABLE + modLoaders.addAll("fabric", "quilt") + + modrinth { + projectId = "LLfA8jAD" + accessToken = providers.environmentVariable("MODRINTH_API_KEY") + minecraftVersions.addAll(supportedMcVersions) + + requires { slug = "fabric-api" } + requires { slug = "yacl" } + requires { slug = "fabric-language-kotlin" } + optional { slug = "modmenu" } } - changelog.set(changelogText) - syncBodyFrom.set(file("../README.md").readText()) -} -githubRelease { - token(findProperty("github.token")?.toString()) - - val (rowner, rrepo) = githubRepo.split("/") - owner = rowner - repo = rrepo - releaseName = "v${project.version}" - tagName = "v${project.version}" - body = changelogText - targetCommitish = "master" - setReleaseAssets(tasks["remapJar"]) + github { + repository = githubRepo + accessToken = providers.environmentVariable("GITHUB_TOKEN") + commitish = "master" + } + + discord { + webhookUrl = providers.environmentVariable("DISCORD_WEBHOOK") + username = "Release Notifier" + content = "# A new version of Telekinesis released!\n$changelogText" + } } publishing { @@ -158,26 +171,46 @@ publishing { maven { name = "nyon" url = uri("https://repo.nyon.dev/releases") - credentials(PasswordCredentials::class) - authentication { - create("basic") + credentials { + username = providers.environmentVariable("NYON_USERNAME").orNull + password = providers.environmentVariable("NYON_PASSWORD").orNull } } } publications { create("maven") { groupId = "dev.nyon" - artifactId = "telekinesis-fabric" - version = "${project.version}" + artifactId = "telekinesis" + version = project.version.toString() from(components["java"]) } } } +java { + withSourcesJar() + + javaVersion.toInt() + .let { JavaVersion.values()[it - 1] } + .let { + sourceCompatibility = it + targetCompatibility = it + } +} + +kotlin { + jvmToolchain(javaVersion.toInt()) +} + +/* signing { + val signingKey: String? by project + val signingPassword: String? by project + useGpgCmd() + if (signingKey != null && signingPassword != null) { + useInMemoryPgpKeys(signingKey, signingPassword) + } sign(publishing.publications) } + */ -java { - withSourcesJar() -} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractMinecartMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractMinecartMixin.java new file mode 100644 index 0000000..96d49d8 --- /dev/null +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractMinecartMixin.java @@ -0,0 +1,32 @@ +package dev.nyon.telekinesis.mixins; + +import net.minecraft.world.entity.vehicle.AbstractMinecart; +import org.spongepowered.asm.mixin.Mixin; + +/*? <=1.20.2 {*/ +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.injection.At; +/*?}*/ + +@Mixin(AbstractMinecart.class) +public class AbstractMinecartMixin { + + /*? <=1.20.2 {*/ + @WrapWithCondition(method = "destroy", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + )) + private boolean redirectMinecartDrops( + AbstractMinecart instance, + ItemStack itemStack, + DamageSource damageSource + ) { + if (!(damageSource.getEntity() instanceof LivingEntity livingEntity)) return true; + return EntityUtils.spawnAtLocationAttacker(livingEntity, itemStack); + } + /*?}*/ +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BoatMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BoatMixin.java new file mode 100644 index 0000000..330867c --- /dev/null +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BoatMixin.java @@ -0,0 +1,31 @@ +package dev.nyon.telekinesis.mixins; + +import net.minecraft.world.entity.vehicle.Boat; +import org.spongepowered.asm.mixin.Mixin; + +/*? <=1.20.2 {*/ +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import dev.nyon.telekinesis.utils.EntityUtils; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.item.Item; +import org.spongepowered.asm.mixin.injection.At; +/*?}*/ + +@Mixin(Boat.class) +public class BoatMixin { + /*? <=1.20.2 {*/ + @ModifyExpressionValue( + method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/vehicle/Boat;getDropItem()Lnet/minecraft/world/item/Item;" + ) + ) + private Item changeDroppedItem( + Item original, + DamageSource damageSource + ) { + return EntityUtils.getDropItemInject(original, damageSource); + } + /*?}*/ +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java index abc6fdd..0fd5b5b 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java @@ -1,16 +1,20 @@ package dev.nyon.telekinesis.mixins; +import net.minecraft.world.entity.vehicle.ChestBoat; +import org.spongepowered.asm.mixin.Mixin; + +/*? if >1.20.2 {*//* import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.vehicle.ChestBoat; import net.minecraft.world.item.Item; -import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; + *//*?}*/ @Mixin(ChestBoat.class) public class ChestBoatMixin { + /*? if >1.20.2 {*//* @ModifyExpressionValue( method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At( @@ -24,4 +28,5 @@ private Item changeDroppedItem( ) { return EntityUtils.getDropItemInject(original, damageSource); } + *//*?}*/ } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java new file mode 100644 index 0000000..ce6b015 --- /dev/null +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java @@ -0,0 +1,32 @@ +package dev.nyon.telekinesis.mixins; + +import net.minecraft.world.entity.vehicle.MinecartTNT; +import org.spongepowered.asm.mixin.Mixin; + +/*? if >1.20.2 {*//* +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import dev.nyon.telekinesis.utils.EntityUtils; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.item.Item; +import org.spongepowered.asm.mixin.injection.At; + *//*?}*/ + +@Mixin(MinecartTNT.class) +public class MinecartTNTMixin { + + /*? if >1.20.2 {*//* + @ModifyExpressionValue( + method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/vehicle/MinecartTNT;getDropItem()Lnet/minecraft/world/item/Item;" + ) + ) + private Item changeDroppedItem( + Item original, + DamageSource damageSource + ) { + return EntityUtils.getDropItemInject(original, damageSource); + } + *//*?}*/ +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SweetBerryBushBlockMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SweetBerryBushBlockMixin.java index 459485b..fd40d74 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SweetBerryBushBlockMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SweetBerryBushBlockMixin.java @@ -5,6 +5,7 @@ import dev.nyon.telekinesis.utils.TelekinesisUtils; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -17,6 +18,7 @@ @Mixin(SweetBerryBushBlock.class) public class SweetBerryBushBlockMixin { + /*? >1.20.5 {*//* @WrapWithCondition( method = "useWithoutItem", at = @At( @@ -46,4 +48,36 @@ private boolean manipulateBerryDrops( return !hasTelekinesis; } -} \ No newline at end of file + *//*?} else {*/ + @WrapWithCondition( + method = "use", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/SweetBerryBushBlock;popResource(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V" + ) + ) + private boolean manipulateBerryDrops( + Level level, + BlockPos blockPos, + ItemStack itemStack, + BlockState state, + Level _level, + BlockPos pos, + Player player, + InteractionHand hand, + BlockHitResult hit + ) { + if (!(player instanceof ServerPlayer serverPlayer)) return true; + + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.BlockDrops, + serverPlayer, + serverPlayer.getMainHandItem(), + cPlayer -> { + if (!player.addItem(itemStack)) Block.popResource(level, blockPos, itemStack); + } + ); + + return !hasTelekinesis; + } + /*?}*/ +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java index 07718b2..7f44166 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java @@ -3,12 +3,13 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.vehicle.VehicleEntity; import net.minecraft.world.item.Item; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; -@Mixin(VehicleEntity.class) +@Pseudo +@Mixin(targets = "net.minecraft.world.entity.vehicle.VehicleEntity") public class VehicleEntityMixin { @ModifyExpressionValue( diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java index fd3548e..f06e1a9 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java @@ -28,13 +28,18 @@ public static boolean spawnAtLocationInject( ItemStack item ) { final var attacker = entity.getLastAttacker(); + + return spawnAtLocationAttacker(attacker, item); + } + + public static boolean spawnAtLocationAttacker(LivingEntity attacker, ItemStack item) { if (!(attacker instanceof ServerPlayer serverPlayer)) return true; boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, serverPlayer, serverPlayer.getMainHandItem(), player -> { - if (!player.addItem(item)) entity.spawnAtLocation(item); + if (!player.addItem(item)) attacker.spawnAtLocation(item); } ); diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt index dd9f8e1..899024c 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt @@ -2,13 +2,19 @@ package dev.nyon.telekinesis import net.minecraft.network.chat.Component import net.minecraft.network.chat.Style -import net.minecraft.tags.ItemTags -import net.minecraft.world.entity.EquipmentSlot import net.minecraft.world.item.enchantment.Enchantment +import net.minecraft.world.entity.EquipmentSlot +/*? >1.20.5 {*//* +import net.minecraft.tags.ItemTags +*//*?} else {*/ +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.entity.MobType +import net.minecraft.world.item.enchantment.EnchantmentCategory +/*?}*/ -/** - * The telekinesis enchantment model - */ + + +/*? >1.20.5 {*//* class TelekinesisEnchantment : Enchantment( definition( ItemTags.DURABILITY_ENCHANTABLE, @@ -23,3 +29,21 @@ class TelekinesisEnchantment : Enchantment( override fun getFullname(i: Int): Component = Component.translatable("enchantment.telekinesis.telekinesis.name").withStyle(Style.EMPTY.withColor(0xFFB64C)) } +*//*?} else {*/ +class TelekinesisEnchantment : Enchantment( + Rarity.RARE, EnchantmentCategory.BREAKABLE, listOf(EquipmentSlot.OFFHAND, EquipmentSlot.MAINHAND).toTypedArray() +) { + + override fun getMinLevel(): Int = 1 + override fun getMaxLevel(): Int = 1 + + override fun getMinCost(i: Int): Int = 25 + override fun getMaxCost(i: Int): Int = 50 + + override fun getDamageProtection(i: Int, damageSource: DamageSource): Int = 0 + override fun getDamageBonus(i: Int, mobType: MobType): Float = 0F + + override fun getFullname(i: Int): Component = + Component.translatable("enchantment.telekinesis.telekinesis.name").withStyle(Style.EMPTY.withColor(0xFFB64C)) +} +/*?}*/ diff --git a/telekinesis-fabric/src/main/resources/fabric.mod.json b/telekinesis-fabric/src/main/resources/fabric.mod.json index f873b06..5a0749f 100644 --- a/telekinesis-fabric/src/main/resources/fabric.mod.json +++ b/telekinesis-fabric/src/main/resources/fabric.mod.json @@ -18,12 +18,12 @@ "version": "${version}", "environment": "*", "depends": { - "fabric-language-kotlin": ">=1.10.19+kotlin.1.9.23", - "yet_another_config_lib_v3": ">=3.3.1+1.20.4", - "minecraft": ">1.20.4" + "fabric-language-kotlin": ">=1.10.20+kotlin.1.9.24", + "yet_another_config_lib_v3": "*", + "minecraft": "${mc}" }, "suggests": { - "modmenu": ">=10.0.0-alpha.3" + "modmenu": "*" }, "entrypoints": { "main": [ diff --git a/telekinesis-fabric/src/main/resources/telekinesis.mixins.json b/telekinesis-fabric/src/main/resources/telekinesis.mixins.json index ac771f1..4c5bf60 100644 --- a/telekinesis-fabric/src/main/resources/telekinesis.mixins.json +++ b/telekinesis-fabric/src/main/resources/telekinesis.mixins.json @@ -6,8 +6,10 @@ "mixins": [ "AbstractChestedHorseMixin", "AbstractHorseMixin", + "AbstractMinecartMixin", "AllayMixin", "BlockMixin", + "BoatMixin", "CatalystBlockAccessor", "ChestBoatMixin", "DropExperienceBlockAccessor", @@ -16,6 +18,7 @@ "FishingHookMixin", "InventoryMixin", "LivingEntityMixin", + "MinecartTNTMixin", "MinecraftServerMixin", "MobMixin", "PiglinMixin", @@ -30,4 +33,4 @@ "injectors": { "defaultRequire": 1 } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/stonecutter.gradle.kts b/telekinesis-fabric/stonecutter.gradle.kts new file mode 100644 index 0000000..495263e --- /dev/null +++ b/telekinesis-fabric/stonecutter.gradle.kts @@ -0,0 +1,16 @@ +plugins { + id("dev.kikugie.stonecutter") +} +stonecutter active "1.20.1" /* [SC] DO NOT EDIT */ + +stonecutter registerChiseled + tasks.register("buildAllVersions", stonecutter.chiseled) { + group = "mod" + ofTask("build") + } + +stonecutter registerChiseled + tasks.register("releaseAllVersions", stonecutter.chiseled) { + group = "mod" + ofTask("releaseMod") + } diff --git a/telekinesis-fabric/versions/1.20.1/gradle.properties b/telekinesis-fabric/versions/1.20.1/gradle.properties new file mode 100644 index 0000000..68beccc --- /dev/null +++ b/telekinesis-fabric/versions/1.20.1/gradle.properties @@ -0,0 +1,10 @@ +mcVersion=1.20.1 +mcVersionRange=>=1.20 <=1.20.3 +supportedMcVersions=1.20,1.20.1 + +deps.parchment=1.20.1:2023.09.03 +deps.fapi=0.92.1+1.20.1 +deps.yacl=3.4.2+1.20.1-fabric +deps.modMenu=7.2.2 + +javaVer=17 diff --git a/telekinesis-fabric/versions/1.20.4/gradle.properties b/telekinesis-fabric/versions/1.20.4/gradle.properties new file mode 100644 index 0000000..60732ac --- /dev/null +++ b/telekinesis-fabric/versions/1.20.4/gradle.properties @@ -0,0 +1,10 @@ +mcVersion=1.20.4 +mcVersionRange=>=1.20.3 <=1.20.4 +supportedMcVersions=1.20.4 + +deps.parchment=1.20.4:2024.04.14 +deps.fapi=0.97.0+1.20.4 +deps.yacl=3.4.2+1.20.4-fabric +deps.modMenu=9.2.0-beta.2 + +javaVer=17 diff --git a/telekinesis-fabric/versions/1.20.6/gradle.properties b/telekinesis-fabric/versions/1.20.6/gradle.properties new file mode 100644 index 0000000..7a02cb9 --- /dev/null +++ b/telekinesis-fabric/versions/1.20.6/gradle.properties @@ -0,0 +1,10 @@ +mcVersion=1.20.6 +mcVersionRange=>=1.20.5 <=1.20.6 +supportedMcVersions=1.20.5,1.20.6 + +deps.parchment=1.20.6:2024.05.01 +deps.fapi=0.97.8+1.20.6 +deps.yacl=3.4.2+1.20.5-fabric +deps.modMenu=10.0.0-beta.1 + +javaVer=21