aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java')
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java50
1 files changed, 11 insertions, 39 deletions
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
index 75a0a5e..0133ff1 100644
--- a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
+++ b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
@@ -1,7 +1,6 @@
package me.djtheredstoner.perspectivemod;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
+import me.djtheredstoner.perspectivemod.commands.PerspectiveModCommand;
import me.djtheredstoner.perspectivemod.config.PerspectiveModConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
@@ -12,23 +11,18 @@ import net.minecraftforge.event.world.WorldEvent;
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.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
-import org.apache.commons.io.FileUtils;
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;
-import java.io.File;
-
-@Mod(modid = "djperspectivemod", name = "Perspective Mod v4", version = "4.1", acceptedMinecraftVersions = "[1.8.9]", clientSideOnly = true)
+@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 Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final KeyBinding perspectiveKey = new KeyBinding("Perspective", Keyboard.KEY_LMENU, "Perspective Mod");
private static final Logger logger = LogManager.getLogger("Perspective Mod v4");
@@ -40,14 +34,12 @@ public class PerspectiveMod {
private static int previousPerspective = 0;
@Mod.EventHandler
- public void preInit(FMLPreInitializationEvent event) {
- File configFile = new File(event.getModConfigurationDirectory(), "perspectivemodv4.json");
- loadConfig(configFile);
- Runtime.getRuntime().addShutdownHook(new Thread(() -> saveConfig(configFile)));
- }
-
- @Mod.EventHandler
public void init(FMLInitializationEvent event) {
+ ModCoreInstaller.initializeModCore(Minecraft.getMinecraft().mcDataDir);
+
+ config = new PerspectiveModConfig();
+ config.preload();
+
ClientRegistry.registerKeyBinding(perspectiveKey);
ClientCommandHandler.instance.registerCommand(new PerspectiveModCommand());
MinecraftForge.EVENT_BUS.register(this);
@@ -117,6 +109,10 @@ public class PerspectiveMod {
float f3 = (float) mc.mouseHelper.deltaX * f2;
float f4 = (float) mc.mouseHelper.deltaY * f2;
+ if(config.invertPitch) {
+ f4 = -f4;
+ }
+
cameraYaw += f3 * 0.15F;
cameraPitch += f4 * 0.15F;
@@ -131,28 +127,4 @@ public class PerspectiveMod {
perspectiveToggled = false;
mc.gameSettings.thirdPersonView = previousPerspective;
}
-
- public static void loadConfig(File configFile) {
- if (configFile.exists()) {
- try {
- String json = FileUtils.readFileToString(configFile);
- config = gson.fromJson(json, PerspectiveModConfig.class);
- } catch (Exception e) {
- logger.error("Error Loading Config, try deleting the file.");
- e.printStackTrace();
- }
- } else {
- config = new PerspectiveModConfig();
- saveConfig(configFile);
- }
- }
-
- public static void saveConfig(File configFile) {
- try {
- String json = gson.toJson(config);
- FileUtils.write(configFile, json);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
}