diff options
Diffstat (limited to 'src')
3 files changed, 41 insertions, 4 deletions
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java index 5cdbd3b..8158b97 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java @@ -6,6 +6,7 @@ import me.djtheredstoner.perspectivemod.config.PerspectiveModConfig; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.client.ClientCommandHandler; +import net.minecraftforge.client.event.GuiOpenEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; @@ -65,6 +66,13 @@ public class PerspectiveMod { } } + @SubscribeEvent + public void onGuiOpen(GuiOpenEvent event) { + if(event.gui != null) { + resetPerspective(); + } + } + public static void onPressed(int eventKey, boolean state) { if (eventKey == perspectiveKey.getKeyCode()) { if (config.modEnabled) { @@ -80,12 +88,10 @@ public class PerspectiveMod { mc.gameSettings.thirdPersonView = previousPerspective; } } else if (config.holdMode) { - perspectiveToggled = false; - mc.gameSettings.thirdPersonView = previousPerspective; + resetPerspective(); } } else if (perspectiveToggled) { - perspectiveToggled = false; - mc.gameSettings.thirdPersonView = previousPerspective; + resetPerspective(); } } } @@ -113,6 +119,11 @@ public class PerspectiveMod { return false; } + public static void resetPerspective() { + perspectiveToggled = false; + mc.gameSettings.thirdPersonView = previousPerspective; + } + public static void loadConfig(File configFile) { if (configFile.exists()) { try { diff --git a/src/main/java/me/djtheredstoner/perspectivemod/mixins/MixinMinecraft.java b/src/main/java/me/djtheredstoner/perspectivemod/mixins/MixinMinecraft.java new file mode 100644 index 0000000..3083599 --- /dev/null +++ b/src/main/java/me/djtheredstoner/perspectivemod/mixins/MixinMinecraft.java @@ -0,0 +1,25 @@ +package me.djtheredstoner.perspectivemod.mixins; + +import me.djtheredstoner.perspectivemod.PerspectiveMod; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.GameSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import static org.objectweb.asm.Opcodes.*; + +@Mixin(Minecraft.class) +public class MixinMinecraft { + + @Redirect(method = "runTick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;thirdPersonView:I", opcode = PUTFIELD)) + public void setThirdPersonView(GameSettings gameSettings, int value) { + if(PerspectiveMod.perspectiveToggled) { + PerspectiveMod.resetPerspective(); + } else { + gameSettings.thirdPersonView = value; + } + } + +} diff --git a/src/main/resources/mixins.djperspectivemod.json b/src/main/resources/mixins.djperspectivemod.json index 1ecb9ea..4244d13 100644 --- a/src/main/resources/mixins.djperspectivemod.json +++ b/src/main/resources/mixins.djperspectivemod.json @@ -7,6 +7,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "MixinEntityRenderer", + "MixinMinecraft", "MixinRenderManager" ] }
\ No newline at end of file |