mirror of
https://github.com/GTNewHorizons/MouseTweaks.git
synced 2026-10-25 20:22:36 +00:00
Swap to GTNHLib config (#5)
* Swap to GTNHLib config * Spotless apply for branch newConfig for #5 (#6) Co-authored-by: GitHub GTNH Actions <> * Update dependencies.gradle * add required dep * Fix old config detection * Remove unneeded lines in mcmod.info --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
9 files changed
+151
-117
No files matched your search
+3
-1
@@ -1 +1,3 @@
|
||||
dependencies {}
|
||||
dependencies {
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.2.0:dev")
|
||||
}
|
||||
+3
-1
@@ -1 +1,3 @@
|
||||
repositories {}
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
@@ -1,69 +1,60 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import yalter.mousetweaks.config.MTConfig;
|
||||
|
||||
public class Config {
|
||||
|
||||
private String fileName;
|
||||
private Properties properties = new Properties();
|
||||
private File file;
|
||||
|
||||
public Config(String fileName) {
|
||||
this.fileName = fileName;
|
||||
public Config(File fileName) {
|
||||
this.file = fileName;
|
||||
}
|
||||
|
||||
public boolean readConfig() {
|
||||
properties.clear();
|
||||
|
||||
public boolean hasOldConfig() {
|
||||
try {
|
||||
FileReader configReader = new FileReader(fileName);
|
||||
properties.load(configReader);
|
||||
configReader.close();
|
||||
|
||||
if (properties.size() == 0) return false;
|
||||
|
||||
return true;
|
||||
} catch (FileNotFoundException ignored) {} catch (IOException e) {
|
||||
Constants.LOGGER.error("Failed to read the config file: " + fileName, e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean saveConfig() {
|
||||
try {
|
||||
File config = new File(fileName);
|
||||
File parentDir = config.getParentFile();
|
||||
if (!parentDir.exists()) parentDir.mkdirs();
|
||||
|
||||
FileWriter configWriter = new FileWriter(config);
|
||||
properties.store(configWriter, null);
|
||||
configWriter.close();
|
||||
|
||||
return true;
|
||||
FileReader reader = new FileReader(this.file);
|
||||
Properties tempProps = new Properties();
|
||||
tempProps.load(reader);
|
||||
return !tempProps.containsKey("general");
|
||||
} catch (IOException e) {
|
||||
Constants.LOGGER.error("Failed to write the config file: " + fileName, e);
|
||||
return true; // assume yes if it failed for whatever reason
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getOrCreateProperty(String name, String defaultValue) {
|
||||
if (properties.containsKey(name)) return properties.getProperty(name);
|
||||
else properties.setProperty(name, defaultValue);
|
||||
public void importOldConfig() {
|
||||
try {
|
||||
FileReader reader = new FileReader(this.file);
|
||||
Properties tempProps = new Properties();
|
||||
tempProps.load(reader);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
if (tempProps.containsKey("RMBTweak"))
|
||||
MTConfig.RMBTweak = Objects.equals(tempProps.get("RMBTweak").toString(), "1");
|
||||
|
||||
public int getOrCreateIntProperty(String name, int defaultValue) {
|
||||
return Integer.parseInt(getOrCreateProperty(name, String.valueOf(defaultValue)));
|
||||
}
|
||||
if (tempProps.containsKey("LMBTweakWithItem"))
|
||||
MTConfig.LMBTweakWithItem = Objects.equals(tempProps.get("LMBTweakWithItem").toString(), "1");
|
||||
|
||||
public void setProperty(String name, String value) {
|
||||
properties.setProperty(name, value);
|
||||
}
|
||||
if (tempProps.containsKey("LMBTweakWithoutItem"))
|
||||
MTConfig.LMBTweakWithoutItem = Objects.equals(tempProps.get("LMBTweakWithoutItem").toString(), "1");
|
||||
|
||||
public void setIntProperty(String name, int value) {
|
||||
setProperty(name, String.valueOf(value));
|
||||
if (tempProps.containsKey("WheelTweak"))
|
||||
MTConfig.WheelTweak = Objects.equals(tempProps.get("WheelTweak").toString(), "1");
|
||||
|
||||
if (tempProps.containsKey("WheelSearchOrder"))
|
||||
MTConfig.WheelSearchOrder = Integer.parseInt(tempProps.get("WheelSearchOrder").toString());
|
||||
|
||||
if (tempProps.containsKey("WheelScrollDirection"))
|
||||
MTConfig.WheelScrollDirection = Integer.parseInt(tempProps.get("WheelScrollDirection").toString());
|
||||
|
||||
if (tempProps.containsKey("ScrollItemScaling"))
|
||||
MTConfig.ScrollItemScaling = Integer.parseInt(tempProps.get("ScrollItemScaling").toString());
|
||||
|
||||
file.renameTo(new File(file.getPath() + ".bak"));
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -11,19 +10,12 @@ import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import yalter.mousetweaks.config.MTConfig;
|
||||
|
||||
public class Main extends DeobfuscationLayer {
|
||||
|
||||
public static boolean DisableRMBTweak = false;
|
||||
|
||||
public static int RMBTweak = 0;
|
||||
public static int LMBTweakWithItem = 0;
|
||||
public static int LMBTweakWithoutItem = 0;
|
||||
public static int WheelTweak = 0;
|
||||
public static int WheelSearchOrder = 1;
|
||||
public static int WheelScrollDirection = 0;
|
||||
public static int ScrollItemScaling = 0;
|
||||
|
||||
public static Config mainConfig;
|
||||
private static GuiScreen oldGuiScreen = null;
|
||||
private static Object container = null;
|
||||
private static Slot oldSelectedSlot = null;
|
||||
@@ -35,46 +27,13 @@ public class Main extends DeobfuscationLayer {
|
||||
private static boolean disableWheelForThisContainer = false;
|
||||
private static int guiContainerID = 0;
|
||||
|
||||
private static boolean readConfig = false;
|
||||
|
||||
public static void initialise() {
|
||||
mc = Minecraft.getMinecraft();
|
||||
|
||||
mainConfig = new Config(mc.mcDataDir + File.separator + "config" + File.separator + "MouseTweaks.cfg");
|
||||
readConfigFile();
|
||||
|
||||
ModCompatibility.initialize();
|
||||
Constants.LOGGER.info("Mouse Tweaks has been initialised.");
|
||||
}
|
||||
|
||||
public static void readConfigFile() {
|
||||
boolean loadedConfig = mainConfig.readConfig();
|
||||
|
||||
RMBTweak = mainConfig.getOrCreateIntProperty("RMBTweak", 1);
|
||||
LMBTweakWithItem = mainConfig.getOrCreateIntProperty("LMBTweakWithItem", 1);
|
||||
LMBTweakWithoutItem = mainConfig.getOrCreateIntProperty("LMBTweakWithoutItem", 1);
|
||||
WheelTweak = mainConfig.getOrCreateIntProperty("WheelTweak", 1);
|
||||
WheelSearchOrder = mainConfig.getOrCreateIntProperty("WheelSearchOrder", 1);
|
||||
WheelScrollDirection = mainConfig.getOrCreateIntProperty("WheelScrollDirection", 0);
|
||||
ScrollItemScaling = mainConfig.getOrCreateIntProperty("ScrollItemScaling", 0);
|
||||
|
||||
boolean savedConfig = saveConfigFile();
|
||||
|
||||
if (savedConfig && !loadedConfig) Constants.LOGGER.info("Mouse Tweaks config file was created.");
|
||||
}
|
||||
|
||||
public static boolean saveConfigFile() {
|
||||
mainConfig.setIntProperty("RMBTweak", RMBTweak);
|
||||
mainConfig.setIntProperty("LMBTweakWithItem", LMBTweakWithItem);
|
||||
mainConfig.setIntProperty("LMBTweakWithoutItem", LMBTweakWithoutItem);
|
||||
mainConfig.setIntProperty("WheelTweak", WheelTweak);
|
||||
mainConfig.setIntProperty("WheelSearchOrder", WheelSearchOrder);
|
||||
mainConfig.setIntProperty("WheelScrollDirection", WheelScrollDirection);
|
||||
mainConfig.setIntProperty("ScrollItemScaling", ScrollItemScaling);
|
||||
|
||||
return mainConfig.saveConfig();
|
||||
}
|
||||
|
||||
public static void onUpdateInGame() {
|
||||
GuiScreen currentScreen = getCurrentScreen();
|
||||
if (currentScreen == null) {
|
||||
@@ -88,15 +47,9 @@ public class Main extends DeobfuscationLayer {
|
||||
shouldClick = true;
|
||||
disableForThisContainer = false;
|
||||
disableWheelForThisContainer = false;
|
||||
readConfig = true;
|
||||
|
||||
guiContainerID = Constants.NOTASSIGNED;
|
||||
} else {
|
||||
if (readConfig) {
|
||||
readConfig = false;
|
||||
readConfigFile();
|
||||
}
|
||||
|
||||
if (guiContainerID == Constants.NOTASSIGNED) {
|
||||
guiContainerID = getGuiContainerID(currentScreen);
|
||||
}
|
||||
@@ -133,9 +86,9 @@ public class Main extends DeobfuscationLayer {
|
||||
|
||||
if (guiContainerID == Constants.NOTGUICONTAINER) return;
|
||||
|
||||
if ((Main.DisableRMBTweak || (Main.RMBTweak == 0)) && (Main.LMBTweakWithoutItem == 0)
|
||||
&& (Main.LMBTweakWithItem == 0)
|
||||
&& (Main.WheelTweak == 0))
|
||||
if ((Main.DisableRMBTweak || (!MTConfig.RMBTweak)) && (!MTConfig.LMBTweakWithoutItem)
|
||||
&& (!MTConfig.LMBTweakWithItem)
|
||||
&& (!MTConfig.WheelTweak))
|
||||
return;
|
||||
|
||||
if (disableForThisContainer) return;
|
||||
@@ -147,7 +100,7 @@ public class Main extends DeobfuscationLayer {
|
||||
if (slotCount == 0) // If there are no slots, then there is nothing to do.
|
||||
return;
|
||||
|
||||
int wheel = ((Main.WheelTweak == 1) && !disableWheelForThisContainer) ? Mouse.getDWheel() : 0;
|
||||
int wheel = ((MTConfig.WheelTweak) && !disableWheelForThisContainer) ? Mouse.getDWheel() : 0;
|
||||
|
||||
if (!Mouse.isButtonDown(1)) {
|
||||
firstSlotClicked = false;
|
||||
@@ -202,7 +155,7 @@ public class Main extends DeobfuscationLayer {
|
||||
boolean shiftIsDown = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
|
||||
if (Mouse.isButtonDown(1)) { // Right mouse button
|
||||
if ((Main.RMBTweak == 1) && !Main.DisableRMBTweak) {
|
||||
if ((MTConfig.RMBTweak) && !Main.DisableRMBTweak) {
|
||||
|
||||
if ((stackOnMouse != null) && areStacksCompatible(stackOnMouse, targetStack)
|
||||
&& !isCraftingOutputSlot(currentScreen, selectedSlot)) {
|
||||
@@ -220,7 +173,7 @@ public class Main extends DeobfuscationLayer {
|
||||
}
|
||||
} else if (Mouse.isButtonDown(0)) { // Left mouse button
|
||||
if (stackOnMouse != null) {
|
||||
if (Main.LMBTweakWithItem == 1) {
|
||||
if (MTConfig.LMBTweakWithItem) {
|
||||
if ((targetStack != null) && areStacksCompatible(stackOnMouse, targetStack)) {
|
||||
|
||||
if (shiftIsDown) { // If shift is down, we just shift-click the slot and the item gets moved
|
||||
@@ -242,7 +195,7 @@ public class Main extends DeobfuscationLayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (Main.LMBTweakWithoutItem == 1) {
|
||||
} else if (MTConfig.LMBTweakWithoutItem) {
|
||||
if (targetStack != null) {
|
||||
if (shiftIsDown) {
|
||||
clickSlot(currentScreen, selectedSlot, 0, true);
|
||||
@@ -256,7 +209,7 @@ public class Main extends DeobfuscationLayer {
|
||||
|
||||
if ((wheel != 0) && (selectedSlot != null)) {
|
||||
int numItemsToMove;
|
||||
if (!ModCompatibility.isLwjgl3Loaded() && ScrollItemScaling == 0) {
|
||||
if (!ModCompatibility.isLwjgl3Loaded() && MTConfig.ScrollItemScaling == 0) {
|
||||
numItemsToMove = Math.abs(wheel) / 120;
|
||||
} else {
|
||||
numItemsToMove = 1;
|
||||
@@ -277,11 +230,11 @@ public class Main extends DeobfuscationLayer {
|
||||
Slot applicableSlot = null;
|
||||
|
||||
boolean pushItems = (wheel < 0);
|
||||
if ((WheelScrollDirection == 2 || WheelScrollDirection == 3)
|
||||
if ((MTConfig.WheelScrollDirection == 2 || MTConfig.WheelScrollDirection == 3)
|
||||
&& otherInventoryIsAbove(selectedSlot, getSlots(asContainer(container)))) {
|
||||
pushItems = !pushItems;
|
||||
}
|
||||
if (WheelScrollDirection == 1 || WheelScrollDirection == 3) {
|
||||
if (MTConfig.WheelScrollDirection == 1 || MTConfig.WheelScrollDirection == 3) {
|
||||
pushItems = !pushItems;
|
||||
}
|
||||
|
||||
@@ -292,7 +245,7 @@ public class Main extends DeobfuscationLayer {
|
||||
countUntil = slotCount;
|
||||
}
|
||||
|
||||
if (pushItems || (Main.WheelSearchOrder == 0)) {
|
||||
if (pushItems || (MTConfig.WheelSearchOrder == 0)) {
|
||||
for (int i = slotCounter; i < countUntil; i++) {
|
||||
Slot sl = getSlotWithID(currentScreen, i);
|
||||
ItemStack stackSl = getSlotStack(sl);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package yalter.mousetweaks.config;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.config.Config;
|
||||
|
||||
import yalter.mousetweaks.Constants;
|
||||
|
||||
@Config(modid = Constants.MOD_ID)
|
||||
public class MTConfig {
|
||||
|
||||
@Config.Comment("Very similar to the standard RMB dragging mechanic, with one difference: if you drag over a slot multiple times, an item will be put there multiple times. Replaces the standard mechanic if enabled.")
|
||||
public static boolean RMBTweak = false;
|
||||
|
||||
@Config.Comment("Lets you quickly pick up or move items of the same type")
|
||||
public static boolean LMBTweakWithItem = true;
|
||||
|
||||
@Config.Comment("Quickly move items into another inventory")
|
||||
public static boolean LMBTweakWithoutItem = true;
|
||||
|
||||
@Config.Comment("Scroll to quickly move items between inventories")
|
||||
public static boolean WheelTweak = true;
|
||||
|
||||
@Config.Comment("Wheel Inventory Slot Search Order\n" + "0 - First to Last\n" + "1 - Last To First")
|
||||
@Config.RangeInt(min = 0, max = 1)
|
||||
public static int WheelSearchOrder = 1;
|
||||
|
||||
@Config.Comment("Wheel Scroll Direction\n" + "0 - Down to Push, Up to Pull\n"
|
||||
+ "1 - Up to Push, Down to Pull\n"
|
||||
+ "2 - Inventory Position Aware\n"
|
||||
+ "3 - Inventory Position Aware, Inverted\n")
|
||||
@Config.RangeInt(min = 0, max = 3)
|
||||
public static int WheelScrollDirection = 0;
|
||||
|
||||
@Config.Comment("Scroll Scaling\n" + "0 - Multiple Wheel Clicks Move Multiple Items\n"
|
||||
+ "1 - Always Move One Item (macOS Compatibility)")
|
||||
@Config.RangeInt(min = 0, max = 1)
|
||||
public static int ScrollItemScaling = 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package yalter.mousetweaks.config;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.config.ConfigException;
|
||||
import com.gtnewhorizon.gtnhlib.config.SimpleGuiConfig;
|
||||
|
||||
import yalter.mousetweaks.Constants;
|
||||
|
||||
public class MTGuiConfig extends SimpleGuiConfig {
|
||||
|
||||
public MTGuiConfig(GuiScreen parent) throws ConfigException {
|
||||
super(parent, MTConfig.class, Constants.MOD_ID, Constants.MOD_NAME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package yalter.mousetweaks.config;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.config.SimpleGuiFactory;
|
||||
|
||||
public class MTGuiConfigFactory implements SimpleGuiFactory {
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return MTGuiConfig.class;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,48 @@
|
||||
package yalter.mousetweaks.loaders;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.config.ConfigException;
|
||||
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import yalter.mousetweaks.Config;
|
||||
import yalter.mousetweaks.Constants;
|
||||
import yalter.mousetweaks.Main;
|
||||
import yalter.mousetweaks.config.MTConfig;
|
||||
|
||||
@Mod(
|
||||
modid = Constants.MOD_ID,
|
||||
name = Constants.MOD_NAME,
|
||||
version = Constants.MOD_VERSION,
|
||||
guiFactory = "yalter.mousetweaks.config.MTGuiConfigFactory",
|
||||
dependencies = "required-after:gtnhlib@[0.2.0,);",
|
||||
acceptedMinecraftVersions = "[1.7.10]",
|
||||
acceptableRemoteVersions = "*")
|
||||
public class MouseTweaksForge {
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preinit(FMLPreInitializationEvent event) {
|
||||
if (event.getSide().isClient()) {
|
||||
try {
|
||||
Config oldConfig = new Config(event.getSuggestedConfigurationFile());
|
||||
if (oldConfig.hasOldConfig()) {
|
||||
oldConfig.importOldConfig();
|
||||
}
|
||||
ConfigurationManager.registerConfig(MTConfig.class);
|
||||
ConfigurationManager.registerBus();
|
||||
} catch (ConfigException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
if (FMLCommonHandler.instance().getSide().isClient()) {
|
||||
if (event.getSide().isClient()) {
|
||||
Main.initialise();
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,6 @@
|
||||
"credits": "Various open-source mods from where I learned.",
|
||||
"logoFile": "mousetweaks_logo.png",
|
||||
"screenshots": [],
|
||||
"parent": "",
|
||||
"requiredMods": [],
|
||||
"dependencies": [],
|
||||
"dependants": [],
|
||||
"useDependencyInformation": true
|
||||
"parent": ""
|
||||
}]
|
||||
}
|
||||
Reference in new issue
Block a user