diff --git a/README.md b/README.md index 3848a01..5187f82 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ This mod/plugin adds the telekinesis enchantment, allowing you to instantly move exp and item drops into your inventory. This includes the drops from mobs, vehicles and blocks. +## Where can I get this enchantment? + +You can trade this enchantment with villagers, enchant it in an enchanting table, or you can find it in treasures +enchanting on tools. + ## Configuration The configuration file can be found in the client/server directory. @@ -13,12 +18,17 @@ The configuration file can be found in the client/server directory. ```json5 { - "version": 1, // For migration purposes only, just ignore this. + "version": 1, + // For migration purposes only, just ignore this. "config": { - "needEnchantment": true, // Defines, whether telekinesis should without or with the enchantment on the tool. - "needSneak": false, // Defines. whether the player should have to sneak in order to use telekinesis. - "expAllowed": true, // Enables the use of telekinesis for exp drops. - "itemsAllowed": true // Enables the use of telekinesis for item drops. + "needEnchantment": true, + // Defines, whether telekinesis should without or with the enchantment on the tool. + "needSneak": false, + // Defines. whether the player should have to sneak in order to use telekinesis. + "expAllowed": true, + // Enables the use of telekinesis for exp drops. + "itemsAllowed": true + // Enables the use of telekinesis for item drops. } } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 4f0cb49..2d66786 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,18 +4,17 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "2.0.10" - kotlin("plugin.serialization") version "2.0.10" - id("fabric-loom") version "1.7-SNAPSHOT" + kotlin("jvm") version "2.0.21" + kotlin("plugin.serialization") version "2.0.21" + id("fabric-loom") version "1.8-SNAPSHOT" - id("me.modmuss50.mod-publish-plugin") version "0.5.+" + id("me.modmuss50.mod-publish-plugin") version "0.7.+" `maven-publish` - signing } val beta: Int? = null // Pattern is '1.0.0-beta1-1.20.6-pre.2' -val featureVersion = "3.0.5${if (beta != null) "-beta$beta" else ""}" +val featureVersion = "3.0.6${if (beta != null) "-beta$beta" else ""}" val mcVersion = property("mcVersion")!!.toString() val mcVersionRange = property("mcVersionRange")!!.toString() version = "$featureVersion-$mcVersion" @@ -63,17 +62,17 @@ dependencies { }) implementation("org.vineflower:vineflower:1.10.1") - modImplementation("net.fabricmc:fabric-loader:0.16.0") + modImplementation("net.fabricmc:fabric-loader:0.16.7") modImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")!!}") - modImplementation("net.fabricmc:fabric-language-kotlin:1.12.0+kotlin.2.0.10") + modImplementation("net.fabricmc:fabric-language-kotlin:1.12.3+kotlin.2.0.21") - modImplementation("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}") + modCompileOnly("dev.isxander:yet-another-config-lib:${property("deps.yacl")!!}") modImplementation("com.terraformersmc:modmenu:${property("deps.modMenu")!!}") include(modImplementation("dev.nyon:konfig:2.0.2-1.20.4")!!) } -val javaVersion = property("javaVer")!!.toString() +val javaVersion = if (stonecutter.eval(mcVersion, ">=1.20.6")) 21 else 17 tasks { processResources { val modId = "telekinesis" @@ -109,7 +108,7 @@ tasks { withType { compilerOptions { - jvmTarget = JvmTarget.fromTarget(javaVersion) + jvmTarget = JvmTarget.fromTarget(javaVersion.toString()) } } } @@ -135,8 +134,8 @@ publishMods { minecraftVersions.addAll(supportedMcVersions) requires { slug = "fabric-api" } - requires { slug = "yacl" } requires { slug = "fabric-language-kotlin" } + optional { slug = "yacl" } optional { slug = "modmenu" } } @@ -177,15 +176,3 @@ java { } } -/* -signing { - val signingKey: String? by project - val signingPassword: String? by project - useGpgCmd() - if (signingKey != null && signingPassword != null) { - useInMemoryPgpKeys(signingKey, signingPassword) - } - sign(publishing.publications) -} - */ - diff --git a/changelog.md b/changelog.md index f2af551..175b59d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,2 +1,3 @@ -- only limit fabric.mod.json Minecraft requirement for versions of Minecraft that are too old -- remove old mixinsquared import \ No newline at end of file +- add support for 1.21.2 +- update kotlin and klf to 2.0.21 +- do not require yacl anymore \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6e93fac..efe916f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,3 @@ -import dev.kikugie.stonecutter.StonecutterSettings - rootProject.name = "telekinesis" pluginManagement { @@ -7,27 +5,27 @@ pluginManagement { gradlePluginPortal() maven("https://maven.fabricmc.net/") maven("https://server.bbkr.space/artifactory/libs-release/") - maven("https://maven.kikugie.dev/releases") + maven("https://maven.kikugie.dev/snapshots") } } plugins { - id("dev.kikugie.stonecutter") version "0.4" + id("dev.kikugie.stonecutter") version "0.5-beta.3" } buildscript { repositories { mavenCentral() } dependencies { - classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0-RC") + classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") } } -extensions.configure { +stonecutter { kotlinController = true centralScript = "build.gradle.kts" shared { - versions("1.20.1", "1.20.4", "1.20.6", "1.21") + versions("1.20.1", "1.20.4", "1.20.6", "1.21", "1.21.2") vcsVersion = "1.21" } create(rootProject) -} +} \ No newline at end of file diff --git a/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java index a05205b..a5f20a7 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; @@ -15,13 +16,14 @@ public class AbstractChestedHorseMixin { method = "dropEquipment", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/animal/horse/AbstractChestedHorse;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/animal/horse/AbstractChestedHorse;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/animal/horse/AbstractChestedHorse;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyEquipmentDrop( AbstractChestedHorse instance, + /*$ serverLevel {*//*$}*/ ItemLike item ) { return MixinHelper.entityDropEquipmentSingle(instance, new ItemStack(item)); } -} +} \ No newline at end of file diff --git a/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java index 04febc9..3345009 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; @@ -14,11 +15,12 @@ public class AbstractHorseMixin { method = "dropEquipment", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyEquipmentDrop( AbstractHorse instance, + /*$ serverLevel {*/ /*$}*/ ItemStack stack ) { return MixinHelper.entityDropEquipmentSingle(instance, stack); @@ -28,11 +30,12 @@ public boolean modifyEquipmentDrop( method = "dropEquipment", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyEquipmentDrops( AbstractHorse instance, + /*$ serverLevel {*//*$}*/ ItemStack itemStack ) { return MixinHelper.entityDropEquipmentSingle(instance, itemStack); diff --git a/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java index 4523d24..6279b72 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java @@ -3,6 +3,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.animal.allay.Allay; import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; @@ -21,11 +22,12 @@ public class AllayMixin { method = "dropEquipment", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/animal/allay/Allay;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/animal/allay/Allay;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/animal/allay/Allay;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyEquipmentDrop( Allay instance, + /*$ serverLevel {*//*$}*/ ItemStack stack ) { return MixinHelper.entityDropEquipmentSingle(instance, stack); diff --git a/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java index f532783..f486a11 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java @@ -1,18 +1,20 @@ package dev.nyon.telekinesis.mixins; -import dev.nyon.telekinesis.utils.MixinHelper; import net.minecraft.world.entity.vehicle.ChestBoat; import org.spongepowered.asm.mixin.Mixin; +/*? if >1.20.2 && <1.21.2 {*/ +import dev.nyon.telekinesis.utils.MixinHelper; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.item.Item; import org.spongepowered.asm.mixin.injection.At; +/*?}*/ @Mixin(ChestBoat.class) public abstract class ChestBoatMixin { - /*? if >1.20.2 {*/ + /*? if >1.20.2 && <1.21.2 {*/ @WrapOperation( method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At( diff --git a/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java index ce86988..856d4b2 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java @@ -16,11 +16,12 @@ public class EnderManMixin { method = "dropCustomDeathLoot", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/monster/EnderMan;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/monster/EnderMan;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/monster/EnderMan;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean redirectEquipmentDrop( EnderMan instance, + /*$ serverLevel {*//*$}*/ ItemStack itemStack, /*? if >=1.21 {*/ ServerLevel serverLevel, diff --git a/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java index 0f49141..e1ffdf6 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java @@ -3,8 +3,10 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; import dev.nyon.telekinesis.DropEvent; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; @@ -14,7 +16,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import org.apache.commons.lang3.mutable.MutableInt; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -36,6 +38,7 @@ public abstract class LivingEntityMixin { ) public int redirectExp( int original + /*? if >=1.21.2 {*//*,ServerLevel level*//*?}*/ /*? if >=1.21*/, Entity entity ) { /*? if >=1.21 {*/ @@ -48,8 +51,23 @@ public int redirectExp( return MixinHelper.modifyExpressionValuePlayerExp(player, original); } + @Unique + private Consumer replaceConsumer(LootParams params, Consumer original) { + DamageSource source = params/*? if <1.21.2 {*/.getParamOrNull(LootContextParams.DAMAGE_SOURCE) /*?} else {*//*.contextMap().getOptional(LootContextParams.DAMAGE_SOURCE) *//*?}*/; + if (source == null || !(source.getEntity() instanceof ServerPlayer player)) return original; + + return item -> { + ArrayList mutableList = new ArrayList<>(List.of(item)); + DropEvent.INSTANCE.getEvent() + .invoker() + .invoke(mutableList, new MutableInt(0), player, player.getMainHandItem()); + + if (!mutableList.isEmpty()) original.accept(item); + }; + } + @ModifyArg( - method = "dropFromLootTable", + method = "dropFromLootTable(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;Z)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/storage/loot/LootTable;getRandomItems(Lnet/minecraft/world/level/storage/loot/LootParams;JLjava/util/function/Consumer;)V" @@ -61,18 +79,21 @@ public Consumer redirectCommonDrops( long seed, Consumer original ) { - DamageSource source = params.getParamOrNull(LootContextParams.DAMAGE_SOURCE); - if (source == null || !(source.getEntity() instanceof ServerPlayer player)) return original; - - return item -> { - ArrayList mutableList = new ArrayList<>(List.of(item)); - DropEvent.INSTANCE.getEvent() - .invoker() - .invoke(mutableList, new MutableInt(0), player, player.getMainHandItem()); + return replaceConsumer(params, original); + } - if (!mutableList.isEmpty()) original.accept(item); - }; + /*? if >=1.21.2 {*/ + /*@ModifyArg( + method = "dropFromLootTable(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/resources/ResourceKey;Ljava/util/function/Function;Ljava/util/function/BiConsumer;)Z", + at = @At( + value = "INVOKE", + target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V" + ) + ) + public Consumer redirectDropConsumer(Consumer original, @Local(ordinal = 0) LootParams params) { + return replaceConsumer(params, original); } + *//*?}*/ /*? if <1.21 {*/ /*@WrapOperation( diff --git a/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java index b1e6475..5033f75 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java @@ -1,21 +1,21 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import dev.nyon.telekinesis.utils.MixinHelper; import net.minecraft.world.entity.vehicle.MinecartTNT; import org.spongepowered.asm.mixin.Mixin; -/*? if >1.20.2 {*/ +/*? if >1.20.2 && <1.21.2 {*/ +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.nyon.telekinesis.utils.MixinHelper; 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 {*/ + /*? if >1.20.2 && <1.21.2 {*/ @WrapOperation( method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At( diff --git a/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java index aa6594e..173e55b 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java @@ -16,11 +16,12 @@ public class MobMixin { method = "dropCustomDeathLoot", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyCustomDeathLoot( Mob instance, + /*$ serverLevel {*//*$}*/ ItemStack itemStack, /*? if >=1.21 {*/ ServerLevel serverLevel, DamageSource damageSource, boolean bl /*?} else {*/ /*DamageSource damageSource, int looting, boolean hitByPlayer *//*?}*/ ) { @@ -29,14 +30,15 @@ public boolean modifyCustomDeathLoot( /*? if >=1.21 {*/ @WrapWithCondition( - method = "dropPreservedEquipment(Ljava/util/function/Predicate;)Ljava/util/Set;", + method = /*? if needsWorldNow {*//*"dropPreservedEquipment(Lnet/minecraft/server/level/ServerLevel;Ljava/util/function/Predicate;)Ljava/util/Set;"*//*?} else {*/ "dropPreservedEquipment(Ljava/util/function/Predicate;)Ljava/util/Set;" /*?}*/, at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyCustomDeathLoot( Mob instance, + /*$ serverLevel {*//*$}*/ ItemStack itemStack ) { return MixinHelper.entityDropEquipmentSingle(instance, itemStack); diff --git a/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java index b5bf54c..dd3b8a6 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.animal.Pig; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; @@ -15,11 +16,12 @@ public class PigMixin { method = "dropEquipment", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/animal/Pig;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/animal/Pig;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/animal/Pig;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean modifyEquipmentDrop( Pig instance, + /*$ serverLevel {*//*$}*/ ItemLike item ) { return MixinHelper.entityDropEquipmentSingle(instance, new ItemStack(item)); diff --git a/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java index 0130a86..5e1a469 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java @@ -1,6 +1,5 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import dev.nyon.telekinesis.utils.MixinHelper; @@ -10,11 +9,24 @@ import net.minecraft.world.entity.animal.Sheep; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +/*? if <1.21.2 {*/ +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.world.level.block.Block; import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal; +/*?} else {*/ +/*import dev.nyon.telekinesis.DropEvent; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.damagesource.DamageSource; +import org.apache.commons.lang3.mutable.MutableInt; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; +*//*?}*/ @Mixin(Sheep.class) public abstract class SheepMixin { @@ -23,19 +35,27 @@ public abstract class SheepMixin { method = "mobInteract", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/animal/Sheep;shear(Lnet/minecraft/sounds/SoundSource;)V" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/animal/Sheep;shear(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/sounds/SoundSource;Lnet/minecraft/world/item/ItemStack;)V" + *//*?} else {*/ + "Lnet/minecraft/world/entity/animal/Sheep;shear(Lnet/minecraft/sounds/SoundSource;)V" + /*?}*/ ) ) private void prepareThreadLocalForShearing( Sheep instance, + /*$ serverLevel {*//*$}*/ SoundSource source, + /*? if >=1.21.2 {*/ + /*ItemStack itemStack, + *//*?}*/ Operation original, - Player _player, + Player player, InteractionHand hand ) { - MixinHelper.prepareShearableServerPlayer(instance, source, original, _player); + MixinHelper.prepareShearableServerPlayer(instance, source, original, player); } + /*? if <1.21.2 {*/ @ModifyExpressionValue( method = "shear", at = @At( @@ -51,4 +71,31 @@ private Object modifyShearDrops(Object original) { if (MixinHelper.wrapWithConditionPlayerItemSingle(player, new ItemStack(block))) return original; else return ItemStack.EMPTY; } + /*?} else {*/ + + /*@Unique + private Sheep instance = (Sheep) (Object) this; + + @ModifyArg( + method = "shear", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/animal/Sheep;dropFromShearingLootTable(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/item/ItemStack;Ljava/util/function/BiConsumer;)V" + ), + index = 3 + ) + private BiConsumer changeOriginalDropConsumer(BiConsumer original) { + DamageSource source = instance.getLastDamageSource(); + if (source == null || !(source.getEntity() instanceof ServerPlayer player)) return original; + + return (world, item) -> { + ArrayList mutableList = new ArrayList<>(List.of(item)); + DropEvent.INSTANCE.getEvent() + .invoker() + .invoke(mutableList, new MutableInt(0), player, player.getMainHandItem()); + + if (!mutableList.isEmpty()) original.accept(world, item); + }; + } + *//*?}*/ } \ No newline at end of file diff --git a/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java index 133b7c5..3092ede 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java @@ -1,24 +1,27 @@ package dev.nyon.telekinesis.mixins; +/*? if <1.21.2 {*/ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import dev.nyon.telekinesis.utils.MixinHelper; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; -import net.minecraft.world.entity.animal.SnowGolem; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; -import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal; +/*?}*/ +import net.minecraft.world.entity.animal.SnowGolem; +import org.spongepowered.asm.mixin.Mixin; @Mixin(SnowGolem.class) public class SnowGolemMixin { + /*? if <1.21.2 {*/ @WrapOperation( method = "mobInteract", at = @At( @@ -49,4 +52,5 @@ private ItemLike modifyShearDrops(ItemLike original) { if (MixinHelper.wrapWithConditionPlayerItemSingle(player, new ItemStack(original))) return original; else return Items.AIR; } + /*?}*/ } diff --git a/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java index 6e4e0cd..89d7aad 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.monster.Strider; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; @@ -15,11 +16,12 @@ public class StriderMixin { method = "dropEquipment", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/monster/Strider;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/monster/Strider;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/monster/Strider;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) public boolean redirectEquipmentDrop( Strider instance, + /*$ serverLevel {*/ /*$}*/ ItemLike item ) { return MixinHelper.entityDropEquipmentSingle(instance, new ItemStack(item)); diff --git a/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java index 13be492..acbdc45 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/VehicleEntityMixin.java @@ -4,6 +4,7 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.damagesource.DamageSource; /*? if >=1.20.4*/ import net.minecraft.world.entity.vehicle.VehicleEntity; @@ -18,7 +19,7 @@ @Pseudo @Mixin(targets = "net.minecraft.world.entity.vehicle.VehicleEntity") public class VehicleEntityMixin { - /*? if >=1.20.4 {*/ + /*? if >=1.20.4 && <1.21.2 {*/ @WrapOperation( method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At( @@ -51,5 +52,24 @@ private boolean replaceDropItem( return MixinHelper.wrapWithConditionPlayerItemSingle(player, itemStack); } - /*?}*/ + /*?} elif >=1.21.2 {*/ + + /*@WrapWithCondition( + method = "Lnet/minecraft/world/entity/vehicle/VehicleEntity;destroy(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/Item;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/vehicle/VehicleEntity;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;" + ) + ) + private boolean replaceDropItem( + VehicleEntity instance, + ServerLevel world, + ItemStack itemStack + ) { + ServerPlayer player = threadLocal.get(); + if (player == null) return true; + + return MixinHelper.wrapWithConditionPlayerItemSingle(player, itemStack); + } + *//*?}*/ } \ No newline at end of file diff --git a/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java b/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java index dbec90e..49fbb56 100644 --- a/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java +++ b/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java @@ -18,7 +18,7 @@ public abstract class WitherBossMixin { method = "dropCustomDeathLoot", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/boss/wither/WitherBoss;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = /*? if needsWorldNow {*//*"Lnet/minecraft/world/entity/boss/wither/WitherBoss;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;"*//*?} else {*/ "Lnet/minecraft/world/entity/boss/wither/WitherBoss;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" /*?}*/ ) ) protected void redirectEquipmentDrop( diff --git a/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt b/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt index 23d04fd..24b08b6 100644 --- a/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt +++ b/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt @@ -11,7 +11,7 @@ import net.minecraft.core.HolderLookup import net.minecraft.core.registries.Registries import net.minecraft.resources.ResourceKey import net.minecraft.resources.ResourceLocation -import net.minecraft.tags.TagKey +import net.minecraft.tags.EnchantmentTags import net.minecraft.world.entity.EquipmentSlotGroup import net.minecraft.world.item.enchantment.Enchantment import net.minecraft.world.item.enchantment.Enchantment.EnchantmentDefinition @@ -35,13 +35,12 @@ private class TelekinesisEnchantmentTagProvider( output: FabricDataOutput, completableFuture: CompletableFuture ) : EnchantmentTagProvider(output, completableFuture) { override fun addTags(registries: HolderLookup.Provider) { - fun minecraftTagKey(value: String): TagKey = TagKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("minecraft", value)) val enchantmentResourceKey = ResourceKey.create(Registries.ENCHANTMENT, telekinesisEnchantmentId) listOf( getOrCreateTagBuilder(telekinesisEffectId), - getOrCreateTagBuilder(minecraftTagKey("tradeable")), - getOrCreateTagBuilder(minecraftTagKey("treasure")), - getOrCreateTagBuilder(minecraftTagKey("non_treasure")) + getOrCreateTagBuilder(EnchantmentTags.TRADEABLE), + getOrCreateTagBuilder(EnchantmentTags.IN_ENCHANTING_TABLE), + getOrCreateTagBuilder(EnchantmentTags.TREASURE) ).forEach { it.addOptional(enchantmentResourceKey) } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2f96b0c..3b3ba18 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,10 +19,10 @@ "environment": "*", "depends": { "fabric-language-kotlin": ">=1.12.0+kotlin.2.0.10", - "yet_another_config_lib_v3": "*", "minecraft": "${mc}" }, "suggests": { + "yet_another_config_lib_v3": "*", "modmenu": "*" }, "entrypoints": { diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 0296b69..cd9edcc 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -1,3 +1,4 @@ +import dev.kikugie.stonecutter.Identifier import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* @@ -12,6 +13,13 @@ plugins { } stonecutter active "1.21" /* [SC] DO NOT EDIT */ +stonecutter parameters { + val needsWorldNow = eval(stonecutter.current.version, ">=1.21.2") + const("needsWorldNow", needsWorldNow) + + swaps["serverLevel"] = if (needsWorldNow) "ServerLevel level," else "" +} + stonecutter registerChiseled tasks.register("buildAllVersions", stonecutter.chiseled) { group = "mod" ofTask("build") @@ -65,7 +73,10 @@ tasks.register("postUpdate") { color = 0xff0080, fields = listOf( Field( - "Supported versions", stonecutter.versions.joinToString { it.version }, false + "Supported versions", + stonecutter.tree.nodes.map { it.property("vers.supportedMcVersions").toString().split(',') } + .flatten().toSet().joinToString(), + false ), Field("Modrinth", "https://modrinth.com/mod/telekinesis", true), Field("GitHub", "https://github.com/btwonion/telekinesis", true) diff --git a/versions/1.20.1/gradle.properties b/versions/1.20.1/gradle.properties index 33fbb90..346e4c6 100644 --- a/versions/1.20.1/gradle.properties +++ b/versions/1.20.1/gradle.properties @@ -5,6 +5,4 @@ supportedMcVersions=1.20,1.20.1 deps.quiltmappings=1.20.1+build.9 deps.fapi=0.92.2+1.20.1 deps.yacl=3.5.0+1.20.1-fabric -deps.modMenu=7.2.2 - -javaVer=17 +deps.modMenu=7.2.2 \ No newline at end of file diff --git a/versions/1.20.4/gradle.properties b/versions/1.20.4/gradle.properties index b01b245..bc5e3bf 100644 --- a/versions/1.20.4/gradle.properties +++ b/versions/1.20.4/gradle.properties @@ -1,10 +1,8 @@ mcVersion=1.20.4 mcVersionRange=>=1.20.3 -supportedMcVersions=1.20.4 +supportedMcVersions=1.20.3,1.20.4 deps.quiltmappings=1.20.4+build.3 deps.fapi=0.97.1+1.20.4 deps.yacl=3.5.0+1.20.4-fabric -deps.modMenu=9.2.0-beta.2 - -javaVer=17 +deps.modMenu=9.2.0-beta.2 \ No newline at end of file diff --git a/versions/1.20.6/gradle.properties b/versions/1.20.6/gradle.properties index 1345b3e..93fd2c8 100644 --- a/versions/1.20.6/gradle.properties +++ b/versions/1.20.6/gradle.properties @@ -5,6 +5,4 @@ supportedMcVersions=1.20.5,1.20.6 deps.quiltmappings=1.20.6+build.6 deps.fapi=0.100.8+1.20.6 deps.yacl=3.5.0+1.20.6-fabric -deps.modMenu=10.0.0-beta.1 - -javaVer=21 +deps.modMenu=10.0.0-beta.1 \ No newline at end of file diff --git a/versions/1.21.2/gradle.properties b/versions/1.21.2/gradle.properties new file mode 100644 index 0000000..6ae9930 --- /dev/null +++ b/versions/1.21.2/gradle.properties @@ -0,0 +1,8 @@ +mcVersion=1.21.2-rc1 +mcVersionRange=>1.20.6 +supportedMcVersions=1.20.2-rc1 + +deps.quiltmappings=1.21.2-pre5+build.1 +deps.fapi=0.106.0+1.21.2 +deps.yacl=3.5.0+1.21-fabric +deps.modMenu=12.0.0-beta.1 \ No newline at end of file diff --git a/versions/1.21/src/main/generated/data/minecraft/tags/enchantment/non_treasure.json b/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/in_enchanting_table.json similarity index 100% rename from versions/1.21/src/main/generated/data/minecraft/tags/enchantment/non_treasure.json rename to versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/in_enchanting_table.json diff --git a/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/tradeable.json b/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/tradeable.json new file mode 100644 index 0000000..0d9aebf --- /dev/null +++ b/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/tradeable.json @@ -0,0 +1,8 @@ +{ + "values": [ + { + "id": "telekinesis:telekinesis", + "required": false + } + ] +} \ No newline at end of file diff --git a/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/treasure.json b/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/treasure.json new file mode 100644 index 0000000..0d9aebf --- /dev/null +++ b/versions/1.21.2/src/main/generated/data/minecraft/tags/enchantment/treasure.json @@ -0,0 +1,8 @@ +{ + "values": [ + { + "id": "telekinesis:telekinesis", + "required": false + } + ] +} \ No newline at end of file diff --git a/versions/1.21.2/src/main/generated/data/telekinesis/enchantment/telekinesis.json b/versions/1.21.2/src/main/generated/data/telekinesis/enchantment/telekinesis.json new file mode 100644 index 0000000..d589ea8 --- /dev/null +++ b/versions/1.21.2/src/main/generated/data/telekinesis/enchantment/telekinesis.json @@ -0,0 +1,20 @@ +{ + "anvil_cost": 7, + "description": { + "translate": "enchantment.telekinesis.telekinesis.name" + }, + "max_cost": { + "base": 75, + "per_level_above_first": 75 + }, + "max_level": 1, + "min_cost": { + "base": 25, + "per_level_above_first": 25 + }, + "slots": [ + "hand" + ], + "supported_items": "#c:tools", + "weight": 2 +} \ No newline at end of file diff --git a/versions/1.21.2/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json b/versions/1.21.2/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json new file mode 100644 index 0000000..0d9aebf --- /dev/null +++ b/versions/1.21.2/src/main/generated/data/telekinesis/tags/enchantment/auto_move.json @@ -0,0 +1,8 @@ +{ + "values": [ + { + "id": "telekinesis:telekinesis", + "required": false + } + ] +} \ No newline at end of file diff --git a/versions/1.21/gradle.properties b/versions/1.21/gradle.properties index 35dd4a3..87fc1e8 100644 --- a/versions/1.21/gradle.properties +++ b/versions/1.21/gradle.properties @@ -5,6 +5,4 @@ supportedMcVersions=1.21,1.21.1 deps.quiltmappings=1.21+build.9 deps.fapi=0.100.8+1.21 deps.yacl=3.5.0+1.21-fabric -deps.modMenu=11.0.0-beta.1 - -javaVer=21 +deps.modMenu=11.0.0-beta.1 \ No newline at end of file diff --git a/versions/1.21/src/main/generated/data/minecraft/tags/enchantment/in_enchanting_table.json b/versions/1.21/src/main/generated/data/minecraft/tags/enchantment/in_enchanting_table.json new file mode 100644 index 0000000..0d9aebf --- /dev/null +++ b/versions/1.21/src/main/generated/data/minecraft/tags/enchantment/in_enchanting_table.json @@ -0,0 +1,8 @@ +{ + "values": [ + { + "id": "telekinesis:telekinesis", + "required": false + } + ] +} \ No newline at end of file