aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDJtheRedstoner <52044242+DJtheRedstoner@users.noreply.github.com>2020-09-01 10:18:01 -0400
committerDJtheRedstoner <52044242+DJtheRedstoner@users.noreply.github.com>2020-09-01 10:18:01 -0400
commitb6ab017f89de88a4e7c9656d62e2e12c91cab523 (patch)
treeccc8e947a77799ab7ca1b31fb1b9faae014c8beb /src
parent2dd36367ec1ea8e18a0e6bc5cafbd65ac5383bde (diff)
downloadPerspectiveModv4-b6ab017f89de88a4e7c9656d62e2e12c91cab523.tar.gz
PerspectiveModv4-b6ab017f89de88a4e7c9656d62e2e12c91cab523.tar.bz2
PerspectiveModv4-b6ab017f89de88a4e7c9656d62e2e12c91cab523.zip
Bug Fixes
Exit perspective when opening a gui (#3) Exit perspective when changing vanilla perspective Add github actions build
Diffstat (limited to 'src')
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java19
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/mixins/MixinMinecraft.java25
-rw-r--r--src/main/resources/mixins.djperspectivemod.json1
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