diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index d0fc38ff..de5cade6 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -478,8 +478,9 @@ public static class EntitiesCategory @Config.RequiresMcRestart @Config.Name("Riding Exhaustion") - @Config.Comment("Enables depleting saturation when riding mounts") - public boolean utRidingExhaustionToggle = false; + @Config.Comment("Sets the exhaustion value per cm when riding mounts") + @Config.RangeDouble(min = 0.0D, max = 1.0D) + public double utRidingExhaustion = 0.0D; @Config.RequiresMcRestart @Config.Name("Soulbound Vexes") diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 391308c8..aadf2111 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -452,7 +452,7 @@ public boolean shouldMixinConfigQueue(String mixinConfig) case "mixins.tweaks.entities.loot.json": return UTConfigTweaks.ENTITIES.utCreeperMusicDiscsToggle; case "mixins.tweaks.entities.saturation.json": - return UTConfigTweaks.ENTITIES.utRidingExhaustionToggle; + return UTConfigTweaks.ENTITIES.utRidingExhaustion != 0.0D; case "mixins.tweaks.entities.spawning.caps.json": return UTConfigTweaks.ENTITIES.SPAWN_CAPS.utSpawnCapsToggle; case "mixins.tweaks.entities.spawning.creeper.confetti.json": diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/saturation/mixin/UTRidingExhaustionMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/saturation/mixin/UTRidingExhaustionMixin.java index aa62eecd..b514ec70 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/saturation/mixin/UTRidingExhaustionMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/saturation/mixin/UTRidingExhaustionMixin.java @@ -1,18 +1,38 @@ package mod.acgaming.universaltweaks.tweaks.entities.saturation.mixin; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; +import mod.acgaming.universaltweaks.UniversalTweaks; +import mod.acgaming.universaltweaks.config.UTConfigGeneral; import mod.acgaming.universaltweaks.config.UTConfigTweaks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityPlayer.class) -public class UTRidingExhaustionMixin +public abstract class UTRidingExhaustionMixin extends EntityLivingBase { - @Redirect(method = "addMovementStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;isRiding()Z")) - public boolean utRidingExhaustion(EntityPlayer player) + protected UTRidingExhaustionMixin(World worldIn) { - return player.isRiding() || UTConfigTweaks.ENTITIES.utRidingExhaustionToggle; + super(worldIn); + } + + @Inject(method = "addMountedMovementStat", at = @At(value = "TAIL")) + public void utRidingExhaustion(double speedX, double speedY, double speedZ, CallbackInfo ci) + { + if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTRidingExhaustion ::: Add exhaustion while riding"); + if (this.isRiding()) + { + int i = Math.round(MathHelper.sqrt(speedX * speedX + speedY * speedY + speedZ * speedZ)); + + if (i > 0) + { + ((EntityPlayer) (Object) this).addExhaustion((float) (i * UTConfigTweaks.ENTITIES.utRidingExhaustion)); + } + } } } \ No newline at end of file