diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4e0d1ae --- /dev/null +++ b/.editorconfig @@ -0,0 +1,40 @@ +# https://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +max_line_length = 140 + +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{java,kt,kts,scala,rs,xml,kt.spec,kts.spec}] +indent_size = 4 + +[*.{kt,kts}] +ktlint_code_style = ktlint_official +ktlint_ignore_back_ticked_identifier = true +ij_kotlin_allow_trailing_comma_on_call_site = false +ij_kotlin_allow_trailing_comma = false + +ktlint_standard = enabled + +# Don't allow any wildcard imports +ij_kotlin_packages_to_use_import_on_demand = unset + +# Prevent wildcard imports +ij_kotlin_name_count_to_use_star_import = 99 +ij_kotlin_name_count_to_use_star_import_for_members = 99 + +[*.md] +trim_trailing_whitespace = false +max_line_length = unset + +[gradle/verification-metadata.xml] +indent_size = 3 + +[*.yml] +ij_yaml_spaces_within_brackets = false \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 6915995..18780aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,14 @@ plugins { - kotlin("jvm") version "1.9.22" - kotlin("plugin.serialization") version "1.9.22" + 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) - id("fabric-loom") version "1.5-SNAPSHOT" apply (false) + id("fabric-loom") version "1.6-SNAPSHOT" apply (false) id("io.papermc.paperweight.userdev") version "1.5.5" apply (false) } repositories { mavenCentral() -} \ No newline at end of file +} diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..009d339 --- /dev/null +++ b/changelog.md @@ -0,0 +1,2 @@ +- update to 1.20.5 + - no config screen cause of yacl at the moment \ No newline at end of file diff --git a/changelogs/fabric-2.1.0-1.20.md b/changelogs/fabric-2.1.0-1.20.md deleted file mode 100644 index e8b54c7..0000000 --- a/changelogs/fabric-2.1.0-1.20.md +++ /dev/null @@ -1,3 +0,0 @@ -# v1.2.0-1.20 -- update to 1.20 -- update flk \ No newline at end of file diff --git a/changelogs/fabric-2.1.1-1.20.md b/changelogs/fabric-2.1.1-1.20.md deleted file mode 100644 index 37a3c4d..0000000 --- a/changelogs/fabric-2.1.1-1.20.md +++ /dev/null @@ -1,2 +0,0 @@ -# vfabric-2.1.1-1.2.0 -- fix piglins not dropping armor/weapons \ No newline at end of file diff --git a/changelogs/fabric-2.2.0-1.20.md b/changelogs/fabric-2.2.0-1.20.md deleted file mode 100644 index 8cf108d..0000000 --- a/changelogs/fabric-2.2.0-1.20.md +++ /dev/null @@ -1,8 +0,0 @@ -# v2.2.0-1.20 -- add tree-harvester compat -- fix exp drops when telekinesis for exp is disabled -- don't add exp to player and mending simultaneously -- major backend changes -- add onlyOnSneak option (requested by @sternschnaube in #4) -- add config screen -- add modmenu support \ No newline at end of file diff --git a/changelogs/fabric-2.2.1-1.20.1.md b/changelogs/fabric-2.2.1-1.20.1.md deleted file mode 100644 index fd4cc14..0000000 --- a/changelogs/fabric-2.2.1-1.20.1.md +++ /dev/null @@ -1,5 +0,0 @@ -# v2.2.1-1.20 -- update gradle -- update dependencies -- remove unused mixin -- fix sheep shearing bug \ No newline at end of file diff --git a/changelogs/fabric-2.2.2-1.20.1.md b/changelogs/fabric-2.2.2-1.20.1.md deleted file mode 100644 index 8679b09..0000000 --- a/changelogs/fabric-2.2.2-1.20.1.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.2.2-1.20.1 -- fix exp dropping from bows \ No newline at end of file diff --git a/changelogs/fabric-2.3.0-1.20.1.md b/changelogs/fabric-2.3.0-1.20.1.md deleted file mode 100644 index 568b3f1..0000000 --- a/changelogs/fabric-2.3.0-1.20.1.md +++ /dev/null @@ -1,4 +0,0 @@ -# v2.3.0-1.20.1 -- add compat for betternether, levelz -- don't override death function to provide compat for other mods (#7) -- add fishing drops \ No newline at end of file diff --git a/changelogs/fabric-2.3.1-1.20.1.md b/changelogs/fabric-2.3.1-1.20.1.md deleted file mode 100644 index 8cb4781..0000000 --- a/changelogs/fabric-2.3.1-1.20.1.md +++ /dev/null @@ -1,3 +0,0 @@ -# v2.3.1-1.20.1 -- update config -- rename entity drops to vehicle drops \ No newline at end of file diff --git a/changelogs/fabric-2.3.1-1.20.md b/changelogs/fabric-2.3.1-1.20.md deleted file mode 100644 index 049839e..0000000 --- a/changelogs/fabric-2.3.1-1.20.md +++ /dev/null @@ -1,5 +0,0 @@ -# v2.3.1-1.20.2 -- support 1.20.2 -- remove debugging i forgot -- slightly improve mixin compatibility -- fix independent experience by levelz \ No newline at end of file diff --git a/changelogs/fabric-2.3.2-1.20.md b/changelogs/fabric-2.3.2-1.20.md deleted file mode 100644 index 01da15b..0000000 --- a/changelogs/fabric-2.3.2-1.20.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.2-1.20 -- fix wither not dropping the nether star without telekinesis \ No newline at end of file diff --git a/changelogs/fabric-2.3.3-1.20.3.md b/changelogs/fabric-2.3.3-1.20.3.md deleted file mode 100644 index a921e2d..0000000 --- a/changelogs/fabric-2.3.3-1.20.3.md +++ /dev/null @@ -1,5 +0,0 @@ -# v2.3.3-1.20.3 -- update to 1.20.3 -- improve dependency management -- update to fabric loader 0.15.0 -- update to kotlin 1.9.21 \ No newline at end of file diff --git a/changelogs/fabric-2.3.3-1.20.md b/changelogs/fabric-2.3.3-1.20.md deleted file mode 100644 index 3628ca2..0000000 --- a/changelogs/fabric-2.3.3-1.20.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.3-1.20 -- fix exp not adding to levelz counter \ No newline at end of file diff --git a/changelogs/fabric-2.3.4-1.20.4.md b/changelogs/fabric-2.3.4-1.20.4.md deleted file mode 100644 index 72833cb..0000000 --- a/changelogs/fabric-2.3.4-1.20.4.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.4-1.20.4 -- fixes enchantment registration \ No newline at end of file diff --git a/changelogs/fabric-2.3.5-1.20.4.md b/changelogs/fabric-2.3.5-1.20.4.md deleted file mode 100644 index 996a695..0000000 --- a/changelogs/fabric-2.3.5-1.20.4.md +++ /dev/null @@ -1,3 +0,0 @@ -# v2.3.5-1.20.4 -- fix config loading bug -- update dependencies \ No newline at end of file diff --git a/changelogs/fabric-2.4.0-1.20.4.md b/changelogs/fabric-2.4.0-1.20.4.md deleted file mode 100644 index 36f37a2..0000000 --- a/changelogs/fabric-2.4.0-1.20.4.md +++ /dev/null @@ -1,3 +0,0 @@ -# v2.4.0-1.20.4 -- add sweet berry bush drops -- update fabric loader dependency \ No newline at end of file diff --git a/changelogs/paper-2.1.0-1.20.md b/changelogs/paper-2.1.0-1.20.md deleted file mode 100644 index 3c714c3..0000000 --- a/changelogs/paper-2.1.0-1.20.md +++ /dev/null @@ -1,2 +0,0 @@ -# v1.2.0-1.20 -- update to 1.20 \ No newline at end of file diff --git a/changelogs/paper-2.1.1-1.20.1.md b/changelogs/paper-2.1.1-1.20.1.md deleted file mode 100644 index e458426..0000000 --- a/changelogs/paper-2.1.1-1.20.1.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.1.1-1.20.1 -- fix startup bug \ No newline at end of file diff --git a/changelogs/paper-2.2.0-1.20.1.md b/changelogs/paper-2.2.0-1.20.1.md deleted file mode 100644 index a174d43..0000000 --- a/changelogs/paper-2.2.0-1.20.1.md +++ /dev/null @@ -1,4 +0,0 @@ -# 2.2.0-1.20.1 -- revamp backend -- remove mobDrops and shearingDrops from configuration as it is unavailable at this time -- use paper library system for downloading kotlin stdlib and ktoml \ No newline at end of file diff --git a/changelogs/paper-2.3.0-1.20.1.md b/changelogs/paper-2.3.0-1.20.1.md deleted file mode 100644 index bc8fade..0000000 --- a/changelogs/paper-2.3.0-1.20.1.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.0-1.20.1 -- add permission requirements \ No newline at end of file diff --git a/changelogs/paper-2.3.1-1.20.1.md b/changelogs/paper-2.3.1-1.20.1.md deleted file mode 100644 index bd8bc4b..0000000 --- a/changelogs/paper-2.3.1-1.20.1.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.1-1.20.1 -- create better config description \ No newline at end of file diff --git a/changelogs/paper-2.3.2-1.20.1.md b/changelogs/paper-2.3.2-1.20.1.md deleted file mode 100644 index bd8bc4b..0000000 --- a/changelogs/paper-2.3.2-1.20.1.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.1-1.20.1 -- create better config description \ No newline at end of file diff --git a/changelogs/paper-2.3.2-1.20.2.md b/changelogs/paper-2.3.2-1.20.2.md deleted file mode 100644 index c816ace..0000000 --- a/changelogs/paper-2.3.2-1.20.2.md +++ /dev/null @@ -1,2 +0,0 @@ -# v2.3.1-1.20.2 -- port to 1.20.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2bbac7d..a8382d7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file diff --git a/telekinesis-fabric/build.gradle.kts b/telekinesis-fabric/build.gradle.kts index 730bcf5..0229582 100644 --- a/telekinesis-fabric/build.gradle.kts +++ b/telekinesis-fabric/build.gradle.kts @@ -1,8 +1,6 @@ @file:Suppress("SpellCheckingInspection") import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import java.nio.file.Path -import kotlin.io.path.notExists import kotlin.io.path.readText plugins { @@ -20,9 +18,9 @@ plugins { group = "dev.nyon" val majorVersion = "2.4.0" -val mcVersion = "1.20.4" -val supportedMcVersions = listOf("1.20.3", "1.20.4") -version = "$majorVersion-1.20.4" +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" @@ -42,30 +40,33 @@ repositories { 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 } dependencies { minecraft("com.mojang:minecraft:$mcVersion") - mappings(loom.layered { - parchment("org.parchmentmc.data:parchment-1.20.3:2023.12.31@zip") - officialMojangMappings() - }) + mappings( + loom.layered { + parchment("org.parchmentmc.data:parchment-1.20.4:2024.04.14@zip") + officialMojangMappings() + } + ) implementation("org.vineflower:vineflower:1.9.3") - modImplementation("net.fabricmc:fabric-loader:0.15.6") - modImplementation("net.fabricmc:fabric-language-kotlin:1.10.17+kotlin.1.9.22") - modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.3.1+1.20.4") - modImplementation("com.terraformersmc:modmenu:9.0.0-pre.1") + 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.91.3+1.20.4") // Not necessary, just here for testing purposes + modRuntimeOnly("net.fabricmc.fabric-api:fabric-api:0.97.3+1.20.5") include(implementation(annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:0.1.1")!!)!!) include(implementation("com.akuleshov7:ktoml-core-jvm:0.5.1")!!) // Integration - modCompileOnly("maven.modrinth:abooMhox:c2klaSgQ") // tree-harvester by ricksouth - modCompileOnly("maven.modrinth:MpzVLzy5:9kJblF2V") // better nether by quickueck - modCompileOnly("maven.modrinth:EFtixeiF:Gcai736Z") // levelz by Globox1997 + // modCompileOnly("maven.modrinth:abooMhox:c2klaSgQ") // tree-harvester by ricksouth wait for 1.20.5 + // modCompileOnly("maven.modrinth:MpzVLzy5:9kJblF2V") // better nether by quickueck wait for 1.20.5 + // modCompileOnly("maven.modrinth:EFtixeiF:Gcai736Z") // levelz by Globox1997 wait for 1.20.5 } tasks { @@ -103,23 +104,29 @@ tasks { } withType { - kotlinOptions.jvmTarget = "17" + kotlinOptions.jvmTarget = "21" } withType { - options.release.set(17) + options.release.set(21) + } + + loom { + accessWidenerPath = file("src/main/resources/telekinesis.accesswidener") } } -val changelogFile: Path = rootDir.toPath().resolve("changelogs/fabric-$version.md") -val changelogText = if (changelogFile.notExists()) "" else changelogFile.readText() -val projectVersionname = "fabric-${project.version}" +val changelogText = + buildString { + append("# v${project.version}\n") + rootDir.toPath().resolve("changelog.md").readText().also { append(it) } + } modrinth { token.set(findProperty("modrinth.token")?.toString()) projectId.set("LLfA8jAD") - versionNumber.set(projectVersionname) - versionName.set(projectVersionname) + versionNumber.set("v${project.version}") + versionName.set("v${project.version}") versionType.set("release") uploadFile.set(tasks["remapJar"]) gameVersions.set(supportedMcVersions) @@ -139,8 +146,8 @@ githubRelease { val (rowner, rrepo) = githubRepo.split("/") owner = rowner repo = rrepo - releaseName = projectVersionname - tagName = projectVersionname + releaseName = "v${project.version}" + tagName = "v${project.version}" body = changelogText targetCommitish = "master" setReleaseAssets(tasks["remapJar"]) @@ -173,4 +180,4 @@ signing { java { withSourcesJar() -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java index 2a1847d..f5759ab 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractChestedHorseMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; import net.minecraft.world.level.ItemLike; import org.spongepowered.asm.mixin.Mixin; @@ -23,17 +21,6 @@ public boolean redirectEquipmentDrop( AbstractChestedHorse instance, ItemLike item ) { - final var attacker = instance.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> { - if (!player.addItem(item.asItem() - .getDefaultInstance())) instance.spawnAtLocation(item); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, item); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java index 832fb71..2c98427 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AbstractHorseMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; @@ -23,16 +21,6 @@ public boolean redirectEquipmentDrop( AbstractHorse instance, ItemStack stack ) { - final var attacker = instance.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> { - if (!player.addItem(stack)) instance.spawnAtLocation(stack); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, stack); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java index 10d8ae8..05abdff 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java @@ -1,7 +1,8 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.TelekinesisPolicy; +import dev.nyon.telekinesis.utils.EntityUtils; import dev.nyon.telekinesis.utils.TelekinesisUtils; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.animal.allay.Allay; @@ -31,17 +32,7 @@ public boolean redirectEquipmentDrop( Allay instance, ItemStack stack ) { - final var attacker = instance.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> { - if (!player.addItem(stack)) instance.spawnAtLocation(stack); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, stack); } @Redirect( @@ -66,7 +57,8 @@ public void redirectInventoryDrops( serverPlayer.getMainHandItem(), player -> instance.forEach(item -> { if (!player.addItem(item)) consumer.accept(item); - })); + }) + ); if (!hasTelekinesis) instance.forEach(consumer); } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java index c1916fa..37695ad 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java @@ -69,27 +69,21 @@ private static void manipulateDrops( if (!(level instanceof ServerLevel serverLevel)) return; Block block = blockState.getBlock(); if (EnchantmentHelper.hasSilkTouch(itemStack)) return; - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.ExpDrops, - entity, - itemStack, - player -> { - int expToAdd = 0; - if (block instanceof DropExperienceBlock expBlock) - expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange() - .sample(level.random); - if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5); - if (block instanceof SculkCatalystBlock catalystBlock) - expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange() - .sample(level.random); - if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock) - expToAdd = ConstantInt.of(5) - .sample(level.random); - if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15); - if (block instanceof InfestedBlock infestedBlock) - infestedBlock.spawnAfterBreak(blockState, serverLevel, blockPos, itemStack, true); - PlayerUtils.addExpToPlayer(player, expToAdd); - }); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.ExpDrops, entity, itemStack, player -> { + int expToAdd = 0; + if (block instanceof DropExperienceBlock expBlock) expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange() + .sample(level.random); + if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5); + if (block instanceof SculkCatalystBlock catalystBlock) expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange() + .sample(level.random); + if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock) expToAdd = ConstantInt.of(5) + .sample(level.random); + if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15); + if (block instanceof InfestedBlock infestedBlock) + infestedBlock.spawnAfterBreak(blockState, serverLevel, blockPos, itemStack, true); + PlayerUtils.addExpToPlayer(player, expToAdd); + }); if (hasTelekinesis) ci.cancel(); } -} \ No newline at end of file +} 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 a44ed4d..abc6fdd 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,18 +1,13 @@ package dev.nyon.telekinesis.mixins; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +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 net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import java.util.concurrent.atomic.AtomicReference; - @Mixin(ChestBoat.class) public class ChestBoatMixin { @@ -27,16 +22,6 @@ private Item changeDroppedItem( Item original, DamageSource damageSource ) { - final var attacker = damageSource.getEntity(); - if (!(attacker instanceof ServerPlayer)) return original; - - AtomicReference toReturn = new AtomicReference<>(original); - - TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.VehicleDrops, damageSource, player -> { - if (player.addItem(original.asItem() - .getDefaultInstance())) toReturn.set(ItemStack.EMPTY.getItem()); - }); - - return toReturn.get(); + return EntityUtils.getDropItemInject(original, damageSource); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java index d049caf..7eb9455 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java @@ -31,9 +31,7 @@ private static void registerTelekinesis( if (!isTelekinesisRegistered) { MainKt.setTelekinesis(new TelekinesisEnchantment()); isTelekinesisRegistered = true; - Registry.register(BuiltInRegistries.ENCHANTMENT, - new ResourceLocation("telekinesis", "telekinesis"), - MainKt.getTelekinesis()); + Registry.register(BuiltInRegistries.ENCHANTMENT, new ResourceLocation("telekinesis", "telekinesis"), MainKt.getTelekinesis()); } } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java index f8c0d65..8b91cfa 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnderManMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.monster.EnderMan; import net.minecraft.world.item.ItemStack; @@ -27,15 +25,6 @@ public boolean redirectEquipmentDrop( int lootingMultiplier, boolean allowDrops ) { - final var attacker = damageSource.getEntity(); - if (!(attacker instanceof ServerPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - damageSource, - player -> { - if (!player.addItem(stack)) instance.spawnAtLocation(stack); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, stack); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/FishingHookMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/FishingHookMixin.java index b4503a3..1a0fca9 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/FishingHookMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/FishingHookMixin.java @@ -1,6 +1,6 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.TelekinesisPolicy; import dev.nyon.telekinesis.utils.PlayerUtils; import dev.nyon.telekinesis.utils.TelekinesisUtils; @@ -42,7 +42,8 @@ private boolean redirectFishingHookDrops( final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, _serverPlayer, stack, - serverPlayer -> PlayerUtils.addExpToPlayer(serverPlayer, expOrb.getValue())); + serverPlayer -> PlayerUtils.addExpToPlayer(serverPlayer, expOrb.getValue()) + ); return !hasTelekinesis; } @@ -53,7 +54,8 @@ private boolean redirectFishingHookDrops( stack, serverPlayer -> { if (!serverPlayer.addItem(itemEntity.getItem())) instance.addFreshEntity(itemEntity); - }); + } + ); return !hasTelekinesis; } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java index 2e391ef..d2b7c47 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -26,16 +24,6 @@ public boolean redirectEquipmentDrop( boolean throwRandomly, boolean retainOwnership ) { - final var attacker = instance.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> { - if (!player.addItem(stack)) instance.spawnAtLocation(stack); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, stack); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java index c189f9a..03b1f98 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java @@ -1,6 +1,6 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.TelekinesisPolicy; import dev.nyon.telekinesis.utils.PlayerUtils; import dev.nyon.telekinesis.utils.TelekinesisUtils; @@ -42,7 +42,8 @@ public boolean redirectExp( boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, serverPlayer, serverPlayer.getMainHandItem(), - player -> PlayerUtils.addExpToPlayer(player, amount)); + player -> PlayerUtils.addExpToPlayer(player, amount) + ); return !hasTelekinesis; } @@ -60,11 +61,9 @@ public void redirectCommonDrops( boolean bl ) { args.>set(2, item -> { - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - damageSource, - player -> { - if (!player.addItem(item)) livingEntity.spawnAtLocation(item); - }); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, damageSource, player -> { + if (!player.addItem(item)) livingEntity.spawnAtLocation(item); + }); if (!hasTelekinesis) livingEntity.spawnAtLocation(item); }); diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java index fa6de6b..a224ec3 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MobMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Mob; import net.minecraft.world.item.ItemStack; @@ -27,15 +25,6 @@ public boolean redirectEquipmentDrop( int lootingMultiplier, boolean allowDrops ) { - final var attacker = damageSource.getEntity(); - if (!(attacker instanceof ServerPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - damageSource, - player -> { - if (!player.addItem(stack)) instance.spawnAtLocation(stack); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, stack); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java index b7770b2..c7bf7b9 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PigMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.entity.animal.Pig; import net.minecraft.world.level.ItemLike; import org.spongepowered.asm.mixin.Mixin; @@ -23,17 +21,6 @@ public boolean redirectEquipmentDrop( Pig instance, ItemLike item ) { - final var attacker = instance.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> { - if (!player.addItem(item.asItem() - .getDefaultInstance())) instance.spawnAtLocation(item); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, item); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PiglinMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PiglinMixin.java index 323efe2..a57939f 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PiglinMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/PiglinMixin.java @@ -35,7 +35,8 @@ public void redirectDrops( damageSource, player -> instance.forEach(item -> { if (!player.addItem(item)) piglin.spawnAtLocation(item); - })); + }) + ); if (!hasTelekinesis) instance.forEach(piglin::spawnAtLocation); } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java index 56bf062..304a1c5 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java @@ -65,10 +65,12 @@ public void manipulateWoolDrops( entity.setDeltaMovement(entity.getDeltaMovement() .add((random.nextFloat() - random.nextFloat()) * 0.1F, random.nextFloat() * 0.05F, - (random.nextFloat() - random.nextFloat()) * 0.1F)); + (random.nextFloat() - random.nextFloat()) * 0.1F + )); } } - }); + } + ); if (!hasTelekinesis) dropAllNormally(i, instance); } @@ -83,7 +85,8 @@ void dropAllNormally( entity.setDeltaMovement(entity.getDeltaMovement() .add((random.nextFloat() - random.nextFloat()) * 0.1F, random.nextFloat() * 0.05F, - (random.nextFloat() - random.nextFloat()) * 0.1F)); + (random.nextFloat() - random.nextFloat()) * 0.1F + )); } } } \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java index 2fa9bed..574a010 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java @@ -37,11 +37,9 @@ public void manipulateWoolDrops( ItemStack item = new ItemStack(Items.CARVED_PUMPKIN); - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ShearingDrops, - player, - serverPlayer -> { - if (!serverPlayer.addItem(item)) instance.spawnAtLocation(item, 1.7F); - }); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ShearingDrops, player, serverPlayer -> { + if (!serverPlayer.addItem(item)) instance.spawnAtLocation(item, 1.7F); + }); if (!hasTelekinesis) instance.spawnAtLocation(item, 1.7F); } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java index 28e6035..0599c7f 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/StriderMixin.java @@ -1,9 +1,7 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import dev.nyon.telekinesis.utils.EntityUtils; import net.minecraft.world.entity.monster.Strider; import net.minecraft.world.level.ItemLike; import org.spongepowered.asm.mixin.Mixin; @@ -23,17 +21,6 @@ public boolean redirectEquipmentDrop( Strider instance, ItemLike item ) { - final var attacker = instance.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> { - if (!player.addItem(item.asItem() - .getDefaultInstance())) instance.spawnAtLocation(item); - }); - - return !hasTelekinesis; + return EntityUtils.spawnAtLocationInject(instance, item); } } 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 b09c519..459485b 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 @@ -1,11 +1,10 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.WrapWithCondition; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.TelekinesisPolicy; 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; @@ -19,7 +18,7 @@ @Mixin(SweetBerryBushBlock.class) public class SweetBerryBushBlockMixin { @WrapWithCondition( - method = "use", + method = "useWithoutItem", 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" @@ -29,21 +28,21 @@ private boolean manipulateBerryDrops( Level level, BlockPos blockPos, ItemStack itemStack, - BlockState state, + BlockState blockState, Level _level, - BlockPos pos, + BlockPos _blockPos, Player player, - InteractionHand hand, - BlockHitResult hit + BlockHitResult blockHitResult ) { if (!(player instanceof ServerPlayer serverPlayer)) return true; boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.BlockDrops, serverPlayer, - serverPlayer.getItemInHand(hand), + serverPlayer.getMainHandItem(), cPlayer -> { - if (!player.addItem(itemStack)) Block.popResource(level, pos, itemStack); - }); + 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 56bacf1..07718b2 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 @@ -1,18 +1,13 @@ package dev.nyon.telekinesis.mixins; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.server.level.ServerPlayer; +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 net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import java.util.concurrent.atomic.AtomicReference; - @Mixin(VehicleEntity.class) public class VehicleEntityMixin { @@ -27,16 +22,6 @@ private Item changeDroppedItem( Item original, DamageSource damageSource ) { - final var attacker = damageSource.getEntity(); - if (!(attacker instanceof ServerPlayer)) return original; - - AtomicReference toReturn = new AtomicReference<>(original); - - TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.VehicleDrops, damageSource, player -> { - if (player.addItem(original.asItem() - .getDefaultInstance())) toReturn.set(ItemStack.EMPTY.getItem()); - }); - - return toReturn.get(); + return EntityUtils.getDropItemInject(original, damageSource); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java index a659502..996ef00 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java @@ -28,15 +28,12 @@ protected ItemEntity redirectEquipmentDrop( final var attacker = instance.getLastAttacker(); if (!(attacker instanceof ServerPlayer serverPlayer)) return original.call(instance, stack); - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - null, - player -> { - if (!player.addItem(stack.asItem() - .getDefaultInstance())) instance.spawnAtLocation(stack); - }); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, serverPlayer, null, player -> { + if (!player.addItem(stack.asItem() + .getDefaultInstance())) instance.spawnAtLocation(stack); + }); if (!hasTelekinesis) return original.call(instance, stack); else return null; } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/BetterNetherMixinPlugin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/BetterNetherMixinPlugin.java index 03aec08..c72730d 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/BetterNetherMixinPlugin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/BetterNetherMixinPlugin.java @@ -20,12 +20,19 @@ public String getRefMapperConfig() { } @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return FabricLoader.getInstance().isModLoaded("betternether"); + public boolean shouldApplyMixin( + String targetClassName, + String mixinClassName + ) { + return FabricLoader.getInstance() + .isModLoaded("betternether"); } @Override - public void acceptTargets(Set myTargets, Set otherTargets) { + public void acceptTargets( + Set myTargets, + Set otherTargets + ) { } @Override @@ -34,10 +41,20 @@ public List getMixins() { } @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + public void preApply( + String targetClassName, + ClassNode targetClass, + String mixinClassName, + IMixinInfo mixinInfo + ) { } @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + public void postApply( + String targetClassName, + ClassNode targetClass, + String mixinClassName, + IMixinInfo mixinInfo + ) { } } \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/RubyFireMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/RubyFireMixin.java index 6a530b2..9322d91 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/RubyFireMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/betternether/RubyFireMixin.java @@ -1,126 +1,99 @@ package dev.nyon.telekinesis.mixins.compat.betternether; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.mixins.CatalystBlockAccessor; -import dev.nyon.telekinesis.mixins.DropExperienceBlockAccessor; -import dev.nyon.telekinesis.utils.PlayerUtils; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.valueproviders.ConstantInt; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.level.block.*; -import net.minecraft.world.level.block.state.BlockState; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.List; -import java.util.function.Consumer; - -@Pseudo -@Mixin(targets = "org.betterx.betternether.enchantments.RubyFire") -public class RubyFireMixin { - - @WrapWithCondition( - method = "getDrops", - at = @At( - value = "INVOKE", - target = "Lorg/betterx/betternether/enchantments/RubyFire;popExperience(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;I)V" - ) - ) - private static boolean redirectExp( - ServerLevel level, - BlockPos blockPos, - int amount, - BlockState brokenBlock, - ServerLevel level1, - BlockPos blockPos1, - Player player, - ItemStack breakingItem - ) { - if (!(player instanceof ServerPlayer _serverPlayer)) return true; - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - breakingItem, - serverPlayer -> PlayerUtils.addExpToPlayer(serverPlayer, amount)); - return !hasTelekinesis; - } - - @Redirect( - method = "getDrops", - at = @At( - value = "INVOKE", - target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V" - ) - ) - private static void redirectCommonDrops( - List instance, Consumer consumer, BlockState brokenBlock, ServerLevel level, BlockPos blockPos, Player player, ItemStack breakingItem - ) { - if (!(player instanceof ServerPlayer _serverPlayer)) { - instance.forEach(consumer); - return; - } - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.MobDrops, - _serverPlayer, - breakingItem, - serverPlayer -> instance.forEach(item -> { - if (!serverPlayer.addItem(item)) consumer.accept(item); - }) - ); - - if (!hasTelekinesis) instance.forEach(consumer); - } - - @WrapWithCondition( - method = "getDrops", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/block/state/BlockState;spawnAfterBreak(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;Z)V" - ) - ) - private static boolean redirectAfterDrops( - BlockState instance, - ServerLevel world, - BlockPos pos, - ItemStack tool, - boolean dropExperience, - BlockState brokenBlock, - ServerLevel level, - BlockPos blockPos, - Player _player, - ItemStack breakingItem - ) { - if (!(_player instanceof ServerPlayer _serverPlayer)) return true; - - Block block = brokenBlock.getBlock(); - if (EnchantmentHelper.hasSilkTouch(breakingItem)) return true; - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - breakingItem, - player -> { - int expToAdd = 0; - if (block instanceof DropExperienceBlock expBlock) - expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange().sample(level.random); - if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5); - if (block instanceof SculkCatalystBlock catalystBlock) - expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange().sample(level.random); - if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock) - expToAdd = ConstantInt.of(5).sample(level.random); - if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15); - if (block instanceof InfestedBlock infestedBlock) - infestedBlock.spawnAfterBreak(brokenBlock, level, blockPos, breakingItem, true); - PlayerUtils.addExpToPlayer(player, expToAdd); - }); - - return !hasTelekinesis; - } -} +/* + * @Pseudo + * @Mixin(targets = "org.betterx.betternether.enchantments.RubyFire") + * public class RubyFireMixin { + * @WrapWithCondition( method = "getDrops", + * at = @At( + * value = "INVOKE", + * target = "Lorg/betterx/betternether/enchantments/RubyFire;popExperience(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;I)V" + * ) + * ) + * private static boolean redirectExp( + * ServerLevel level, + * BlockPos blockPos, + * int amount, + * BlockState brokenBlock, + * ServerLevel level1, + * BlockPos blockPos1, + * Player player, + * ItemStack breakingItem + * ) { + * if (!(player instanceof ServerPlayer _serverPlayer)) return true; + * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( + * TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * breakingItem, + * serverPlayer -> PlayerUtils.addExpToPlayer(serverPlayer, amount)); + * return !hasTelekinesis; + * } + * @Redirect( method = "getDrops", + * at = @At( + * value = "INVOKE", + * target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V" + * ) + * ) + * private static void redirectCommonDrops( + * List instance, Consumer consumer, BlockState brokenBlock, ServerLevel level, BlockPos blockPos, Player player, ItemStack breakingItem + * ) { + * if (!(player instanceof ServerPlayer _serverPlayer)) { + * instance.forEach(consumer); + * return; + * } + * boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis( + * TelekinesisPolicy.MobDrops, + * _serverPlayer, + * breakingItem, + * serverPlayer -> instance.forEach(item -> { + * if (!serverPlayer.addItem(item)) consumer.accept(item); + * }) + * ); + *

