Skip to content

Commit

Permalink
update to 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Oct 17, 2024
1 parent c692aca commit 493285f
Show file tree
Hide file tree
Showing 32 changed files with 266 additions and 100 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
}
}
```
Expand Down
35 changes: 11 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -109,7 +108,7 @@ tasks {

withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.fromTarget(javaVersion)
jvmTarget = JvmTarget.fromTarget(javaVersion.toString())
}
}
}
Expand All @@ -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" }
}

Expand Down Expand Up @@ -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)
}
*/

5 changes: 3 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- only limit fabric.mod.json Minecraft requirement for versions of Minecraft that are too old
- remove old mixinsquared import
- add support for 1.21.2
- update kotlin and klf to 2.0.21
- do not require yacl anymore
14 changes: 6 additions & 8 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
import dev.kikugie.stonecutter.StonecutterSettings

rootProject.name = "telekinesis"

pluginManagement {
repositories {
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<StonecutterSettings> {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 33 additions & 12 deletions src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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 {*/
Expand All @@ -48,8 +51,23 @@ public int redirectExp(
return MixinHelper.modifyExpressionValuePlayerExp(player, original);
}

@Unique
private Consumer<ItemStack> replaceConsumer(LootParams params, Consumer<ItemStack> 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<ItemStack> 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"
Expand All @@ -61,18 +79,21 @@ public Consumer<ItemStack> redirectCommonDrops(
long seed,
Consumer<ItemStack> original
) {
DamageSource source = params.getParamOrNull(LootContextParams.DAMAGE_SOURCE);
if (source == null || !(source.getEntity() instanceof ServerPlayer player)) return original;

return item -> {
ArrayList<ItemStack> 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<ItemStack> redirectDropConsumer(Consumer<ItemStack> original, @Local(ordinal = 0) LootParams params) {
return replaceConsumer(params, original);
}
*//*?}*/

/*? if <1.21 {*/
/*@WrapOperation(
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Loading

0 comments on commit 493285f

Please sign in to comment.