From 034513d7df518ce6730c71d7147832ff8efb236a Mon Sep 17 00:00:00 2001 From: Yak <107325508+TheTrueYak@users.noreply.github.com> Date: Mon, 14 Apr 2025 04:25:07 -0500 Subject: [PATCH] update to 1.21.1 -updated to 1.21.1, also updated loom and gradle -refactored mixins, using the beautiful and powerful WrapOperation for more simplicity and better compatibility with other mods (thank you MixinExtras) I've never made a pr before so I hope this works lmfao --- build.gradle | 8 +++---- gradle.properties | 10 ++++----- gradle/wrapper/gradle-wrapper.properties | 2 +- .../mixin/PeacefulHungerManagerMixin.java | 22 ++++++++----------- .../hungy/mixin/PretendNotPeacefulMixin.java | 20 +++++++++++++++++ .../PretendNotPeacefulRedirectMixin.java | 16 -------------- src/main/resources/fabric.mod.json | 9 ++++---- src/main/resources/hungy.mixins.json | 2 +- 8 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulMixin.java delete mode 100644 src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulRedirectMixin.java diff --git a/build.gradle b/build.gradle index e1d0330..21f263b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.3-SNAPSHOT' + id 'fabric-loom' version '1.10-SNAPSHOT' id 'maven-publish' } @@ -55,7 +55,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 17 + it.options.release = 21 } java { @@ -64,8 +64,8 @@ java { // If you remove this line, sources will not be generated. withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { diff --git a/gradle.properties b/gradle.properties index 44ae602..07c0509 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20 -yarn_mappings=1.20+build.1 -loader_version=0.14.22 +minecraft_version=1.21.1 +yarn_mappings=1.21.1+build.3 +loader_version=0.16.13 # Mod Properties -mod_version=1.0.1 +mod_version=1.0.2 maven_group=xyz.fulmine.hungy archives_base_name=hungy # Dependencies -fabric_version=0.83.0+1.20 \ No newline at end of file +fabric_version=0.115.4+1.21.1 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9f4197d..e18bc25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/xyz/fulmine/hungy/mixin/PeacefulHungerManagerMixin.java b/src/main/java/xyz/fulmine/hungy/mixin/PeacefulHungerManagerMixin.java index e640e55..3b9b97c 100644 --- a/src/main/java/xyz/fulmine/hungy/mixin/PeacefulHungerManagerMixin.java +++ b/src/main/java/xyz/fulmine/hungy/mixin/PeacefulHungerManagerMixin.java @@ -1,24 +1,20 @@ package xyz.fulmine.hungy.mixin; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.entity.player.HungerManager; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.Difficulty; -import org.objectweb.asm.Opcodes; +import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(HungerManager.class) -public class PeacefulHungerManagerMixin { - @Inject(at = @At( - value = "FIELD", - target = "Lnet/minecraft/entity/player/HungerManager;saturationLevel:F", - opcode = Opcodes.GETFIELD, - ordinal = 0), method = "update(Lnet/minecraft/entity/player/PlayerEntity;)V") - private void alwaysHungry(PlayerEntity player, CallbackInfo info) { - if (((HungerManager)(Object)this).getSaturationLevel() <= 0 && player.getWorld().getDifficulty() == Difficulty.PEACEFUL) { - ((HungerManager)(Object)this).setFoodLevel(Math.max(((HungerManager)(Object)this).getFoodLevel() - 1, 0)); +public abstract class PeacefulHungerManagerMixin { + @WrapOperation(method = "update(Lnet/minecraft/entity/player/PlayerEntity;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getDifficulty()Lnet/minecraft/world/Difficulty;")) + private Difficulty hungy$alwaysHungry(World instance, Operation original) { + if (instance.getDifficulty() == Difficulty.PEACEFUL) { + return Difficulty.NORMAL; } + return original.call(instance); } } \ No newline at end of file diff --git a/src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulMixin.java b/src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulMixin.java new file mode 100644 index 0000000..90266ee --- /dev/null +++ b/src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulMixin.java @@ -0,0 +1,20 @@ +package xyz.fulmine.hungy.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.Difficulty; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(PlayerEntity.class) +public abstract class PretendNotPeacefulMixin { + @WrapOperation(method = "tickMovement()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getDifficulty()Lnet/minecraft/world/Difficulty;")) + private Difficulty hungy$pretendItsNotPeaceful(World instance, Operation original) { + if (instance.getDifficulty() == Difficulty.PEACEFUL) { + return Difficulty.NORMAL; + } + return original.call(instance); + } +} diff --git a/src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulRedirectMixin.java b/src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulRedirectMixin.java deleted file mode 100644 index 4c699f8..0000000 --- a/src/main/java/xyz/fulmine/hungy/mixin/PretendNotPeacefulRedirectMixin.java +++ /dev/null @@ -1,16 +0,0 @@ -package xyz.fulmine.hungy.mixin; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.Difficulty; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(PlayerEntity.class) -public class PretendNotPeacefulRedirectMixin { - @Redirect(method = "tickMovement()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getDifficulty()Lnet/minecraft/world/Difficulty;")) - private Difficulty pretendItsNotPeaceful(World world) { - return Difficulty.NORMAL; - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 74ac1d8..6266c6d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -5,7 +5,8 @@ "name": "hungy", "description": "A simple mod that enables hunger in peaceful mode.", "authors": [ - "Jake Fulmine" + "Jake Fulmine", + "TheTrueYak" ], "contact": { "homepage": "https://modrinth.com/mod/hungy", @@ -30,8 +31,8 @@ } ], "depends": { - "fabricloader": ">=0.14.22", - "minecraft": "~1.20", - "java": ">=17" + "fabricloader": ">=0.16.0", + "minecraft": "~1.21.1", + "java": ">=21" } } \ No newline at end of file diff --git a/src/main/resources/hungy.mixins.json b/src/main/resources/hungy.mixins.json index f02d286..d1e0451 100644 --- a/src/main/resources/hungy.mixins.json +++ b/src/main/resources/hungy.mixins.json @@ -4,7 +4,7 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "PeacefulHungerManagerMixin", - "PretendNotPeacefulRedirectMixin" + "PretendNotPeacefulMixin" ], "injectors": { "defaultRequire": 1