diff options
author | DJtheRedstoner <52044242+DJtheRedstoner@users.noreply.github.com> | 2020-10-21 21:15:01 -0400 |
---|---|---|
committer | DJtheRedstoner <52044242+DJtheRedstoner@users.noreply.github.com> | 2020-10-21 21:15:01 -0400 |
commit | ab4eb74fb5af37b7eaf5e9faa95debb75721d269 (patch) | |
tree | f68910a45549b5c3636228a016824a5b3e965dbe /src | |
parent | 3cd0d242a9a631ab7a255c81a761b9a91c6d23b5 (diff) | |
download | PerspectiveModv4-ab4eb74fb5af37b7eaf5e9faa95debb75721d269.tar.gz PerspectiveModv4-ab4eb74fb5af37b7eaf5e9faa95debb75721d269.tar.bz2 PerspectiveModv4-ab4eb74fb5af37b7eaf5e9faa95debb75721d269.zip |
Bug Fixes:
- Fix spazing in and out
- Now with 100% less static abuse
Diffstat (limited to 'src')
6 files changed, 49 insertions, 52 deletions
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java index 6d71bf0..34e3b13 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java @@ -3,6 +3,7 @@ package me.djtheredstoner.perspectivemod; import me.djtheredstoner.perspectivemod.commands.PerspectiveModCommand; import me.djtheredstoner.perspectivemod.config.PerspectiveModConfig; import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.GuiOpenEvent; @@ -12,32 +13,35 @@ import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; @Mod(modid = "djperspectivemod", name = "Perspective Mod v4", version = "4.2", acceptedMinecraftVersions = "[1.8.9]", clientSideOnly = true) public class PerspectiveMod { - private static final Minecraft mc = Minecraft.getMinecraft(); - private static final KeyBinding perspectiveKey = new KeyBinding("Perspective", Keyboard.KEY_LMENU, "Perspective Mod"); - private static final Logger logger = LogManager.getLogger("Perspective Mod v4"); + @Mod.Instance + public static PerspectiveMod instance; - public static PerspectiveModConfig config; + public final PerspectiveModConfig config = new PerspectiveModConfig(); - public static boolean perspectiveToggled = false; - public static float cameraYaw = 0F; - public static float cameraPitch = 0F; - private static int previousPerspective = 0; + public boolean perspectiveToggled = false; + public float cameraYaw = 0F; + public float cameraPitch = 0F; + + private int previousPerspective = 0; + private boolean prevState = false; + + private final Minecraft mc = Minecraft.getMinecraft(); + private final KeyBinding perspectiveKey = new KeyBinding("Perspective", Keyboard.KEY_LMENU, "Perspective Mod"); + private final Logger logger = LogManager.getLogger("Perspective Mod v4"); @Mod.EventHandler public void init(FMLInitializationEvent event) { ModCoreInstaller.initializeModCore(Minecraft.getMinecraft().mcDataDir); - config = new PerspectiveModConfig(); config.preload(); ClientRegistry.registerKeyBinding(perspectiveKey); @@ -46,16 +50,11 @@ public class PerspectiveMod { } @SubscribeEvent - public void onKeyEvent(InputEvent.KeyInputEvent event) { - if (perspectiveKey.getKeyCode() > 0) { - onPressed(Keyboard.getEventKey(), Keyboard.getEventKeyState()); - } - } - - @SubscribeEvent - public void onMouseEvent(InputEvent.MouseInputEvent event) { - if (perspectiveKey.getKeyCode() < 0) { - onPressed(Mouse.getEventButton() - 100, Mouse.getEventButtonState()); + public void tick(TickEvent.RenderTickEvent event) { + boolean down = GameSettings.isKeyDown(perspectiveKey); + if(down != prevState && mc.currentScreen == null) { + prevState = down; + onPressed(0, down); } } @@ -73,30 +72,28 @@ public class PerspectiveMod { } } - public static void onPressed(int eventKey, boolean state) { - if (eventKey == perspectiveKey.getKeyCode()) { - if (config.modEnabled) { - if (state) { - perspectiveToggled = !perspectiveToggled; - cameraYaw = mc.thePlayer.rotationYaw; - cameraPitch = mc.thePlayer.rotationPitch; - - if (perspectiveToggled) { - previousPerspective = mc.gameSettings.thirdPersonView; - mc.gameSettings.thirdPersonView = 1; - } else { - mc.gameSettings.thirdPersonView = previousPerspective; - } - } else if (config.holdMode) { - resetPerspective(); + public void onPressed(int eventKey, boolean state) { + if (config.modEnabled) { + if (state) { + perspectiveToggled = !perspectiveToggled; + cameraYaw = mc.thePlayer.rotationYaw; + cameraPitch = mc.thePlayer.rotationPitch; + + if (perspectiveToggled) { + previousPerspective = mc.gameSettings.thirdPersonView; + mc.gameSettings.thirdPersonView = 1; + } else { + mc.gameSettings.thirdPersonView = previousPerspective; } - } else if (perspectiveToggled) { + } else if (config.holdMode) { resetPerspective(); } + } else if (perspectiveToggled) { + resetPerspective(); } } - public static boolean overrideMouse() { + public boolean overrideMouse() { if (mc.inGameHasFocus && Display.isActive()) { if (!perspectiveToggled) { return true; @@ -124,7 +121,7 @@ public class PerspectiveMod { return false; } - public static void resetPerspective() { + public void resetPerspective() { perspectiveToggled = false; mc.gameSettings.thirdPersonView = previousPerspective; } diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java index e60ede4..94296d1 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/ActiveRenderInfoHook.java @@ -6,11 +6,11 @@ import net.minecraft.entity.player.EntityPlayer; public class ActiveRenderInfoHook { public static float rotationYawHook(EntityPlayer entity) { - return PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraYaw : entity.rotationYaw; + return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : entity.rotationYaw; } public static float rotationPitchHook(EntityPlayer entity) { - return PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraPitch : entity.rotationPitch; + return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : entity.rotationPitch; } } diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java index 193affb..ebdfd88 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/EntityRendererHook.java @@ -7,23 +7,23 @@ import net.minecraft.entity.Entity; public class EntityRendererHook { public static float rotationYawHook(Entity entity) { - return PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraYaw : entity.rotationYaw; + return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : entity.rotationYaw; } public static float prevRotationYawHook(Entity entity) { - return PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraYaw : entity.prevRotationYaw; + return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : entity.prevRotationYaw; } public static float rotationPitchHook(Entity entity) { - return PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraPitch : entity.rotationPitch; + return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : entity.rotationPitch; } public static float prevRotationPitchHook(Entity entity) { - return PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraPitch : entity.prevRotationPitch; + return PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : entity.prevRotationPitch; } public static boolean mouseHook(Minecraft minecraft) { - return PerspectiveMod.overrideMouse(); + return PerspectiveMod.instance.overrideMouse(); } public static double distanceHook(double value) { diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java index e502232..31914f8 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/MinecraftHook.java @@ -6,8 +6,8 @@ import net.minecraft.client.settings.GameSettings; public class MinecraftHook { public static void thirdPersonHook(GameSettings gameSettings, int value) { - if(PerspectiveMod.perspectiveToggled) { - PerspectiveMod.resetPerspective(); + if(PerspectiveMod.instance.perspectiveToggled) { + PerspectiveMod.instance.resetPerspective(); } else { gameSettings.thirdPersonView = value; } diff --git a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java index 3373378..2f55de1 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/asm/hooks/RenderManagerHook.java @@ -6,10 +6,10 @@ import net.minecraft.client.renderer.entity.RenderManager; public class RenderManagerHook { public static void playerViewXHook(RenderManager renderManager, float value) { - renderManager.playerViewX = PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraPitch : value; + renderManager.playerViewX = PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraPitch : value; } public static void playerViewYHook(RenderManager renderManager, float value) { - renderManager.playerViewY = PerspectiveMod.perspectiveToggled ? PerspectiveMod.cameraYaw : value; + renderManager.playerViewY = PerspectiveMod.instance.perspectiveToggled ? PerspectiveMod.instance.cameraYaw : value; } } diff --git a/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java b/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java index 68dd051..cad7f79 100644 --- a/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java +++ b/src/main/java/me/djtheredstoner/perspectivemod/commands/PerspectiveModCommand.java @@ -37,7 +37,7 @@ public class PerspectiveModCommand extends CommandBase { if (args.length == 1 && args[0].equals("eW91IGZvdW5kIGEgc2VjcmV0IQo=")) { sendMessage("you found a secret!"); } else { - ModCore.getInstance().getGuiHandler().open(PerspectiveMod.config.gui()); + ModCore.getInstance().getGuiHandler().open(PerspectiveMod.instance.config.gui()); } } |