+ * if (!hasTelekinesis) instance.forEach(consumer); + * } + * @WrapWithCondition( method = "getDrops", + * at = @At( + * value = "INVOKE", + * target = "Lnet/minecraft/world/level/block/state/BlockState;spawnAfterBreak(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;Z)V" + * ) + * ) + * private static boolean redirectAfterDrops( + * BlockState instance, + * ServerLevel world, + * BlockPos pos, + * ItemStack tool, + * boolean dropExperience, + * BlockState brokenBlock, + * ServerLevel level, + * BlockPos blockPos, + * Player _player, + * ItemStack breakingItem + * ) { + * if (!(_player instanceof ServerPlayer _serverPlayer)) return true; + *

+ * Block block = brokenBlock.getBlock(); + * if (EnchantmentHelper.hasSilkTouch(breakingItem)) return true; + * boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock( + * TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * breakingItem, + * player -> { + * int expToAdd = 0; + * if (block instanceof DropExperienceBlock expBlock) + * expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange().sample(level.random); + * if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5); + * if (block instanceof SculkCatalystBlock catalystBlock) + * expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange().sample(level.random); + * if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock) + * expToAdd = ConstantInt.of(5).sample(level.random); + * if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15); + * if (block instanceof InfestedBlock infestedBlock) + * infestedBlock.spawnAfterBreak(brokenBlock, level, blockPos, breakingItem, true); + * PlayerUtils.addExpToPlayer(player, expToAdd); + * }); + *

