diff --git a/common/src/main/java/dev/igalaxy/takeitslow/mixin/LivingEntityMixin.java b/common/src/main/java/dev/igalaxy/takeitslow/mixin/LivingEntityMixin.java new file mode 100644 index 0000000..238ca0b --- /dev/null +++ b/common/src/main/java/dev/igalaxy/takeitslow/mixin/LivingEntityMixin.java @@ -0,0 +1,31 @@ +package dev.igalaxy.takeitslow.mixin; + +import dev.igalaxy.takeitslow.TakeItSlow; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.GameType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(LivingEntity.class) +public class LivingEntityMixin { + @ModifyVariable(method = "setSprinting(Z)V", at = @At("HEAD")) + private boolean modifySetSprinting(boolean bl) { + if (((Object) this) instanceof LocalPlayer) { + LocalPlayer player = (LocalPlayer) (Object) this; + + GameType localPlayerMode = ((LocalPlayerAccessor)player).getMinecraft().gameMode.getPlayerMode(); + + boolean allowSwimming = TakeItSlow.getConfig().allowSwimming; + boolean allowCreative = TakeItSlow.getConfig().allowCreative; + + boolean isUnderwater = player.isUnderWater(); + boolean isCreative = localPlayerMode == GameType.CREATIVE; + boolean isSpectator = localPlayerMode == GameType.SPECTATOR; + + return (isUnderwater && bl && allowSwimming) || (isCreative && bl && allowCreative) || (isSpectator && bl && allowCreative); + } + return bl; + } +} diff --git a/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerAccessor.java b/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerAccessor.java new file mode 100644 index 0000000..292046f --- /dev/null +++ b/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerAccessor.java @@ -0,0 +1,12 @@ +package dev.igalaxy.takeitslow.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(LocalPlayer.class) +public interface LocalPlayerAccessor { + @Accessor + Minecraft getMinecraft(); +} diff --git a/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerMixin.java b/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerMixin.java index bf69b7b..9ec682d 100644 --- a/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerMixin.java +++ b/common/src/main/java/dev/igalaxy/takeitslow/mixin/LocalPlayerMixin.java @@ -3,6 +3,7 @@ import dev.igalaxy.takeitslow.TakeItSlow; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.GameType; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -16,21 +17,6 @@ public abstract class LocalPlayerMixin { @Shadow @Final protected Minecraft minecraft; @Shadow public abstract boolean isUnderWater(); - @Shadow public abstract void setSprinting(boolean bl); - - @ModifyVariable(method = "setSprinting(Z)V", at = @At("HEAD")) - private boolean modifySetSprinting(boolean bl) { - GameType localPlayerMode = ((MultiPlayerGameModeAccessor)this.minecraft.gameMode).getLocalPlayerMode(); - - boolean allowSwimming = TakeItSlow.getConfig().allowSwimming; - boolean allowCreative = TakeItSlow.getConfig().allowCreative; - - boolean isUnderwater = this.isUnderWater(); - boolean isCreative = localPlayerMode == GameType.CREATIVE; - boolean isSpectator = localPlayerMode == GameType.SPECTATOR; - - return (isUnderwater && bl && allowSwimming) || (isCreative && bl && allowCreative) || (isSpectator && bl && allowCreative); - } @Inject(method = "updateIsUnderwater", at = @At("TAIL")) private void modifyUpdateIsUnderwater(CallbackInfoReturnable cir) { @@ -41,7 +27,7 @@ private void modifyUpdateIsUnderwater(CallbackInfoReturnable cir) { boolean isSpectator = localPlayerMode == GameType.SPECTATOR; if (!isUnderwater && !isCreative && !isSpectator) { - this.setSprinting(false); + ((LivingEntity) (Object) this).setSprinting(false); } } } \ No newline at end of file diff --git a/common/src/main/resources/takeitslow-common.mixins.json b/common/src/main/resources/takeitslow-common.mixins.json index be5dcfc..eb5b916 100644 --- a/common/src/main/resources/takeitslow-common.mixins.json +++ b/common/src/main/resources/takeitslow-common.mixins.json @@ -4,6 +4,8 @@ "compatibilityLevel": "JAVA_16", "client": [ "LocalPlayerMixin", + "LocalPlayerAccessor", + "LivingEntityMixin", "MultiPlayerGameModeAccessor" ], "mixins": [ diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 1a85d2f..baeab9c 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -16,20 +16,20 @@ Who needs sprinting anyways? [[dependencies.takeitslow]] modId = "forge" mandatory = true -versionRange = "[41,)" +versionRange = "[45,)" ordering = "NONE" side = "BOTH" [[dependencies.takeitslow]] modId = "minecraft" mandatory = true -versionRange = "[1.19,)" +versionRange = "[1.19.4,)" ordering = "NONE" side = "BOTH" [[dependencies.takeitslow]] modId = "cloth_config" mandatory = true -versionRange = "[8,9)" +versionRange = "[10,11)" ordering = "NONE" side = "BOTH" \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 6ad0d53..dd4d62a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,20 @@ org.gradle.jvmargs=-Xmx2048M -minecraft_version=1.19 +minecraft_version=1.19.4 enabled_platforms=fabric,forge archives_base_name=take-it-slow -mod_version=1.0.3 +mod_version=1.1.0 maven_group=dev.igalaxy.takeitslow -architectury_version=5.6.22 +architectury_version=8.1.73 fabric_loader_version=0.14.7 -forge_version=1.19-41.1.0 +forge_version=1.19.4-45.0.9 -cloth_version = 8.+ -modmenu_version = 4.0.4 +cloth_version = 10.+ +modmenu_version = 6.1.0-rc.4