aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/perspectivemod.png (renamed from perspectivemod.png)bin727415 -> 727415 bytes
-rw-r--r--README.md2
-rw-r--r--build.gradle14
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java24
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/PerspectiveModCommand.java28
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java2
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java80
7 files changed, 115 insertions, 35 deletions
diff --git a/perspectivemod.png b/.github/perspectivemod.png
index c87b15a..c87b15a 100644
--- a/perspectivemod.png
+++ b/.github/perspectivemod.png
Binary files differ
diff --git a/README.md b/README.md
index eece8f8..8c07a63 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
A remake of [Perspective Mod v3 by canelex](https://github.com/Canelex/PerspectiveMod) with bug fixes and additional functionality
-![Image of mod](perspectivemod.png)
+![Image of mod](.github/perspectivemod.png)
Features:
- Mouse button support
diff --git a/build.gradle b/build.gradle
index c4a3739..cafad49 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,7 +21,8 @@ apply plugin: "com.github.johnrengelman.shadow"
version = "4.0"
group= "me.djtheredstoner"
archivesBaseName = "PerspectiveModv4"
-String modid = "djperspectivemod"
+
+def modid = "djperspectivemod"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@@ -36,8 +37,8 @@ sourceSets {
minecraft {
version = "1.8.9-11.15.1.2318-1.8.9"
runDir = "run"
-
mappings = "stable_22"
+ clientJvmArgs += "-Dfml.coreMods.load=me.djtheredstoner.perspectivemod.forge.PerspectiveModLoadingPlugin"
}
repositories {
@@ -46,7 +47,11 @@ repositories {
}
dependencies {
- implementation 'org.spongepowered:mixin:0.7.11-SNAPSHOT'
+ implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
+ exclude module: 'gson'
+ exclude module: 'guava'
+ exclude module: 'commons-io'
+ }
}
mixin {
@@ -67,7 +72,8 @@ shadowJar {
'MixinConfigs': "mixins.${modid}.json",
'FMLCorePluginContainsFMLMod': true,
"ForceLoadAsMod": true,
- 'ModSide': 'CLIENT'
+ 'ModSide': 'CLIENT',
+ "FMLCorePlugin": "me.djtheredstoner.perspectivemod.forge.PerspectiveTweaker"
)
exclude('dummyThing')
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
index f819c66..5cdbd3b 100644
--- a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
+++ b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveMod.java
@@ -22,7 +22,6 @@ import org.lwjgl.opengl.Display;
import java.io.File;
-
@Mod(modid = "djperspectivemod", name = "Perspective Mod v4", version = "4.0", acceptedMinecraftVersions = "[1.8.9]", clientSideOnly = true)
public class PerspectiveMod {
@@ -42,9 +41,7 @@ public class PerspectiveMod {
public void preInit(FMLPreInitializationEvent event) {
File configFile = new File(event.getModConfigurationDirectory(), "perspectivemodv4.json");
loadConfig(configFile);
- Runtime.getRuntime().addShutdownHook(new Thread(() -> {
- saveConfig(configFile);
- }));
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> saveConfig(configFile)));
}
@Mod.EventHandler
@@ -56,21 +53,21 @@ public class PerspectiveMod {
@SubscribeEvent
public void onKeyEvent(InputEvent.KeyInputEvent event) {
- if(perspectiveKey.getKeyCode() > 0) {
+ if (perspectiveKey.getKeyCode() > 0) {
onPressed(Keyboard.getEventKey(), Keyboard.getEventKeyState());
}
}
@SubscribeEvent
public void onMouseEvent(InputEvent.MouseInputEvent event) {
- if(perspectiveKey.getKeyCode() < 0) {
+ if (perspectiveKey.getKeyCode() < 0) {
onPressed(Mouse.getEventButton() - 100, Mouse.getEventButtonState());
}
}
public static void onPressed(int eventKey, boolean state) {
if (eventKey == perspectiveKey.getKeyCode()) {
- if(config.modEnabled) {
+ if (config.modEnabled) {
if (state) {
perspectiveToggled = !perspectiveToggled;
cameraYaw = mc.thePlayer.rotationYaw;
@@ -86,7 +83,7 @@ public class PerspectiveMod {
perspectiveToggled = false;
mc.gameSettings.thirdPersonView = previousPerspective;
}
- } else if(perspectiveToggled) {
+ } else if (perspectiveToggled) {
perspectiveToggled = false;
mc.gameSettings.thirdPersonView = previousPerspective;
}
@@ -94,10 +91,8 @@ public class PerspectiveMod {
}
public static boolean overrideMouse() {
- if (mc.inGameHasFocus && Display.isActive())
- {
- if (!perspectiveToggled)
- {
+ if (mc.inGameHasFocus && Display.isActive()) {
+ if (!perspectiveToggled) {
return true;
}
@@ -119,7 +114,7 @@ public class PerspectiveMod {
}
public static void loadConfig(File configFile) {
- if(configFile.exists()) {
+ if (configFile.exists()) {
try {
String json = FileUtils.readFileToString(configFile);
config = gson.fromJson(json, PerspectiveModConfig.class);
@@ -140,6 +135,5 @@ public class PerspectiveMod {
} catch (Exception e) {
e.printStackTrace();
}
- };
-
+ }
}
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveModCommand.java b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveModCommand.java
index c19c81c..3eae96a 100644
--- a/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveModCommand.java
+++ b/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveModCommand.java
@@ -5,7 +5,7 @@ import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
public class PerspectiveModCommand extends CommandBase {
@@ -19,39 +19,37 @@ public class PerspectiveModCommand extends CommandBase {
@Override
public List<String> getCommandAliases() {
- List<String> aliases = new ArrayList<>();
- aliases.add("pmod");
- return aliases;
+ return Collections.singletonList("pmod");
}
@Override
public String getCommandUsage(ICommandSender sender) {
- return "§6Perspective Mod Help\n" +
- "§b/pmod <enable|disable> §7- Enables or disables the mod.\n" +
- "§b/pmod mode <hold|toggle> §7- Changes the mode.\n" +
- "§7Edit the keybind in the minecraft controls menu.";
+ return "§6Perspective Mod Help\n" +
+ "§b/pmod <enable|disable> §7- Enables or disables the mod.\n" +
+ "§b/pmod mode <hold|toggle> §7- Changes the mode.\n" +
+ "§7Edit the keybind in the minecraft controls menu.";
}
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
- if(args.length > 0 && args.length < 3) {
+ if (args.length > 0 && args.length < 3) {
String arg = args[0];
- if(arg.equalsIgnoreCase("enable")) {
+ if (arg.equalsIgnoreCase("enable")) {
PerspectiveMod.config.modEnabled = true;
sendMessage(sender, "§bMod §aEnabled§b.");
- } else if(arg.equalsIgnoreCase("disable")) {
+ } else if (arg.equalsIgnoreCase("disable")) {
PerspectiveMod.config.modEnabled = false;
sendMessage(sender, "§bMod §cDisabled§b.");
- } else if(arg.equalsIgnoreCase("mode")) {
- if(args.length == 2) {
+ } else if (arg.equalsIgnoreCase("mode")) {
+ if (args.length == 2) {
String mode = args[1];
- if(mode.equalsIgnoreCase("hold")) {
+ if (mode.equalsIgnoreCase("hold")) {
PerspectiveMod.config.holdMode = true;
sendMessage(sender, "§bMode set to hold.");
- } else if(mode.equalsIgnoreCase("toggle")) {
+ } else if (mode.equalsIgnoreCase("toggle")) {
PerspectiveMod.config.holdMode = false;
sendMessage(sender, "§bMode set to toggle.");
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java
index c54efd7..1242671 100644
--- a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java
+++ b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java
@@ -1,5 +1,6 @@
package me.djtheredstoner.perspectivemod.forge;
+import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.Mixins;
@@ -7,6 +8,7 @@ import org.spongepowered.asm.mixin.Mixins;
import java.util.Map;
// ONLY needed in development environment, the mixin tweaker handles this in prod.
+@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
public class PerspectiveModLoadingPlugin implements IFMLLoadingPlugin {
public PerspectiveModLoadingPlugin() {
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java
new file mode 100644
index 0000000..f22ba05
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java
@@ -0,0 +1,80 @@
+package me.djtheredstoner.perspectivemod.forge;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraftforge.common.ForgeVersion;
+import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
+
+import javax.swing.JOptionPane;
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+// this one will be loaded in prod, used to detect Canelex's perspective mod
+@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
+public class PerspectiveTweaker implements IFMLLoadingPlugin {
+
+ public PerspectiveTweaker() {
+ File mods = new File(Launch.minecraftHome, "mods");
+
+ if (!mods.exists()) {
+ mods.mkdirs(); // mods folder may not exist in dev yet
+ }
+
+ File[] coreModList = mods.listFiles((dir, name) -> name.endsWith(".jar"));
+ for (File file : coreModList) {
+ try {
+ try (ZipFile zipFile = new ZipFile(file)) {
+ if (zipFile.getEntry("net/canelex/perspectivemod/PerspectiveMod.class") != null) {
+ halt("<html><p>Perspective Mod v4 is not compatible with Perspective Mod v3 by Canelex. Please remove Canelex's in order to launch the game.</p></html>");
+ continue;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void halt(final String message) {
+ JOptionPane.showMessageDialog(null, message, "Launch Aborted", JOptionPane.ERROR_MESSAGE);
+ try {
+ final Class<?> aClass = Class.forName("java.lang.Shutdown");
+ final Method exit = aClass.getDeclaredMethod("exit", int.class);
+ exit.setAccessible(true);
+ exit.invoke(null, 0);
+ } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String[] getASMTransformerClass() {
+ return new String[0];
+ }
+
+ @Override
+ public String getModContainerClass() {
+ return null;
+ }
+
+ @Override
+ public String getSetupClass() {
+ return null;
+ }
+
+ @Override
+ public void injectData(Map<String, Object> map) {
+
+ }
+
+ @Override
+ public String getAccessTransformerClass() {
+ return null;
+ }
+}