+ * return !hasTelekinesis; + * } + * } + */ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/BlockMixinMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/BlockMixinMixin.java index 922399d..70f155f 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/BlockMixinMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/BlockMixinMixin.java @@ -1,36 +1,11 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import com.bawnorton.mixinsquared.TargetHandler; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.PlayerUtils; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.levelz.access.PlayerSyncAccess; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.storage.loot.LootParams; -import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; - +/* @Pseudo -@Mixin(value = Block.class, priority = 1500) +@Mixin( + value = Block.class, + priority = 1500 +) public abstract class BlockMixinMixin { @Unique private static @Nullable ServerPlayer serverPlayer; @@ -60,13 +35,13 @@ private static boolean redirectDroppedStacks( LootParams.Builder builder ) { if (!(entity instanceof ServerPlayer _serverPlayer)) return true; - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.BlockDrops, + final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.BlockDrops, _serverPlayer, tool, serverPlayer -> { if (!_serverPlayer.addItem(stack)) Block.popResource(world, pos, stack); - }); + } + ); return !hasTelekinesis; } @@ -86,21 +61,28 @@ private static boolean redirectExp( Vec3 pos, int amount ) { - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, + final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, serverPlayer, null, - serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount)); + serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount) + ); return !hasTelekinesis; } @Inject( method = "playerWillDestroy", - at = {@At("HEAD")} + at = { @At("HEAD") } ) - private void onDestroy(Level world, BlockPos pos, BlockState state, Player player, CallbackInfo info) { + private void onDestroy( + Level world, + BlockPos pos, + BlockState state, + Player player, + CallbackInfo info + ) { if (!world.isClientSide) { serverPlayer = (ServerPlayer) player; } } } +*/ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/EnderDragonEntityMixinMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/EnderDragonEntityMixinMixin.java index bb89644..4d19f98 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/EnderDragonEntityMixinMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/EnderDragonEntityMixinMixin.java @@ -1,74 +1,55 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import com.bawnorton.mixinsquared.TargetHandler; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.PlayerUtils; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.levelz.access.PlayerSyncAccess; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.boss.enderdragon.EnderDragon; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; - -@Pseudo -@Mixin(value = EnderDragon.class, priority = 1500) -public class EnderDragonEntityMixinMixin { - - @Unique - final EnderDragon instance = (EnderDragon) (Object) this; - - @TargetHandler( - mixin = "net.levelz.mixin.entity.EnderDragonEntityMixin", - name = "updatePostDeathMixin" - ) - @WrapWithCondition( - method = "@MixinSquared:Handler", - at = @At( - value = "INVOKE", - target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" - ) - ) - private boolean redirectExp( - ServerLevel world, - Vec3 pos, - int amount - ) { - if (!(instance.getLastAttacker() instanceof ServerPlayer _serverPlayer)) return true; - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - null, - serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount)); - return !hasTelekinesis; - } - - @TargetHandler( - mixin = "net.levelz.mixin.entity.EnderDragonEntityMixin", - name = "updatePostDeathXPMixin" - ) - @WrapWithCondition( - method = "@MixinSquared:Handler", - at = @At( - value = "INVOKE", - target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" - ) - ) - private boolean redirectExp1( - ServerLevel world, - Vec3 pos, - int amount - ) { - if (!(instance.getLastAttacker() instanceof ServerPlayer _serverPlayer)) return true; - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - null, - serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount)); - return !hasTelekinesis; - } -} +/* + * @Pseudo + * @Mixin( value = EnderDragon.class, + * priority = 1500 + * ) + * public class EnderDragonEntityMixinMixin { + * @Unique final EnderDragon instance = (EnderDragon) (Object) this; + * @TargetHandler( mixin = "net.levelz.mixin.entity.EnderDragonEntityMixin", + * name = "updatePostDeathMixin" + * ) + * @WrapWithCondition( method = "@MixinSquared:Handler", + * at = @At( + * value = "INVOKE", + * target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" + * ) + * ) + * private boolean redirectExp( + * ServerLevel world, + * Vec3 pos, + * int amount + * ) { + * if (!(instance.getLastAttacker() instanceof ServerPlayer _serverPlayer)) return true; + * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * null, + * serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount) + * ); + * return !hasTelekinesis; + * } + * @TargetHandler( mixin = "net.levelz.mixin.entity.EnderDragonEntityMixin", + * name = "updatePostDeathXPMixin" + * ) + * @WrapWithCondition( method = "@MixinSquared:Handler", + * at = @At( + * value = "INVOKE", + * target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" + * ) + * ) + * private boolean redirectExp1( + * ServerLevel world, + * Vec3 pos, + * int amount + * ) { + * if (!(instance.getLastAttacker() instanceof ServerPlayer _serverPlayer)) return true; + * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * null, + * serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount) + * ); + * return !hasTelekinesis; + * } + * } + */ diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/FishingBobberEntityMixinMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/FishingBobberEntityMixinMixin.java index 1efd290..39235fd 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/FishingBobberEntityMixinMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/FishingBobberEntityMixinMixin.java @@ -1,55 +1,36 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import com.bawnorton.mixinsquared.TargetHandler; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.PlayerUtils; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.levelz.access.PlayerSyncAccess; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.phys.Vec3; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Pseudo -@Mixin(value = FishingHook.class, priority = 1500) -public abstract class FishingBobberEntityMixinMixin { - - @Shadow @Nullable - public abstract Player getPlayerOwner(); - - @TargetHandler( - mixin = "net.levelz.mixin.entity.FishingBobberEntityMixin", - name = "useMixin" - ) - @WrapWithCondition( - method = "@MixinSquared:Handler", - at = @At( - value = "INVOKE", - target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" - ) - ) - private boolean redirectExp( - ServerLevel world, - Vec3 pos, - int amount, - ItemStack usedItem, - CallbackInfoReturnable info - ) { - if (!(getPlayerOwner() instanceof ServerPlayer _serverPlayer)) return true; - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - usedItem, - serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount)); - return !hasTelekinesis; - } -} +/* + * @Pseudo + * @Mixin( value = FishingHook.class, + * priority = 1500 + * ) + * public abstract class FishingBobberEntityMixinMixin { + * @Shadow + * @Nullable public abstract Player getPlayerOwner(); + * @TargetHandler( mixin = "net.levelz.mixin.entity.FishingBobberEntityMixin", + * name = "useMixin" + * ) + * @WrapWithCondition( method = "@MixinSquared:Handler", + * at = @At( + * value = "INVOKE", + * target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" + * ) + * ) + * private boolean redirectExp( + * ServerLevel world, + * Vec3 pos, + * int amount, + * ItemStack usedItem, + * CallbackInfoReturnable info + * ) { + * if (!(getPlayerOwner() instanceof ServerPlayer _serverPlayer)) return true; + * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * usedItem, + * serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount) + * ); + * return !hasTelekinesis; + * } + * } + */ diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbAccessor.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbAccessor.java index 93b870e..b070c36 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbAccessor.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbAccessor.java @@ -1,21 +1,9 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import net.levelz.entity.LevelExperienceOrbEntity; -import net.minecraft.world.entity.player.Player; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.gen.Invoker; - -import java.util.Map; - -@Pseudo -@Mixin(LevelExperienceOrbEntity.class) -public interface LevelExperienceOrbAccessor { - - @Accessor - Player getTarget(); - - @Invoker("getClumpedMap") - Map invokeGetClumpedMap(); -} +/* + * @Pseudo + * @Mixin(LevelExperienceOrbEntity.class) public interface LevelExperienceOrbAccessor { + * @Accessor Player getTarget(); + * @Invoker("getClumpedMap") Map invokeGetClumpedMap(); + * } + */ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbEntityMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbEntityMixin.java index 23a7646..2e62593 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbEntityMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelExperienceOrbEntityMixin.java @@ -1,48 +1,34 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.levelz.access.PlayerSyncAccess; -import net.levelz.entity.LevelExperienceOrbEntity; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; - -@Pseudo -@Mixin(net.levelz.entity.LevelExperienceOrbEntity.class) -public class LevelExperienceOrbEntityMixin { - - @WrapWithCondition( - method = "spawn", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z" - ) - ) - private static boolean redirectSpawnOnTelekinesis( - ServerLevel level, - Entity entity - ) { - if (!(entity instanceof LevelExperienceOrbEntity expOrb)) return true; - - Player target = ((LevelExperienceOrbAccessor) expOrb).getTarget(); - if (target == null || target.distanceToSqr(expOrb) > 64.0) { - target = level.getNearestPlayer(expOrb, 8.0); - } - if (!(target instanceof ServerPlayer _serverPlayer)) return true; - - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - null, - serverPlayer -> ((LevelExperienceOrbAccessor) expOrb).invokeGetClumpedMap() - .forEach((value, amount) -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(value * amount)) - ); - return !hasTelekinesis; - } -} +/* + * @Pseudo + * @Mixin(net.levelz.entity.LevelExperienceOrbEntity.class) public class LevelExperienceOrbEntityMixin { + * @WrapWithCondition( method = "spawn", + * at = @At( + * value = "INVOKE", + * target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z" + * ) + * ) + * private static boolean redirectSpawnOnTelekinesis( + * ServerLevel level, + * Entity entity + * ) { + * if (!(entity instanceof LevelExperienceOrbEntity expOrb)) return true; + *

+ * Player target = ((LevelExperienceOrbAccessor) expOrb).getTarget(); + * if (target == null || target.distanceToSqr(expOrb) > 64.0) { + * target = level.getNearestPlayer(expOrb, 8.0); + * } + * if (!(target instanceof ServerPlayer _serverPlayer)) return true; + *

+ * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( + * TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * null, + * serverPlayer -> ((LevelExperienceOrbAccessor) expOrb).invokeGetClumpedMap() + * .forEach((value, amount) -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(value * amount)) + * ); + * return !hasTelekinesis; + * } + * } + */ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelZMixinPlugin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelZMixinPlugin.java index 2251601..680ca49 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelZMixinPlugin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LevelZMixinPlugin.java @@ -21,12 +21,19 @@ public String getRefMapperConfig() { } @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return FabricLoader.getInstance().isModLoaded("levelz"); + public boolean shouldApplyMixin( + String targetClassName, + String mixinClassName + ) { + return FabricLoader.getInstance() + .isModLoaded("levelz"); } @Override - public void acceptTargets(Set myTargets, Set otherTargets) { + public void acceptTargets( + Set myTargets, + Set otherTargets + ) { } @Override @@ -35,10 +42,20 @@ public List getMixins() { } @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + public void preApply( + String targetClassName, + ClassNode targetClass, + String mixinClassName, + IMixinInfo mixinInfo + ) { } @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + public void postApply( + String targetClassName, + ClassNode targetClass, + String mixinClassName, + IMixinInfo mixinInfo + ) { } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LivingEntityMixinMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LivingEntityMixinMixin.java index 5010d5d..e40ac1d 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LivingEntityMixinMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/LivingEntityMixinMixin.java @@ -1,49 +1,35 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import com.bawnorton.mixinsquared.TargetHandler; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.levelz.access.PlayerSyncAccess; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; - -@Pseudo -@Mixin(value = LivingEntity.class, priority = 1500) -public class LivingEntityMixinMixin { - @Unique - final LivingEntity instance = (LivingEntity) (Object) this; - - @TargetHandler( - mixin = "net.levelz.mixin.entity.LivingEntityMixin", - name = "dropXpMixin" - ) - @WrapWithCondition( - method = "@MixinSquared:Handler", - at = @At( - value = "INVOKE", - target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" - ) - ) - protected boolean redirectLevelZExpDrop( - ServerLevel world, - Vec3 pos, - int amount - ) { - if (!(instance.getLastAttacker() instanceof ServerPlayer _serverPlayer)) return true; - System.out.println("wtf" + amount); - System.out.println(amount); - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.ExpDrops, - _serverPlayer, - null, - serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount)); - return !hasTelekinesis; - } -} +/* + * @Pseudo + * @Mixin( value = LivingEntity.class, + * priority = 1500 + * ) + * public class LivingEntityMixinMixin { + * @Unique final LivingEntity instance = (LivingEntity) (Object) this; + * @TargetHandler( mixin = "net.levelz.mixin.entity.LivingEntityMixin", + * name = "dropXpMixin" + * ) + * @WrapWithCondition( method = "@MixinSquared:Handler", + * at = @At( + * value = "INVOKE", + * target = "net/levelz/entity/LevelExperienceOrbEntity.spawn (Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" + * ) + * ) + * protected boolean redirectLevelZExpDrop( + * ServerLevel world, + * Vec3 pos, + * int amount + * ) { + * if (!(instance.getLastAttacker() instanceof ServerPlayer _serverPlayer)) return true; + * System.out.println("wtf" + amount); + * System.out.println(amount); + * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, + * _serverPlayer, + * null, + * serverPlayer -> ((PlayerSyncAccess) serverPlayer).addLevelExperience(amount) + * ); + * return !hasTelekinesis; + * } + * } + */ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/PlantBlockMixinMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/PlantBlockMixinMixin.java index 4046f66..4b5704e 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/PlantBlockMixinMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/levelz/PlantBlockMixinMixin.java @@ -1,52 +1,39 @@ package dev.nyon.telekinesis.mixins.compat.levelz; -import com.llamalad7.mixinextras.injector.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import dev.nyon.telekinesis.utils.TelekinesisUtils; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BushBlock; -import net.minecraft.world.level.block.state.BlockState; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; - -@Pseudo -@Mixin(value = BushBlock.class, priority = 1500) -public class PlantBlockMixinMixin extends Block { - - public PlantBlockMixinMixin(Properties properties) { - super(properties); - } - - @WrapWithCondition( - method = "playerWillDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/player/Player;)V", - at = @At( - value = "INVOKE", - target = "net/minecraft/world/level/block/Block.popResource (Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V" - ) - ) - private boolean checkTelekinesisAndRedirect( - Level world, - BlockPos pos, - ItemStack stack, - Level world1, - BlockPos pos1, - BlockState state, - Player player - ) { - if (!(player instanceof ServerPlayer _serverPlayer)) return true; - final var hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.BlockDrops, - _serverPlayer, - null, - serverPlayer -> { - if (!serverPlayer.addItem(stack)) Block.popResource(world, pos, stack); - }); - return !hasTelekinesis; - } -} \ No newline at end of file +/* + * @Pseudo + * @Mixin( value = BushBlock.class, + * priority = 1500 + * ) + * public class PlantBlockMixinMixin extends Block { + *

+ * public PlantBlockMixinMixin(Properties properties) { + * super(properties); + * } + * @WrapWithCondition( method = "playerWillDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/player/Player;)V", + * at = @At( + * value = "INVOKE", + * target = "net/minecraft/world/level/block/Block.popResource (Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V" + * ) + * ) + * private boolean checkTelekinesisAndRedirect( + * Level world, + * BlockPos pos, + * ItemStack stack, + * Level world1, + * BlockPos pos1, + * BlockState state, + * Player player + * ) { + * if (!(player instanceof ServerPlayer _serverPlayer)) return true; + * final var hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.BlockDrops, + * _serverPlayer, + * null, + * serverPlayer -> { + * if (!serverPlayer.addItem(stack)) Block.popResource(world, pos, stack); + * } + * ); + * return !hasTelekinesis; + * } + * } + */ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeCutEventsMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeCutEventsMixin.java index c8e22cc..2da886a 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeCutEventsMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeCutEventsMixin.java @@ -1,25 +1,6 @@ package dev.nyon.telekinesis.mixins.compat.treeharvester; -import dev.nyon.telekinesis.MainKt; -import dev.nyon.telekinesis.TelekinesisConfigKt; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.List; - +/* @Pseudo @Mixin(targets = "com.natamus.treeharvester_common_fabric.events.TreeCutEvents") public class TreeCutEventsMixin { @@ -31,15 +12,21 @@ public class TreeCutEventsMixin { target = "Lcom/natamus/collective_common_fabric/functions/BlockFunctions;dropBlock(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V" ) ) - private static void redirectDrop(Level level, BlockPos blockPos, Level _level, Player player, BlockPos bpos, BlockState state, BlockEntity blockEntity) { - if ( - ( - EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), player.getItemInHand(InteractionHand.MAIN_HAND)) == 0 - && !TelekinesisConfigKt.getConfig().getOnByDefault() - ) - || !TelekinesisConfigKt.getConfig().getBlockDrops() - || !(level instanceof ServerLevel serverLevel) - ) return; + private static void redirectDrop( + Level level, + BlockPos blockPos, + Level _level, + Player player, + BlockPos bpos, + BlockState state, + BlockEntity blockEntity + ) { + if ((EnchantmentHelper.getItemEnchantmentLevel( + MainKt.getTelekinesis(), + player.getItemInHand(InteractionHand.MAIN_HAND) + ) == 0 && !TelekinesisConfigKt.getConfig() + .getOnByDefault()) || !TelekinesisConfigKt.getConfig() + .getBlockDrops() || !(level instanceof ServerLevel serverLevel)) return; BlockState blockState = level.getBlockState(blockPos); BlockEntity tileEntity = level.getBlockEntity(blockPos); @@ -52,4 +39,6 @@ private static void redirectDrop(Level level, BlockPos blockPos, Level _level, P serverLevel.setBlock(blockPos, Blocks.AIR.defaultBlockState(), 3); } -} \ No newline at end of file +} + + */ \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeHarvesterMixinPlugin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeHarvesterMixinPlugin.java index 489d047..e1d653f 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeHarvesterMixinPlugin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/compat/treeharvester/TreeHarvesterMixinPlugin.java @@ -20,12 +20,19 @@ public String getRefMapperConfig() { } @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return FabricLoader.getInstance().isModLoaded("treeharvester"); + public boolean shouldApplyMixin( + String targetClassName, + String mixinClassName + ) { + return FabricLoader.getInstance() + .isModLoaded("treeharvester"); } @Override - public void acceptTargets(Set myTargets, Set otherTargets) { + public void acceptTargets( + Set myTargets, + Set otherTargets + ) { } @Override @@ -34,10 +41,20 @@ public List getMixins() { } @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + public void preApply( + String targetClassName, + ClassNode targetClass, + String mixinClassName, + IMixinInfo mixinInfo + ) { } @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + public void postApply( + String targetClassName, + ClassNode targetClass, + String mixinClassName, + IMixinInfo mixinInfo + ) { } } 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 new file mode 100644 index 0000000..fd3548e --- /dev/null +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java @@ -0,0 +1,60 @@ +package dev.nyon.telekinesis.utils; + +import dev.nyon.telekinesis.TelekinesisPolicy; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; + +import java.util.concurrent.atomic.AtomicReference; + +public class EntityUtils { + + public static boolean spawnAtLocationInject( + LivingEntity entity, + ItemLike item + ) { + return spawnAtLocationInject( + entity, + item.asItem() + .getDefaultInstance() + ); + } + + public static boolean spawnAtLocationInject( + LivingEntity entity, + ItemStack item + ) { + final var attacker = entity.getLastAttacker(); + if (!(attacker instanceof ServerPlayer serverPlayer)) return true; + + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, + serverPlayer, + serverPlayer.getMainHandItem(), + player -> { + if (!player.addItem(item)) entity.spawnAtLocation(item); + } + ); + + return !hasTelekinesis; + } + + public static Item getDropItemInject( + Item original, + DamageSource source + ) { + final var attacker = source.getEntity(); + if (!(attacker instanceof ServerPlayer)) return original; + + AtomicReference toReturn = new AtomicReference<>(original); + + TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.VehicleDrops, source, player -> { + if (player.addItem(original.asItem() + .getDefaultInstance())) toReturn.set(ItemStack.EMPTY.getItem()); + }); + + return toReturn.get(); + } +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java index 238b014..e6ad9ba 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java @@ -21,9 +21,7 @@ private static int repairPlayerItems( Player player, Integer exp ) { - Map.Entry entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, - player, - ItemStack::isDamaged); + Map.Entry entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, player, ItemStack::isDamaged); if (entry != null) { ItemStack itemStack = entry.getValue(); int j = Math.min(exp * 2, itemStack.getDamageValue()); diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java index f57cbdc..0be0142 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java @@ -75,16 +75,14 @@ private static boolean playerMeetsConditions( boolean hasArmorTelekinesis = player.getInventory().armor.stream() .allMatch(item -> EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), item) > 0); boolean hasMainHandTelekinesis = (itemStack != null && EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), - itemStack) > 0) || EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), - player.getMainHandItem()) > 0; - boolean hasOffHandTelekinesis = EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), - player.getOffhandItem()) > 0; + itemStack + ) > 0) || EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), player.getMainHandItem()) > 0; + boolean hasOffHandTelekinesis = EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), player.getOffhandItem()) > 0; if (isEnabledByDefault) conditionsMet = true; else switch (policy) { case ExpDrops -> conditionsMet = hasArmorTelekinesis || hasMainHandTelekinesis || hasOffHandTelekinesis; - case MobDrops, ShearingDrops, VehicleDrops, FishingDrops -> - conditionsMet = hasMainHandTelekinesis || hasOffHandTelekinesis; + case MobDrops, ShearingDrops, VehicleDrops, FishingDrops -> conditionsMet = hasMainHandTelekinesis || hasOffHandTelekinesis; case BlockDrops -> conditionsMet = hasMainHandTelekinesis; } diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/Main.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/Main.kt index 54b9060..6c67387 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/Main.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/Main.kt @@ -9,4 +9,4 @@ lateinit var telekinesis: TelekinesisEnchantment fun init() { loadConfig() -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/ModMenuImpl.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/ModMenuImpl.kt index c9cd181..bd2ac2e 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/ModMenuImpl.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/ModMenuImpl.kt @@ -5,10 +5,9 @@ import com.terraformersmc.modmenu.api.ModMenuApi @Suppress("unused") class ModMenuImpl : ModMenuApi { - override fun getModConfigScreenFactory(): ConfigScreenFactory<*> { return ConfigScreenFactory { generateConfigScreen(it) } } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt index f44f9a4..1e6f973 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt @@ -59,8 +59,9 @@ lateinit var configPath: Path fun saveConfig() = configPath.writeText(Toml.encodeToString(TelekinesisConfig.serializer(), config)) fun loadConfig() { - configPath = FabricLoader.getInstance().configDir.toAbsolutePath().resolve("telekinesis.toml") - .also { if (!it.exists()) it.createFile() } + configPath = + FabricLoader.getInstance().configDir.toAbsolutePath().resolve("telekinesis.toml") + .also { if (!it.exists()) it.createFile() } if (configPath.readText().isEmpty()) { saveConfig() @@ -72,4 +73,4 @@ fun loadConfig() { } catch (e: Exception) { saveConfig() } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt index 9949b17..b0b1986 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt @@ -24,7 +24,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.onbydefault")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.onbydefault.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.onbydefault.description")) + ) .binding(config.onByDefault, { config.onByDefault }, { config.onByDefault = it }) .controller { TickBoxControllerBuilder.create(it) @@ -33,7 +36,12 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.onlywhilesneaking")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.onlywhilesneaking.description"))) + .description( + OptionDescription + .of( + Component.translatable("menu.telekinesis.config.general.onlywhilesneaking.description") + ) + ) .binding(config.onlyOnSneak, { config.onlyOnSneak }, { config.onlyOnSneak = it }) .controller { TickBoxControllerBuilder.create(it) @@ -56,7 +64,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.blockdrops")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.blockdrops.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.blockdrops.description")) + ) .binding(config.blockDrops, { config.blockDrops }, { config.blockDrops = it }) .controller { TickBoxControllerBuilder.create(it) @@ -65,7 +76,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.expdrops")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.expdrops.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.expdrops.description")) + ) .binding(config.expDrops, { config.expDrops }, { config.expDrops = it }) .controller { TickBoxControllerBuilder.create(it) @@ -74,7 +88,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.mobdrops")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.mobdrops.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.mobdrops.description")) + ) .binding(config.mobDrops, { config.mobDrops }, { config.mobDrops = it }) .controller { TickBoxControllerBuilder.create(it) @@ -83,7 +100,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.vehicledrops")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.vehicledrops.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.vehicledrops.description")) + ) .binding(config.vehicleDrops, { config.vehicleDrops }, { config.vehicleDrops = it }) .controller { TickBoxControllerBuilder.create(it) @@ -92,7 +112,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.shearingdrops")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.shearingdrops.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.shearingdrops.description")) + ) .binding(config.shearingDrops, { config.shearingDrops }, { config.shearingDrops = it }) .controller { TickBoxControllerBuilder.create(it) @@ -101,7 +124,10 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.fishingdrops")) - .description(OptionDescription.of(Component.translatable("menu.telekinesis.config.general.fishingdrops.description"))) + .description( + OptionDescription + .of(Component.translatable("menu.telekinesis.config.general.fishingdrops.description")) + ) .binding(config.fishingDrops, { config.fishingDrops }, { config.fishingDrops = it }) .controller { TickBoxControllerBuilder.create(it) @@ -109,4 +135,4 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { ) .build() ) -} \ No newline at end of file +} 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 aadbd1c..dd9f8e1 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt @@ -2,28 +2,24 @@ package dev.nyon.telekinesis import net.minecraft.network.chat.Component import net.minecraft.network.chat.Style -import net.minecraft.world.damagesource.DamageSource +import net.minecraft.tags.ItemTags import net.minecraft.world.entity.EquipmentSlot -import net.minecraft.world.entity.MobType import net.minecraft.world.item.enchantment.Enchantment -import net.minecraft.world.item.enchantment.EnchantmentCategory /** * The telekinesis enchantment model */ class TelekinesisEnchantment : Enchantment( - Rarity.RARE, EnchantmentCategory.BREAKABLE, listOf(EquipmentSlot.OFFHAND, EquipmentSlot.MAINHAND).toTypedArray() + definition( + ItemTags.DURABILITY_ENCHANTABLE, + 2, + 1, + dynamicCost(25, 25), + dynamicCost(75, 25), + 5, + *EquipmentSlot.entries.toTypedArray() + ) ) { - - override fun getMinLevel(): Int = 1 - override fun getMaxLevel(): Int = 1 - - override fun getMinCost(i: Int): Int = 30 - override fun getMaxCost(i: Int): Int = 30 - - 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)) -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt index 72b27cb..3c8e44c 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt @@ -8,12 +8,13 @@ enum class TelekinesisPolicy { ShearingDrops, FishingDrops; - fun isEnabled(): Boolean = when (this) { - BlockDrops -> config.blockDrops - ExpDrops -> config.expDrops - MobDrops -> config.mobDrops - VehicleDrops -> config.vehicleDrops - ShearingDrops -> config.shearingDrops - FishingDrops -> config.fishingDrops - } -} \ No newline at end of file + fun isEnabled(): Boolean = + when (this) { + BlockDrops -> config.blockDrops + ExpDrops -> config.expDrops + MobDrops -> config.mobDrops + VehicleDrops -> config.vehicleDrops + ShearingDrops -> config.shearingDrops + FishingDrops -> config.fishingDrops + } +} diff --git a/telekinesis-fabric/src/main/resources/fabric.mod.json b/telekinesis-fabric/src/main/resources/fabric.mod.json index 5ef054f..f873b06 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.17+kotlin.1.9.22", + "fabric-language-kotlin": ">=1.10.19+kotlin.1.9.23", "yet_another_config_lib_v3": ">=3.3.1+1.20.4", - "minecraft": ">=1.20.3" + "minecraft": ">1.20.4" }, "suggests": { - "modmenu": ">=9.0.0" + "modmenu": ">=10.0.0-alpha.3" }, "entrypoints": { "main": [ @@ -40,11 +40,9 @@ ] }, "mixins": [ - "telekinesis.mixins.json", - "compat.treeharvester.mixins.json", - "compat.betternether.mixins.json", - "compat.levelz.mixins.json" + "telekinesis.mixins.json" ], + "accessWidener": "telekinesis.accesswidener", "custom": { "modmenu": { "links": { @@ -52,4 +50,4 @@ } } } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/resources/telekinesis.accesswidener b/telekinesis-fabric/src/main/resources/telekinesis.accesswidener new file mode 100644 index 0000000..09fb9bf --- /dev/null +++ b/telekinesis-fabric/src/main/resources/telekinesis.accesswidener @@ -0,0 +1,3 @@ +accessWidener v2 named + +accessible method net/minecraft/world/level/block/InfestedBlock spawnAfterBreak (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;Z)V \ No newline at end of file