From 03076fbef9688446ac714d5979ff2ce38cec54a0 Mon Sep 17 00:00:00 2001 From: hashalite Date: Wed, 2 Mar 2022 22:43:22 -0500 Subject: [PATCH] - Added 'Disable on Damage' setting - Reordered settings --- .../net/xolt/freecam/config/ModConfig.java | 19 +++++++++++-------- .../mixins/ClientPlayerEntityMixin.java | 9 +++++++++ .../resources/assets/freecam/lang/en_us.json | 5 +++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/xolt/freecam/config/ModConfig.java b/src/main/java/net/xolt/freecam/config/ModConfig.java index c791f7e7..1fd97382 100644 --- a/src/main/java/net/xolt/freecam/config/ModConfig.java +++ b/src/main/java/net/xolt/freecam/config/ModConfig.java @@ -23,24 +23,27 @@ public static void init() { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public FlightMode flightMode = FlightMode.DEFAULT; - @Comment("Changes the horizontal speed of freecam.") + @Comment("The horizontal speed of freecam.") public double horizontalSpeed = 1.0; - @Comment("Changes the vertical speed of freecam.") + @Comment("The vertical speed of freecam.") public double verticalSpeed = 0.8; - @Comment("Toggles whether you can break blocks while freecam is enabled.") - public boolean allowBlockBreak = true; - - @Comment("Toggles whether you can interact with entities while freecam is enabled.") - public boolean allowEntityInteract = true; - @Comment("Toggles whether your player is rendered in your original position while freecam is enabled.") public boolean showPlayer = true; @Comment("Toggles whether your hand is shown while freecam is enabled.") public boolean showHand = false; + @Comment("Toggles whether taking damage disables freecam.") + public boolean disableOnDamage = true; + + @Comment("Toggles whether you can break blocks while freecam is enabled.") + public boolean allowBlockBreak = true; + + @Comment("Toggles whether you can interact with entities while freecam is enabled.") + public boolean allowEntityInteract = true; + @Comment("Toggles action bar notifications.") public boolean notify = true; diff --git a/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java b/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java index 2be7d28c..ab9f69eb 100644 --- a/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java +++ b/src/main/java/net/xolt/freecam/mixins/ClientPlayerEntityMixin.java @@ -2,9 +2,11 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.xolt.freecam.Freecam; +import net.xolt.freecam.config.ModConfig; 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; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import static net.xolt.freecam.Freecam.MC; @@ -18,4 +20,11 @@ private void onIsCamera(CallbackInfoReturnable cir) { cir.setReturnValue(true); } } + + @Inject(method = "damage", at = @At("HEAD")) + private void onDamage(CallbackInfoReturnable cir) { + if (Freecam.isEnabled() && ModConfig.INSTANCE.disableOnDamage && this.equals(MC.player)) { + Freecam.toggle(); + } + } } diff --git a/src/main/resources/assets/freecam/lang/en_us.json b/src/main/resources/assets/freecam/lang/en_us.json index 01f7301e..627c4016 100644 --- a/src/main/resources/assets/freecam/lang/en_us.json +++ b/src/main/resources/assets/freecam/lang/en_us.json @@ -5,10 +5,11 @@ "text.autoconfig.freecam.option.flightMode": "Flight Mode", "text.autoconfig.freecam.option.horizontalSpeed": "Horizontal Speed", "text.autoconfig.freecam.option.verticalSpeed": "Vertical Speed", + "text.autoconfig.freecam.option.showPlayer": "Show Player", + "text.autoconfig.freecam.option.showHand": "Show Hand", + "text.autoconfig.freecam.option.disableOnDamage": "Disable on Damage", "text.autoconfig.freecam.option.allowBlockBreak": "Allow Breaking Blocks", "text.autoconfig.freecam.option.allowEntityInteract": "Allow Entity Interaction", - "text.autoconfig.freecam.option.showHand": "Show Hand", - "text.autoconfig.freecam.option.showPlayer": "Show Player", "text.autoconfig.freecam.option.notify": "Notifications", "text.autoconfig.freecam.option.enableMessage": "Enable Message", "text.autoconfig.freecam.option.disableMessage": "Disable Message"