mirror of
https://github.com/GTNewHorizons/MouseTweaks.git
synced 2026-11-20 12:09:37 +00:00
Now using MCP + LiteLoader build system, clean up, remade Config, remade the initialisation and whatnot, reformat, fixed LiteLoader compatibility.
This commit is contained in:
1 parent
8abfb6e2c3
commit
a204c82ea5
34 files changed
+2166
-2391
No files matched your search
@@ -0,0 +1,73 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Config {
|
||||
private String fileName;
|
||||
private Properties properties = new Properties();
|
||||
|
||||
public Config(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public boolean readConfig() {
|
||||
properties.clear();
|
||||
|
||||
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) {
|
||||
Logger.Log("Failed to read the config file: " + fileName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean saveConfig() {
|
||||
try {
|
||||
FileWriter configWriter = new FileWriter(fileName);
|
||||
properties.store(configWriter, null);
|
||||
configWriter.close();
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Logger.Log("Failed to write the config file: " + fileName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getOrCreateProperty(String name, String defaultValue) {
|
||||
if (properties.containsKey(name))
|
||||
return properties.getProperty(name);
|
||||
else
|
||||
properties.setProperty(name, defaultValue);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public int getOrCreateIntProperty(String name, int defaultValue) {
|
||||
return Integer.parseInt(getOrCreateProperty(name, String.valueOf(defaultValue)));
|
||||
}
|
||||
|
||||
public void setProperty(String name, String value) {
|
||||
properties.setProperty(name, value);
|
||||
}
|
||||
|
||||
public void setIntProperty(String name, int value) {
|
||||
setProperty(name, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
public class Constants {
|
||||
public static final String MOD_NAME = "@MODNAME@";
|
||||
public static final String MOD_ID = "@MODID@";
|
||||
public static final String MOD_VERSION = "@VERSION@";
|
||||
|
||||
// Obfuscated names
|
||||
public static final String ISMOUSEOVERSLOT_NAME = "a";
|
||||
public static final String FIELDE_NAME = "H";
|
||||
public static final String FIELDq_NAME = "t";
|
||||
public static final String MCPROFILER_NAME = "A";
|
||||
|
||||
// Forge obfuscated names
|
||||
public static final String ISMOUSEOVERSLOT_FORGE_NAME = "func_146981_a";
|
||||
public static final String FIELDE_FORGE_NAME = "field_146995_H";
|
||||
public static final String FIELDq_FORGE_NAME = "field_147007_t";
|
||||
public static final String MCPROFILER_FORGE_NAME = "field_71424_I";
|
||||
|
||||
// MCP names - these are the same as Forge ones for the most part
|
||||
public static final String MCPROFILER_MCP_NAME = "mcProfiler";
|
||||
|
||||
// OnTick methods
|
||||
public static final String ONTICKMETHOD_FORGE_NAME = "Forge";
|
||||
public static final String ONTICKMETHOD_LITELOADER_NAME = "LiteLoader";
|
||||
public static final String ONTICKMETHOD_PROFILER_NAME = "Minecraft";
|
||||
|
||||
// Inventory-related stuff
|
||||
public static final int INVENTORY_SIZE = 36; // Size of the player inventory
|
||||
|
||||
// Mod GUI container IDs
|
||||
public static final int NOTASSIGNED = -1; // When we haven't determined it yet.
|
||||
public static final int NOTGUICONTAINER = 0; // This is not a container GUI.
|
||||
public static final int MINECRAFT = 1; // Containers that should be compatible with vanilla Minecraft ones.
|
||||
public static final int MTMODGUICONTAINER = 2; // Containers that implement the IMTModGuiContainer interface.
|
||||
public static final int FORESTRY = 3; // Forestry containers.
|
||||
public static final int CODECHICKENCORE = 4; // CodeChickenCore containers.
|
||||
public static final int NEI = 5; // NotEnoughItems containers (like the crafting menu).
|
||||
|
||||
public enum EntryPoint {
|
||||
UNDEFINED,
|
||||
FORGE,
|
||||
LITELOADER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.*;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeobfuscationLayer {
|
||||
|
||||
protected static Minecraft mc;
|
||||
|
||||
protected static GuiScreen getCurrentScreen() {
|
||||
return mc.currentScreen;
|
||||
}
|
||||
|
||||
protected static boolean isGuiContainer(GuiScreen guiScreen) {
|
||||
return (guiScreen != null) && (guiScreen instanceof GuiContainer);
|
||||
}
|
||||
|
||||
protected static boolean isValidGuiContainer(GuiScreen guiScreen) {
|
||||
return (guiScreen != null)
|
||||
&& !(guiScreen.getClass().getSimpleName().contains("CJB_GuiCrafting"))
|
||||
&& !(guiScreen.getClass().equals(GuiContainerCreative.class));
|
||||
}
|
||||
|
||||
protected static boolean isVanillaCraftingOutputSlot(Container container, Slot slot) {
|
||||
return ((container instanceof ContainerWorkbench) && (getSlotNumber(slot) == 0))
|
||||
|| ((container instanceof ContainerPlayer) && (getSlotNumber(slot) == 0))
|
||||
|| ((container instanceof ContainerFurnace) && (getSlotNumber(slot) == 2))
|
||||
|| ((container instanceof ContainerRepair) && (getSlotNumber(slot) == 2));
|
||||
}
|
||||
|
||||
protected static GuiContainer asGuiContainer(GuiScreen guiScreen) {
|
||||
return (GuiContainer) guiScreen;
|
||||
}
|
||||
|
||||
protected static Container asContainer(Object obj) {
|
||||
return (Container) obj;
|
||||
}
|
||||
|
||||
protected static Slot asSlot(Object obj) {
|
||||
return (Slot) obj;
|
||||
}
|
||||
|
||||
protected static Container getContainer(GuiContainer guiContainer) {
|
||||
return guiContainer.field_147002_h;
|
||||
}
|
||||
|
||||
protected static List<?> getSlots(Container container) {
|
||||
return container.inventorySlots;
|
||||
}
|
||||
|
||||
protected static Slot getSlot(Container container, int index) {
|
||||
return (Slot) (getSlots(container).get(index));
|
||||
}
|
||||
|
||||
protected static ItemStack getSlotStack(Slot slot) {
|
||||
return (slot == null) ? null : slot.getStack();
|
||||
}
|
||||
|
||||
protected static int getItemStackID(ItemStack itemStack) {
|
||||
return Item.getIdFromItem(itemStack.getItem());
|
||||
}
|
||||
|
||||
protected static boolean hasSubtypesItemStack(ItemStack itemStack) {
|
||||
return itemStack.getHasSubtypes();
|
||||
}
|
||||
|
||||
protected static int getItemStackItemDamage(ItemStack itemStack) {
|
||||
return itemStack.getItemDamage();
|
||||
}
|
||||
|
||||
protected static int getWindowId(Container container) {
|
||||
return container.windowId;
|
||||
}
|
||||
|
||||
protected static void windowClick(int windowId, int slotNumber, int mouseButton,
|
||||
int shiftPressed) {
|
||||
// if (slotNumber != -1) {
|
||||
getPlayerController().windowClick(windowId, slotNumber, mouseButton, shiftPressed,
|
||||
getThePlayer());
|
||||
// }
|
||||
}
|
||||
|
||||
protected static EntityClientPlayerMP getThePlayer() {
|
||||
return mc.thePlayer;
|
||||
}
|
||||
|
||||
protected static InventoryPlayer getInventoryPlayer() {
|
||||
return getThePlayer().inventory;
|
||||
}
|
||||
|
||||
protected static GameSettings getGameSettings() {
|
||||
return mc.gameSettings;
|
||||
}
|
||||
|
||||
protected static int getDisplayWidth() {
|
||||
return mc.displayWidth;
|
||||
}
|
||||
|
||||
protected static int getDisplayHeight() {
|
||||
return mc.displayHeight;
|
||||
}
|
||||
|
||||
protected static ItemStack getStackOnMouse() {
|
||||
return getInventoryPlayer().getItemStack();
|
||||
}
|
||||
|
||||
protected static PlayerControllerMP getPlayerController() {
|
||||
return mc.playerController;
|
||||
}
|
||||
|
||||
protected static int getSlotNumber(Slot slot) {
|
||||
return slot.slotNumber;
|
||||
}
|
||||
|
||||
protected static int getItemStackSize(ItemStack itemStack) {
|
||||
return itemStack.stackSize;
|
||||
}
|
||||
|
||||
protected static int getMaxItemStackSize(ItemStack itemStack) {
|
||||
return itemStack.getMaxStackSize();
|
||||
}
|
||||
|
||||
protected static ItemStack copyItemStack(ItemStack itemStack) {
|
||||
return (itemStack == null) ? null : itemStack.copy();
|
||||
}
|
||||
|
||||
protected static boolean areStacksCompatible(ItemStack itemStack1, ItemStack itemStack2) {
|
||||
return ((itemStack1 == null) || (itemStack2 == null))
|
||||
|| ((getItemStackID(itemStack1) == getItemStackID(itemStack2))
|
||||
&& (!hasSubtypesItemStack(itemStack1)
|
||||
|| (getItemStackItemDamage(itemStack1) == getItemStackItemDamage(itemStack2))));
|
||||
}
|
||||
|
||||
protected static boolean isMouseOverSlot(GuiContainer guiContainer, Slot slot) {
|
||||
return (Boolean) Reflection.guiContainerClass.invokeMethod(guiContainer, "isMouseOverSlot", slot, getRequiredMouseX(), getRequiredMouseY());
|
||||
}
|
||||
|
||||
protected static Slot getSelectedSlot(GuiContainer guiContainer, Container container, int slotCount) {
|
||||
for (int i = 0; i < slotCount; i++) {
|
||||
Slot slot = getSlot(container, i);
|
||||
if (isMouseOverSlot(guiContainer, slot))
|
||||
return slot;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the vanilla RMB drag mechanic in the given GuiContainer. If your guiContainer is based on the vanilla GuiContainer, you can use this method to disable the RMB drag.
|
||||
*
|
||||
* @param guiContainer The guiContainer to disable RMB drag in.
|
||||
*/
|
||||
public static void disableVanillaRMBDrag(GuiContainer guiContainer) {
|
||||
Reflection.guiContainerClass.setFieldValue(guiContainer, Constants.FIELDE_FORGE_NAME, true);
|
||||
Reflection.guiContainerClass.setFieldValue(guiContainer, Constants.FIELDq_FORGE_NAME, false);
|
||||
}
|
||||
|
||||
protected static int getRequiredMouseX() {
|
||||
ScaledResolution var8 = new ScaledResolution(getGameSettings(), getDisplayWidth(),
|
||||
getDisplayHeight());
|
||||
int var9 = var8.getScaledWidth();
|
||||
return (Mouse.getX() * var9) / getDisplayWidth();
|
||||
}
|
||||
|
||||
protected static int getRequiredMouseY() {
|
||||
ScaledResolution var8 = new ScaledResolution(getGameSettings(), getDisplayWidth(),
|
||||
getDisplayHeight());
|
||||
int var10 = var8.getScaledHeight();
|
||||
return var10 - ((Mouse.getY() * var10) / getDisplayHeight()) - 1;
|
||||
}
|
||||
|
||||
protected static void sendClientMessage(String message) {
|
||||
getThePlayer().sendChatMessage(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
public class Logger {
|
||||
|
||||
public static void Log(String textToLog) {
|
||||
System.out.println("[Mouse Tweaks] " + textToLog);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,621 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main extends DeobfuscationLayer {
|
||||
|
||||
public static boolean liteLoader = false;
|
||||
public static boolean minecraftForge = false;
|
||||
public static boolean optifine = false;
|
||||
|
||||
public static boolean useForge = false;
|
||||
public static boolean useLiteLoader = false;
|
||||
public static boolean useProfiler = false;
|
||||
|
||||
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 enum OnTickMethod {PROFILER, FORGE, LITELOADER}
|
||||
public static List<OnTickMethod> onTickMethodOrder = new LinkedList<OnTickMethod>();
|
||||
|
||||
public static int Debug = 0;
|
||||
|
||||
public static Config mainConfig;
|
||||
private static GuiScreen oldGuiScreen = null;
|
||||
private static Object container = null;
|
||||
private static Slot oldSelectedSlot = null;
|
||||
private static Slot firstSlot = null;
|
||||
private static ItemStack oldStackOnMouse = null;
|
||||
private static boolean firstSlotClicked = false;
|
||||
private static boolean shouldClick = true;
|
||||
private static boolean disableForThisContainer = false;
|
||||
private static boolean disableWheelForThisContainer = false;
|
||||
private static int guiContainerID = 0;
|
||||
|
||||
private static boolean readConfig = false;
|
||||
private static boolean initialised = false;
|
||||
private static boolean disabled = false;
|
||||
|
||||
public static boolean initialise() {
|
||||
return initialise(Constants.EntryPoint.UNDEFINED);
|
||||
}
|
||||
|
||||
public static boolean initialise(Constants.EntryPoint entryPoint) {
|
||||
Logger.Log("A call to initialise, entry point: " + entryPoint.toString() + ".");
|
||||
|
||||
if (disabled)
|
||||
return false;
|
||||
|
||||
if (initialised)
|
||||
return true;
|
||||
|
||||
initialised = true;
|
||||
|
||||
if (!Reflection.reflectGuiContainer()) {
|
||||
disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
mc = Minecraft.getMinecraft();
|
||||
|
||||
mainConfig = new Config(mc.mcDataDir + File.separator + "config" + File.separator + "MouseTweaks.cfg");
|
||||
readConfigFile();
|
||||
|
||||
minecraftForge = Reflection.doesClassExist("net.minecraftforge.client.MinecraftForgeClient");
|
||||
if (minecraftForge) {
|
||||
Logger.Log("Minecraft Forge is installed.");
|
||||
} else {
|
||||
Logger.Log("Minecraft Forge is not installed.");
|
||||
}
|
||||
|
||||
liteLoader = ((entryPoint == Constants.EntryPoint.LITELOADER) // If we're initialising from LiteModMouseTweaks, the check is not necessary.
|
||||
|| Reflection.doesClassExist("com.mumfrey.liteloader.core.LiteLoader"));
|
||||
if (liteLoader) {
|
||||
Logger.Log("LiteLoader is installed.");
|
||||
} else {
|
||||
Logger.Log("LiteLoader is not installed.");
|
||||
}
|
||||
|
||||
// Find the first suitable OnTick method.
|
||||
methodLoop:
|
||||
for (OnTickMethod method : onTickMethodOrder) {
|
||||
switch (method) {
|
||||
case FORGE:
|
||||
if (minecraftForge) {
|
||||
useForge = true;
|
||||
Logger.Log("Using Forge for the mod operation.");
|
||||
break methodLoop;
|
||||
}
|
||||
break;
|
||||
|
||||
case LITELOADER:
|
||||
if (liteLoader) {
|
||||
useLiteLoader = ((entryPoint == Constants.EntryPoint.LITELOADER)
|
||||
|| Reflection.registerLiteModListenerInLiteLoader());
|
||||
if (useLiteLoader) {
|
||||
Logger.Log("Using LiteLoader for the mod operation.");
|
||||
break methodLoop;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case PROFILER:
|
||||
if (Reflection.replaceProfiler()) {
|
||||
useProfiler = true;
|
||||
Logger.Log("Using the Minecraft profiler for the mod operation.");
|
||||
|
||||
optifine = Reflection.reflectOptifine();
|
||||
|
||||
break methodLoop;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!useForge && !useLiteLoader && !useProfiler) {
|
||||
// Nothing worked at all.
|
||||
disabled = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
ModCompatibility.initialize();
|
||||
Logger.Log("Mouse Tweaks has been initialised.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
Debug = mainConfig.getOrCreateIntProperty("Debug", 0);
|
||||
|
||||
// Load the OnTick method order.
|
||||
String onTickMethodString = mainConfig.getOrCreateProperty("OnTickMethodOrder",
|
||||
Constants.ONTICKMETHOD_FORGE_NAME + ", "
|
||||
+ Constants.ONTICKMETHOD_LITELOADER_NAME + ", "
|
||||
+ Constants.ONTICKMETHOD_PROFILER_NAME);
|
||||
|
||||
onTickMethodString = onTickMethodString.trim();
|
||||
String onTickMethods[] = onTickMethodString.split("[\\s]*,[\\s]*");
|
||||
for (String method : onTickMethods) {
|
||||
if (Constants.ONTICKMETHOD_FORGE_NAME.equalsIgnoreCase(method) && !onTickMethodOrder.contains(OnTickMethod.FORGE))
|
||||
onTickMethodOrder.add(OnTickMethod.FORGE);
|
||||
else if (Constants.ONTICKMETHOD_LITELOADER_NAME.equalsIgnoreCase(method) && !onTickMethodOrder.contains(OnTickMethod.LITELOADER))
|
||||
onTickMethodOrder.add(OnTickMethod.LITELOADER);
|
||||
else if (Constants.ONTICKMETHOD_PROFILER_NAME.equalsIgnoreCase(method) && !onTickMethodOrder.contains(OnTickMethod.PROFILER))
|
||||
onTickMethodOrder.add(OnTickMethod.PROFILER);
|
||||
}
|
||||
|
||||
// Make sure we have one of each.
|
||||
if (!onTickMethodOrder.contains(OnTickMethod.FORGE))
|
||||
onTickMethodOrder.add(OnTickMethod.FORGE);
|
||||
if (!onTickMethodOrder.contains(OnTickMethod.LITELOADER))
|
||||
onTickMethodOrder.add(OnTickMethod.LITELOADER);
|
||||
if (!onTickMethodOrder.contains(OnTickMethod.PROFILER))
|
||||
onTickMethodOrder.add(OnTickMethod.PROFILER);
|
||||
|
||||
boolean savedConfig = saveConfigFile();
|
||||
|
||||
if (savedConfig && !loadedConfig)
|
||||
Logger.Log("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("Debug", Debug);
|
||||
|
||||
String onTickMethodString = "";
|
||||
for (OnTickMethod method : onTickMethodOrder) {
|
||||
if (!onTickMethodString.isEmpty())
|
||||
onTickMethodString += ", ";
|
||||
|
||||
switch (method) {
|
||||
case FORGE:
|
||||
onTickMethodString += Constants.ONTICKMETHOD_FORGE_NAME;
|
||||
break;
|
||||
|
||||
case LITELOADER:
|
||||
onTickMethodString += Constants.ONTICKMETHOD_LITELOADER_NAME;
|
||||
break;
|
||||
|
||||
case PROFILER:
|
||||
onTickMethodString += Constants.ONTICKMETHOD_PROFILER_NAME;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mainConfig.setProperty("OnTickMethodOrder", onTickMethodString);
|
||||
|
||||
return mainConfig.saveConfig();
|
||||
}
|
||||
|
||||
public static void onUpdateInGame() {
|
||||
GuiScreen currentScreen = getCurrentScreen();
|
||||
if (currentScreen == null) {
|
||||
// Reset stuff
|
||||
oldGuiScreen = null;
|
||||
container = null;
|
||||
oldSelectedSlot = null;
|
||||
firstSlot = null;
|
||||
oldStackOnMouse = null;
|
||||
firstSlotClicked = false;
|
||||
shouldClick = true;
|
||||
disableForThisContainer = false;
|
||||
disableWheelForThisContainer = false;
|
||||
readConfig = true;
|
||||
|
||||
guiContainerID = Constants.NOTASSIGNED;
|
||||
} else {
|
||||
if (readConfig) {
|
||||
readConfig = false;
|
||||
readConfigFile();
|
||||
}
|
||||
|
||||
if (guiContainerID == Constants.NOTASSIGNED) {
|
||||
guiContainerID = getGuiContainerID(currentScreen);
|
||||
}
|
||||
|
||||
onUpdateInGui(currentScreen);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onUpdateInGui(GuiScreen currentScreen) {
|
||||
|
||||
if (oldGuiScreen != currentScreen) {
|
||||
oldGuiScreen = currentScreen;
|
||||
|
||||
// If we opened an inventory from another inventory (for example, NEI's options menu).
|
||||
guiContainerID = getGuiContainerID(currentScreen);
|
||||
if (guiContainerID == Constants.NOTGUICONTAINER)
|
||||
return;
|
||||
|
||||
container = getContainerWithID(currentScreen);
|
||||
disableForThisContainer = isDisabledForThisContainer(currentScreen);
|
||||
|
||||
if (Debug == 1) {
|
||||
Logger.Log(new StringBuilder().append("You have just opened a ").append(getGuiContainerNameFromID(currentScreen)).append(" container (").append(currentScreen.getClass().getSimpleName()).append((container == null) ? "" : "; ").append((container == null) ? "" : container.getClass().getSimpleName()).append("), which has ").append(getSlotCountWithID(currentScreen)).append(" slots!").toString());
|
||||
}
|
||||
|
||||
disableWheelForThisContainer = isWheelDisabledForThisContainer(currentScreen);
|
||||
}
|
||||
|
||||
if (guiContainerID == Constants.NOTGUICONTAINER)
|
||||
return;
|
||||
|
||||
if ((Main.DisableRMBTweak || (Main.RMBTweak == 0)) && (Main.LMBTweakWithoutItem == 0) && (Main.LMBTweakWithItem == 0)
|
||||
&& (Main.WheelTweak == 0))
|
||||
return;
|
||||
|
||||
if (disableForThisContainer)
|
||||
return;
|
||||
|
||||
int slotCount = getSlotCountWithID(currentScreen); // It's better to have this here, because there are some inventories that change slot count during
|
||||
// runtime (for example NEI's crafting recipe GUI).
|
||||
if (slotCount == 0) // If there are no slots, then there is nothing to do.
|
||||
return;
|
||||
|
||||
int wheel = ((Main.WheelTweak == 1) && !disableWheelForThisContainer) ? Mouse.getDWheel() / 120 : 0;
|
||||
|
||||
if (!Mouse.isButtonDown(1)) {
|
||||
firstSlotClicked = false;
|
||||
firstSlot = null;
|
||||
shouldClick = true;
|
||||
}
|
||||
|
||||
Slot selectedSlot = getSelectedSlotWithID(currentScreen, slotCount);
|
||||
|
||||
// Copy the stacks, so that they don't change while we do our stuff.
|
||||
ItemStack stackOnMouse = copyItemStack(getStackOnMouse());
|
||||
ItemStack targetStack = copyItemStack(getSlotStack(selectedSlot));
|
||||
|
||||
// To correctly determine, when and how the default RMB drag needs to be disabled, we need a bunch of conditions...
|
||||
if (Mouse.isButtonDown(1) && (oldStackOnMouse != stackOnMouse) && (oldStackOnMouse == null)) {
|
||||
shouldClick = false;
|
||||
}
|
||||
|
||||
if (oldSelectedSlot != selectedSlot) {
|
||||
// ...and some more conditions.
|
||||
if (Mouse.isButtonDown(1) && !firstSlotClicked && (firstSlot == null) && (oldSelectedSlot != null)) {
|
||||
if (!areStacksCompatible(stackOnMouse, getSlotStack(oldSelectedSlot))) {
|
||||
shouldClick = false;
|
||||
}
|
||||
|
||||
firstSlot = oldSelectedSlot;
|
||||
}
|
||||
|
||||
if (Mouse.isButtonDown(1) && (oldSelectedSlot == null) && !firstSlotClicked && (firstSlot == null)) {
|
||||
shouldClick = false;
|
||||
}
|
||||
|
||||
if (selectedSlot == null) {
|
||||
oldSelectedSlot = selectedSlot;
|
||||
|
||||
if ((firstSlot != null) && !firstSlotClicked) {
|
||||
firstSlotClicked = true;
|
||||
disableRMBDragWithID(currentScreen);
|
||||
firstSlot = null;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Debug == 1) {
|
||||
Logger.Log(new StringBuilder().append("You have selected a new slot, it's slot number is ").append(getSlotNumber(selectedSlot)).toString());
|
||||
}
|
||||
|
||||
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 ((stackOnMouse != null) && areStacksCompatible(stackOnMouse, targetStack)) {
|
||||
if ((firstSlot != null) && !firstSlotClicked) {
|
||||
firstSlotClicked = true;
|
||||
disableRMBDragWithID(currentScreen);
|
||||
firstSlot = null;
|
||||
} else {
|
||||
shouldClick = false;
|
||||
disableRMBDragWithID(currentScreen);
|
||||
}
|
||||
|
||||
clickSlot(currentScreen, selectedSlot, 1, false);
|
||||
}
|
||||
|
||||
}
|
||||
} else if (Mouse.isButtonDown(0)) { // Left mouse button
|
||||
if (stackOnMouse != null) {
|
||||
if (Main.LMBTweakWithItem == 1) {
|
||||
if ((targetStack != null) && areStacksCompatible(stackOnMouse, targetStack)) {
|
||||
|
||||
if (shiftIsDown) { // If shift is down, we just shift-click the slot and the item gets moved into another inventory.
|
||||
clickSlot(currentScreen, selectedSlot, 0, true);
|
||||
} else { // If shift is not down, we need to merge the item stack on the mouse with the one in the slot.
|
||||
if ((getItemStackSize(stackOnMouse) + getItemStackSize(targetStack)) <= getMaxItemStackSize(stackOnMouse)) {
|
||||
clickSlot(currentScreen, selectedSlot, 0, false); // We need to click on the slot so that our item stack gets merged with
|
||||
clickSlot(currentScreen, selectedSlot, 0, false); // it, and then click again to return the stack to the mouse.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else if (Main.LMBTweakWithoutItem == 1) {
|
||||
if (targetStack != null) {
|
||||
if (shiftIsDown) {
|
||||
clickSlot(currentScreen, selectedSlot, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldSelectedSlot = selectedSlot;
|
||||
}
|
||||
|
||||
if ((wheel != 0) && (selectedSlot != null)) {
|
||||
int numItemsToMove = Math.abs(wheel);
|
||||
if (Debug == 1) {
|
||||
Logger.Log("numItemsToMove: " + numItemsToMove);
|
||||
}
|
||||
|
||||
if (slotCount > Constants.INVENTORY_SIZE) {
|
||||
ItemStack originalStack = getSlotStack(selectedSlot);
|
||||
boolean isCraftingOutput = isCraftingOutputSlot(currentScreen, selectedSlot);
|
||||
|
||||
if ((originalStack != null)
|
||||
&& ((stackOnMouse == null) || (isCraftingOutput ? areStacksCompatible(originalStack, stackOnMouse) : !areStacksCompatible(originalStack, stackOnMouse)))) {
|
||||
do {
|
||||
Slot applicableSlot = null;
|
||||
|
||||
int slotCounter = 0;
|
||||
int countUntil = slotCount
|
||||
- Constants.INVENTORY_SIZE;
|
||||
if (getSlotNumber(selectedSlot) < countUntil) {
|
||||
slotCounter = countUntil;
|
||||
countUntil = slotCount;
|
||||
}
|
||||
|
||||
if ((wheel < 0) || (Main.WheelSearchOrder == 0)) {
|
||||
for (int i = slotCounter; i < countUntil; i++) {
|
||||
Slot sl = getSlotWithID(currentScreen, i);
|
||||
ItemStack stackSl = getSlotStack(sl);
|
||||
|
||||
if (stackSl == null) {
|
||||
if ((applicableSlot == null)
|
||||
&& (wheel < 0)
|
||||
&& sl.isItemValid(originalStack)
|
||||
&& !isCraftingOutputSlot(currentScreen, sl)) {
|
||||
applicableSlot = sl;
|
||||
}
|
||||
} else if (areStacksCompatible(originalStack, stackSl)) {
|
||||
if ((wheel < 0)
|
||||
&& (stackSl.stackSize < stackSl.getMaxStackSize())) {
|
||||
applicableSlot = sl;
|
||||
break;
|
||||
} else if (wheel > 0) {
|
||||
applicableSlot = sl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = countUntil - 1; i >= slotCounter; i--) {
|
||||
Slot sl = getSlotWithID(currentScreen, i);
|
||||
ItemStack stackSl = getSlotStack(sl);
|
||||
|
||||
if (stackSl == null) {
|
||||
if ((applicableSlot == null)
|
||||
&& (wheel < 0)
|
||||
&& sl.isItemValid(originalStack)) {
|
||||
applicableSlot = sl;
|
||||
}
|
||||
} else if (areStacksCompatible(originalStack, stackSl)) {
|
||||
if ((wheel < 0)
|
||||
&& (stackSl.stackSize < stackSl.getMaxStackSize())) {
|
||||
applicableSlot = sl;
|
||||
break;
|
||||
} else if (wheel > 0) {
|
||||
applicableSlot = sl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isCraftingOutput) {
|
||||
if (wheel < 0) {
|
||||
boolean mouseWasEmpty = stackOnMouse == null;
|
||||
|
||||
for (int i = 0; i < numItemsToMove; i++) {
|
||||
clickSlot(currentScreen, selectedSlot, 0, false);
|
||||
}
|
||||
|
||||
if ((applicableSlot != null)
|
||||
&& mouseWasEmpty) {
|
||||
clickSlot(currentScreen, applicableSlot, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (applicableSlot != null) {
|
||||
Slot slotTo = (wheel < 0) ? applicableSlot : selectedSlot;
|
||||
Slot slotFrom = (wheel < 0) ? selectedSlot : applicableSlot;
|
||||
ItemStack stackTo = (getSlotStack(slotTo) != null) ? copyItemStack(getSlotStack(slotTo)) : null;
|
||||
ItemStack stackFrom = copyItemStack(getSlotStack(slotFrom));
|
||||
|
||||
if (wheel < 0) {
|
||||
numItemsToMove = Math.min(numItemsToMove, getItemStackSize(stackFrom));
|
||||
|
||||
if ((stackTo != null)
|
||||
&& ((getMaxItemStackSize(stackTo) - getItemStackSize(stackTo)) <= numItemsToMove)) {
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
clickSlot(currentScreen, slotTo, 0, false);
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
|
||||
numItemsToMove -= getMaxItemStackSize(stackTo) - getItemStackSize(stackTo);
|
||||
} else {
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
|
||||
if (getItemStackSize(stackFrom) <= numItemsToMove) {
|
||||
clickSlot(currentScreen, slotTo, 0, false);
|
||||
} else {
|
||||
for (int i = 0; i < numItemsToMove; i++) {
|
||||
clickSlot(currentScreen, slotTo, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
|
||||
numItemsToMove = 0;
|
||||
}
|
||||
} else {
|
||||
if ((getMaxItemStackSize(stackTo) - getItemStackSize(stackTo)) <= numItemsToMove) {
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
clickSlot(currentScreen, slotTo, 0, false);
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
} else {
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
|
||||
if (getItemStackSize(stackFrom) <= numItemsToMove) {
|
||||
clickSlot(currentScreen, slotTo, 0, false);
|
||||
numItemsToMove -= getMaxItemStackSize(stackFrom);
|
||||
} else {
|
||||
for (int i = 0; i < numItemsToMove; i++) {
|
||||
clickSlot(currentScreen, slotTo, 1, false);
|
||||
}
|
||||
|
||||
numItemsToMove = 0;
|
||||
}
|
||||
|
||||
clickSlot(currentScreen, slotFrom, 0, false);
|
||||
}
|
||||
|
||||
if (getMaxItemStackSize(stackTo) == getMaxItemStackSize(stackTo)) {
|
||||
numItemsToMove = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (numItemsToMove != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldStackOnMouse = stackOnMouse;
|
||||
}
|
||||
|
||||
public static int getGuiContainerID(GuiScreen currentScreen) {
|
||||
int containerID = ModCompatibility.getModGuiContainerID(currentScreen); // This first because a lot of mod containers extend the vanilla Minecraft one.
|
||||
if (containerID == Constants.NOTGUICONTAINER)
|
||||
return (isGuiContainer(currentScreen) && isValidGuiContainer(currentScreen)) ? Constants.MINECRAFT : Constants.NOTGUICONTAINER;
|
||||
else
|
||||
return containerID;
|
||||
}
|
||||
|
||||
public static Object getContainerWithID(GuiScreen currentScreen) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return getContainer(asGuiContainer(currentScreen));
|
||||
else
|
||||
return ModCompatibility.getModContainer(guiContainerID, currentScreen);
|
||||
}
|
||||
|
||||
public static int getSlotCountWithID(GuiScreen currentScreen) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return getSlots(asContainer(container)).size();
|
||||
else
|
||||
return ModCompatibility.getModSlotCount(guiContainerID, currentScreen, container);
|
||||
}
|
||||
|
||||
public static String getGuiContainerNameFromID(GuiScreen currentScreen) {
|
||||
switch (guiContainerID) {
|
||||
case Constants.NOTASSIGNED:
|
||||
return "Unknown";
|
||||
case Constants.NOTGUICONTAINER:
|
||||
return "Wrong";
|
||||
case Constants.MINECRAFT:
|
||||
return "Vanilla Minecraft";
|
||||
|
||||
default:
|
||||
return ModCompatibility.getModNameFromModGuiContainerID(guiContainerID, currentScreen);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDisabledForThisContainer(GuiScreen currentScreen) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return false;
|
||||
else
|
||||
return ModCompatibility.isDisabledForThisModContainer(guiContainerID, currentScreen, container);
|
||||
}
|
||||
|
||||
public static boolean isWheelDisabledForThisContainer(GuiScreen currentScreen) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return false;
|
||||
else
|
||||
return ModCompatibility.isWheelDisabledForThisModContainer(guiContainerID, currentScreen);
|
||||
}
|
||||
|
||||
public static Slot getSelectedSlotWithID(GuiScreen currentScreen, int slotCount) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return getSelectedSlot(asGuiContainer(currentScreen), asContainer(container), slotCount);
|
||||
else
|
||||
return ModCompatibility.getModSelectedSlot(guiContainerID, currentScreen, container, slotCount);
|
||||
}
|
||||
|
||||
public static void clickSlot(GuiScreen currentScreen, Slot targetSlot, int mouseButton, boolean shiftPressed) {
|
||||
if (guiContainerID == Constants.MINECRAFT) {
|
||||
windowClick(getWindowId(asContainer(container)), getSlotNumber(targetSlot), mouseButton, shiftPressed ? 1 : 0);
|
||||
} else {
|
||||
ModCompatibility.modClickSlot(guiContainerID, currentScreen, container, targetSlot, mouseButton, shiftPressed);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCraftingOutputSlot(GuiScreen currentScreen, Slot targetSlot) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return isVanillaCraftingOutputSlot(asContainer(container), targetSlot);
|
||||
else
|
||||
return ModCompatibility.modIsCraftingOutputSlot(guiContainerID, currentScreen, container, targetSlot);
|
||||
}
|
||||
|
||||
public static Slot getSlotWithID(GuiScreen currentScreen, int slotNumber) {
|
||||
if (guiContainerID == Constants.MINECRAFT)
|
||||
return getSlot(asContainer(container), slotNumber);
|
||||
else
|
||||
return ModCompatibility.modGetSlot(guiContainerID, currentScreen, container, slotNumber);
|
||||
}
|
||||
|
||||
public static void disableRMBDragWithID(GuiScreen currentScreen) {
|
||||
if (guiContainerID == Constants.MINECRAFT) {
|
||||
disableVanillaRMBDrag(asGuiContainer(currentScreen));
|
||||
|
||||
if (shouldClick) {
|
||||
clickSlot(currentScreen, firstSlot, 1, false);
|
||||
}
|
||||
} else {
|
||||
ModCompatibility.disableRMBDragIfRequired(guiContainerID, currentScreen, container, firstSlot, shouldClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import yalter.mousetweaks.api.IMTModGuiContainer;
|
||||
|
||||
public class ModCompatibility extends DeobfuscationLayer {
|
||||
private static boolean initialized = false;
|
||||
|
||||
private static boolean forestryInstalled = false;
|
||||
private static boolean codechickencoreInstalled = false;
|
||||
private static boolean NEIInstalled = false;
|
||||
|
||||
public static void initialize() {
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
forestryInstalled = Reflection.reflectForestry();
|
||||
if (forestryInstalled) {
|
||||
Logger.Log("Successfully reflected Forestry!");
|
||||
}
|
||||
|
||||
codechickencoreInstalled = Reflection.reflectCodeChickenCore();
|
||||
if (codechickencoreInstalled) {
|
||||
Logger.Log("Successfully reflected CodeChickenCore!");
|
||||
}
|
||||
|
||||
NEIInstalled = Reflection.reflectNEI();
|
||||
if (NEIInstalled) {
|
||||
Logger.Log("Successfully reflected NEI!");
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public static int getModGuiContainerID(GuiScreen guiScreen) {
|
||||
if (guiScreen instanceof IMTModGuiContainer)
|
||||
return Constants.MTMODGUICONTAINER;
|
||||
|
||||
if (forestryInstalled && Reflection.forestry.isInstance("GuiForestry", guiScreen))
|
||||
return Constants.FORESTRY;
|
||||
|
||||
if (codechickencoreInstalled && Reflection.codechickencore.isInstance("GuiContainerWidget", guiScreen))
|
||||
return Constants.CODECHICKENCORE;
|
||||
|
||||
if ((NEIInstalled
|
||||
&& (Reflection.NEI.isInstance("GuiRecipe", guiScreen)))
|
||||
|| Reflection.NEI.isInstance("GuiEnchantmentModifier", guiScreen))
|
||||
return Constants.NEI;
|
||||
|
||||
return Constants.NOTGUICONTAINER;
|
||||
}
|
||||
|
||||
public static String getModNameFromModGuiContainerID(int id, GuiScreen guiScreen) {
|
||||
switch (id) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return ((IMTModGuiContainer) guiScreen).getModName();
|
||||
|
||||
case Constants.FORESTRY:
|
||||
return "Forestry";
|
||||
case Constants.CODECHICKENCORE:
|
||||
return "CodeChickenCore";
|
||||
case Constants.NEI:
|
||||
return "NotEnoughItems";
|
||||
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isWheelDisabledForThisModContainer(int modGuiContainerID, GuiScreen guiScreen) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return ((IMTModGuiContainer) guiScreen).isWheelTweakDisabled();
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Slot modGetSlot(int modGuiContainerID, GuiScreen guiScreen, Object modContainer, int slotNumber) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return asSlot(((IMTModGuiContainer) guiScreen).getModSlot(modContainer, slotNumber));
|
||||
|
||||
case Constants.FORESTRY:
|
||||
return getSlot(asContainer(modContainer), slotNumber);
|
||||
case Constants.NEI:
|
||||
return getSlot(asContainer(modContainer), slotNumber);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean modIsCraftingOutputSlot(int modGuiContainerID, GuiScreen guiScreen, Object modContainer, Slot selectedSlot) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return ((IMTModGuiContainer) guiScreen).isCraftingOutputSlot(modContainer, selectedSlot);
|
||||
|
||||
case Constants.FORESTRY:
|
||||
return (Reflection.is(modContainer, "ContainerSqueezer") && ((getSlotNumber(selectedSlot) == 9) || (getSlotNumber(selectedSlot) == 11)))
|
||||
|| (Reflection.is(modContainer, "ContainerMoistener") && (getSlotNumber(selectedSlot) == 9))
|
||||
|| (Reflection.is(modContainer, "ContainerCentrifuge") && ((getSlotNumber(selectedSlot) >= 1) && (getSlotNumber(selectedSlot) <= 9)))
|
||||
|| (Reflection.is(modContainer, "ContainerCarpenter") && (getSlotNumber(selectedSlot) == 21))
|
||||
|| (Reflection.is(modContainer, "ContainerFabricator") && (getSlotNumber(selectedSlot) == 20))
|
||||
|| (Reflection.is(modContainer, "ContainerWorktable") && (getSlotNumber(selectedSlot) == 27));
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void modClickSlot(int modGuiContainerID, GuiScreen guiScreen, Object modContainer, Slot targetSlot, int mouseButton, boolean shiftPressed) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
((IMTModGuiContainer) guiScreen).clickModSlot(modContainer, targetSlot, mouseButton, shiftPressed);
|
||||
return;
|
||||
|
||||
case Constants.FORESTRY:
|
||||
Reflection.forestry.invokeMethod(guiScreen, "handleMouseClick", targetSlot, 0, mouseButton, shiftPressed ? 1 : 0);
|
||||
return;
|
||||
|
||||
case Constants.NEI:
|
||||
windowClick(getWindowId(asContainer(modContainer)), getSlotNumber(targetSlot), mouseButton, shiftPressed ? 1 : 0);
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static Slot getModSelectedSlot(int modGuiContainerID, GuiScreen guiScreen, Object modContainer, int slotCount) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return asSlot(((IMTModGuiContainer) guiScreen).getModSelectedSlot(modContainer, slotCount));
|
||||
|
||||
case Constants.FORESTRY:
|
||||
return asSlot(Reflection.forestry.invokeMethod(guiScreen, "getSlotAtPosition", getRequiredMouseX(), getRequiredMouseY()));
|
||||
case Constants.NEI:
|
||||
return getSelectedSlot(asGuiContainer(guiScreen), asContainer(modContainer), slotCount);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getModSlotCount(int modGuiContainerID, GuiScreen guiScreen, Object modContainer) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return ((IMTModGuiContainer) guiScreen).getModSlotCount(modContainer);
|
||||
|
||||
case Constants.FORESTRY:
|
||||
return getSlots(asContainer(modContainer)).size();
|
||||
case Constants.NEI:
|
||||
return getSlots(asContainer(modContainer)).size();
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getModContainer(int modGuiContainerID, GuiScreen guiScreen) {
|
||||
switch (modGuiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return ((IMTModGuiContainer) guiScreen).getModContainer();
|
||||
|
||||
case Constants.FORESTRY:
|
||||
return Reflection.forestry.getFieldValue("inventorySlots", guiScreen);
|
||||
case Constants.NEI:
|
||||
return getContainer(asGuiContainer(guiScreen));
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void disableRMBDragIfRequired(int guiContainerID, GuiScreen guiScreen, Object modContainer, Slot firstSlot, boolean shouldClick) {
|
||||
switch (guiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
((IMTModGuiContainer) guiScreen).disableRMBDragIfRequired(modContainer, firstSlot, shouldClick);
|
||||
|
||||
return;
|
||||
|
||||
case Constants.NEI:
|
||||
disableVanillaRMBDrag(asGuiContainer(guiScreen));
|
||||
|
||||
if (shouldClick) {
|
||||
modClickSlot(guiContainerID, guiScreen, modContainer, firstSlot, 1, false);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDisabledForThisModContainer(int guiContainerID, GuiScreen guiScreen, Object container) {
|
||||
switch (guiContainerID) {
|
||||
case Constants.MTMODGUICONTAINER:
|
||||
return ((IMTModGuiContainer) guiScreen).isMouseTweaksDisabled();
|
||||
|
||||
case Constants.CODECHICKENCORE:
|
||||
return true;
|
||||
case Constants.NEI:
|
||||
return !Reflection.NEI.isInstance("GuiEnchantmentModifier", guiScreen);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.profiler.Profiler;
|
||||
|
||||
public class ProfilerCustom extends Profiler {
|
||||
private Minecraft minecraft;
|
||||
|
||||
public ProfilerCustom() {
|
||||
minecraft = Minecraft.getMinecraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSection(String sectionName) {
|
||||
// The useProfiler check is redundant here since the OnTick method cannot change in the runtime (at the time of writing this comment).
|
||||
if (Main.useProfiler && "gameRenderer".equals(sectionName)) {
|
||||
Main.onUpdateInGame();
|
||||
}
|
||||
|
||||
super.startSection(sectionName);
|
||||
|
||||
if (Main.optifine) {
|
||||
if (!Reflection.gameSettings.setFieldValue(minecraft.gameSettings, "ofProfiler", true)) {
|
||||
Main.optifine = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class Reflection {
|
||||
public static ReflectionCache guiContainerClass;
|
||||
public static ReflectionCache liteLoaderClass;
|
||||
public static ReflectionCache liteModMouseTweaks;
|
||||
public static ReflectionCache gameSettings;
|
||||
public static ReflectionCache minecraft;
|
||||
|
||||
public static ReflectionCache forestry;
|
||||
public static ReflectionCache codechickencore;
|
||||
public static ReflectionCache NEI;
|
||||
|
||||
public enum Obfuscation {MCP, FORGE, VANILLA}
|
||||
private static Obfuscation obfuscation;
|
||||
private static boolean checkObfuscation = true;
|
||||
|
||||
public static boolean reflectGuiContainer() {
|
||||
guiContainerClass = new ReflectionCache();
|
||||
guiContainerClass.storeClass("GuiContainer", GuiContainer.class);
|
||||
|
||||
Method isMouseOverSlot = getMethod(GuiContainer.class,
|
||||
getObfuscatedName(Constants.ISMOUSEOVERSLOT_FORGE_NAME, Constants.ISMOUSEOVERSLOT_FORGE_NAME, Constants.ISMOUSEOVERSLOT_NAME), Slot.class, int.class,
|
||||
int.class);
|
||||
|
||||
if (isMouseOverSlot == null) {
|
||||
Logger.Log("Failed to get isMouseOverSlot method, quitting");
|
||||
return false;
|
||||
}
|
||||
|
||||
guiContainerClass.storeMethod("isMouseOverSlot", isMouseOverSlot);
|
||||
|
||||
Field field;
|
||||
field = getField(GuiContainer.class,
|
||||
getObfuscatedName(Constants.FIELDE_FORGE_NAME, Constants.FIELDE_FORGE_NAME, Constants.FIELDE_NAME));
|
||||
|
||||
if (field == null) {
|
||||
Logger.Log("Failed to retrieve the E field, disabling RMBTweak");
|
||||
Main.DisableRMBTweak = true;
|
||||
} else {
|
||||
guiContainerClass.storeField(Constants.FIELDE_FORGE_NAME, field);
|
||||
|
||||
field = getField(GuiContainer.class,
|
||||
getObfuscatedName(Constants.FIELDq_FORGE_NAME, Constants.FIELDq_FORGE_NAME, Constants.FIELDq_NAME));
|
||||
|
||||
if (field == null) {
|
||||
Logger.Log("Failed to retreive the q field, disabling RMBTweak");
|
||||
Main.DisableRMBTweak = true;
|
||||
} else {
|
||||
guiContainerClass.storeField(Constants.FIELDq_FORGE_NAME, field);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean registerLiteModListenerInLiteLoader() {
|
||||
liteLoaderClass = new ReflectionCache();
|
||||
|
||||
Class lL = getClass("com.mumfrey.liteloader.core.LiteLoader");
|
||||
if (lL != null) {
|
||||
liteLoaderClass.storeClass("LiteLoader", lL);
|
||||
|
||||
liteLoaderClass.available = true;
|
||||
|
||||
Class llEvents = getClass("com.mumfrey.liteloader.core.Events");
|
||||
if (llEvents != null) {
|
||||
liteLoaderClass.storeClass("Events", llEvents);
|
||||
|
||||
Field llEventsField = getField(lL, "events");
|
||||
if (llEventsField != null) {
|
||||
liteLoaderClass.storeField("events", llEventsField);
|
||||
|
||||
Class lM = getClass("com.mumfrey.liteloader.LiteMod");
|
||||
if (lM != null) {
|
||||
liteLoaderClass.storeClass("LiteMod", lM);
|
||||
|
||||
Method addListener = getMethod(llEvents, "addListener", lM);
|
||||
if (addListener != null) {
|
||||
liteLoaderClass.storeMethod("addListener", addListener);
|
||||
|
||||
Method getInstance = getMethod(lL, "getInstance");
|
||||
if (getInstance != null) {
|
||||
liteLoaderClass.storeMethod("getInstance", getInstance);
|
||||
|
||||
Object liteLoaderInstance = liteLoaderClass.invokeStaticMethod("LiteLoader", "getInstance");
|
||||
if (liteLoaderInstance != null) {
|
||||
Object llEventsInstance = liteLoaderClass.getFieldValue("events", liteLoaderInstance);
|
||||
if (llEventsInstance != null) {
|
||||
Class mouseTweaks = getClass("yalter.mousetweaks.loaders.LiteModMouseTweaks");
|
||||
if (mouseTweaks != null) {
|
||||
liteModMouseTweaks = new ReflectionCache();
|
||||
liteModMouseTweaks.storeClass("LiteModMouseTweaks", mouseTweaks);
|
||||
|
||||
Method getLMMTInstance = getMethod(mouseTweaks, "getInstance");
|
||||
if (getLMMTInstance != null) {
|
||||
liteModMouseTweaks.storeMethod("getInstance", getLMMTInstance);
|
||||
|
||||
Object LMMTInstance = liteModMouseTweaks.invokeStaticMethod("LiteModMouseTweaks", "getInstance");
|
||||
if (LMMTInstance != null) {
|
||||
liteLoaderClass.invokeMethod(llEventsInstance, "addListener", LMMTInstance);
|
||||
|
||||
liteLoaderClass.compatible = true;
|
||||
Logger.Log("Registered the LiteModMouseTweaks' listener in LiteLoader.");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
Logger.Log("Could not get the instance from the getInstance method of LiteModMouseTweaks! Have you modified the class?");
|
||||
}
|
||||
} else {
|
||||
Logger.Log("Could not get the getInstance method from LiteModMouseTweaks! Have you modified the class?");
|
||||
}
|
||||
} else {
|
||||
Logger.Log("Could not get the LiteModMouseTweaks class! Have you deleted it accidentally?");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Logger.Log("Failed to retrieve the LiteLoader instance!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean reflectOptifine() {
|
||||
gameSettings = new ReflectionCache();
|
||||
gameSettings.storeClass("GameSettings", GameSettings.class);
|
||||
|
||||
Field optifineProfilerEnabled = getField(GameSettings.class, "ofProfiler");
|
||||
if (optifineProfilerEnabled != null) {
|
||||
gameSettings.storeField("ofProfiler", optifineProfilerEnabled);
|
||||
|
||||
Logger.Log("Optifine is installed.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Logger.Log("Optifine is not installed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean replaceProfiler() {
|
||||
minecraft = new ReflectionCache();
|
||||
minecraft.storeClass("Minecraft", Minecraft.class);
|
||||
|
||||
Field profilerField = getFinalField(Minecraft.class, getObfuscatedName(Constants.MCPROFILER_MCP_NAME, Constants.MCPROFILER_FORGE_NAME, Constants.MCPROFILER_NAME));
|
||||
if (profilerField != null) {
|
||||
minecraft.storeField("mcProfiler", profilerField);
|
||||
return minecraft.setFieldValue(Minecraft.getMinecraft(), "mcProfiler", new ProfilerCustom());
|
||||
}
|
||||
|
||||
Logger.Log("Failed to get the Minecraft profiler field!");
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean reflectForestry() {
|
||||
forestry = new ReflectionCache();
|
||||
|
||||
Class guiForestryClass = getClass("forestry.core.gui.GuiForestry");
|
||||
if (guiForestryClass != null) {
|
||||
forestry.storeClass("GuiForestry", guiForestryClass);
|
||||
forestry.available = true;
|
||||
|
||||
Field inventorySlotsField = getField(guiForestryClass, "inventorySlots");
|
||||
if (inventorySlotsField != null) {
|
||||
forestry.storeField("inventorySlots", inventorySlotsField);
|
||||
|
||||
Method getSlotAtPositionMethod = getMethod(guiForestryClass, "getSlotAtPosition", int.class, int.class);
|
||||
if (getSlotAtPositionMethod != null) {
|
||||
forestry.storeMethod("getSlotAtPosition", getSlotAtPositionMethod);
|
||||
|
||||
Method handleMouseClickMethod = getMethod(guiForestryClass, "handleMouseClick", Slot.class, int.class, int.class, int.class);
|
||||
if (handleMouseClickMethod != null) {
|
||||
forestry.storeMethod("handleMouseClick", handleMouseClickMethod);
|
||||
|
||||
forestry.compatible = true;
|
||||
|
||||
// Class containerForestryClass = getClass( "forestry.core.gui.ContainerForestry" );
|
||||
// if ( containerForestryClass != null ) {
|
||||
// forestry.storeClass( "ContainerForestry", containerForestryClass );
|
||||
//
|
||||
// Field slotCountField = getField( containerForestryClass, "slotCount" );
|
||||
// if ( slotCountField != null ) {
|
||||
// forestry.storeField( "slotCount", slotCountField );
|
||||
//
|
||||
// forestry.compatible = true;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return forestry.compatible;
|
||||
}
|
||||
|
||||
public static boolean reflectCodeChickenCore() {
|
||||
codechickencore = new ReflectionCache();
|
||||
|
||||
Class guiContainerWidgetClass = getClass("codechicken.core.inventory.GuiContainerWidget");
|
||||
if (guiContainerWidgetClass != null) {
|
||||
codechickencore.storeClass("GuiContainerWidget", guiContainerWidgetClass);
|
||||
|
||||
codechickencore.available = true;
|
||||
codechickencore.compatible = true;
|
||||
}
|
||||
|
||||
return codechickencore.compatible;
|
||||
}
|
||||
|
||||
public static boolean reflectNEI() {
|
||||
NEI = new ReflectionCache();
|
||||
|
||||
Class guiRecipeClass = getClass("codechicken.nei.recipe.GuiRecipe");
|
||||
if (guiRecipeClass != null) {
|
||||
NEI.storeClass("GuiRecipe", guiRecipeClass);
|
||||
NEI.available = true;
|
||||
|
||||
Class guiEnchantmentModifierClass = getClass("codechicken.nei.GuiEnchantmentModifier");
|
||||
if (guiEnchantmentModifierClass != null) {
|
||||
NEI.storeClass("GuiEnchantmentModifier", guiEnchantmentModifierClass);
|
||||
|
||||
NEI.compatible = true;
|
||||
}
|
||||
}
|
||||
|
||||
return NEI.compatible;
|
||||
}
|
||||
|
||||
public static boolean is(Object object, String name) {
|
||||
return object.getClass().getSimpleName() == name;
|
||||
}
|
||||
|
||||
public static boolean doesClassExist(String name) {
|
||||
Class clazz = getClass(name);
|
||||
return clazz != null;
|
||||
}
|
||||
|
||||
public static Class getClass(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getField(Class clazz, String name) {
|
||||
try {
|
||||
Field field = null;
|
||||
|
||||
try {
|
||||
field = clazz.getField(name);
|
||||
} catch (Exception e) {
|
||||
field = null;
|
||||
}
|
||||
|
||||
if (field == null) {
|
||||
field = clazz.getDeclaredField(name);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
if (name != "ofProfiler") {
|
||||
Logger.Log("Could not retrieve field \"" + name + "\" from class \"" + clazz.getName()
|
||||
+ "\"");
|
||||
|
||||
if (Main.Debug == 1) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Field getFinalField(Class clazz, String name) {
|
||||
try {
|
||||
Field field = null;
|
||||
|
||||
try {
|
||||
field = clazz.getField(name);
|
||||
} catch (Exception e) {
|
||||
field = null;
|
||||
}
|
||||
|
||||
if (field == null) {
|
||||
field = clazz.getDeclaredField(name);
|
||||
}
|
||||
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
modifiers.set(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
Logger.Log("Could not retrieve field \"" + name + "\" from class \"" + clazz.getName()
|
||||
+ "\"");
|
||||
|
||||
if (Main.Debug == 1) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> clazz, String name, Class... args) {
|
||||
try {
|
||||
Method method = null;
|
||||
|
||||
try {
|
||||
method = clazz.getMethod(name, args);
|
||||
} catch (Exception e) {
|
||||
method = null;
|
||||
}
|
||||
|
||||
if (method == null) {
|
||||
if ((args != null) & (args.length != 0)) {
|
||||
method = clazz.getDeclaredMethod(name, args);
|
||||
} else {
|
||||
method = clazz.getDeclaredMethod(name, new Class[0]);
|
||||
}
|
||||
}
|
||||
|
||||
method.setAccessible(true);
|
||||
return method;
|
||||
} catch (Exception e) {
|
||||
Logger.Log("Could not retrieve method \"" + name + "\" from class \"" + clazz.getName()
|
||||
+ "\"");
|
||||
|
||||
if (Main.Debug == 1) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String methodToString(Method method) {
|
||||
return Modifier.toString(method.getModifiers()) + " " + ((method.getReturnType() != null) ? method
|
||||
.getReturnType().getName() : "void") + " " + method.getName();
|
||||
}
|
||||
|
||||
public static String getObfuscatedName(String mcpName, String forgeName, String originalName) {
|
||||
if (checkObfuscation) {
|
||||
checkObfuscation();
|
||||
}
|
||||
|
||||
if (obfuscation == Obfuscation.MCP)
|
||||
return mcpName;
|
||||
else if (obfuscation == Obfuscation.FORGE)
|
||||
return forgeName;
|
||||
else
|
||||
return originalName;
|
||||
}
|
||||
|
||||
public static void checkObfuscation() {
|
||||
checkObfuscation = false;
|
||||
|
||||
Logger.Log("Obfuscation check, please ignore the following errors (if they come up).");
|
||||
|
||||
if (getField(Minecraft.class, Constants.MCPROFILER_MCP_NAME) != null)
|
||||
obfuscation = Obfuscation.MCP;
|
||||
else if (getField(Minecraft.class, Constants.MCPROFILER_FORGE_NAME) != null)
|
||||
obfuscation = Obfuscation.FORGE;
|
||||
else
|
||||
obfuscation = Obfuscation.VANILLA;
|
||||
|
||||
Logger.Log("Obfuscation check completed.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ReflectionCache {
|
||||
public boolean available = false;
|
||||
public boolean compatible = false;
|
||||
public HashMap<String, Class> classes = new HashMap<String, Class>();
|
||||
public HashMap<String, Method> methods = new HashMap<String, Method>();
|
||||
public HashMap<String, Field> fields = new HashMap<String, Field>();
|
||||
|
||||
public ReflectionCache() {
|
||||
}
|
||||
|
||||
public Object getFieldValue(String name, Object obj) {
|
||||
try {
|
||||
if (fields.containsKey(name)) {
|
||||
Field field = fields.get(name);
|
||||
return field.get(obj);
|
||||
}
|
||||
|
||||
Logger.Log("No such field: " + name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.Log("Failed to get a value of field: " + name);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean setFieldValue(Object obj, String name, Object value) {
|
||||
try {
|
||||
if (fields.containsKey(name)) {
|
||||
Field field = fields.get(name);
|
||||
field.set(obj, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Logger.Log("No such field: " + name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.Log("Failed to set a value of field: " + name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object invokeMethod(Object obj, String name, Object... args) {
|
||||
try {
|
||||
if (methods.containsKey(name)) {
|
||||
Method method = methods.get(name);
|
||||
|
||||
if (args != null)
|
||||
return method.invoke(obj, args);
|
||||
|
||||
return method.invoke(obj, new Object[0]);
|
||||
}
|
||||
|
||||
Logger.Log("No such method: " + name);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Logger.Log("Failed to invoke method: " + name);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object invokeStaticMethod(String className, String name, Object... args) {
|
||||
if (classes.containsKey(className)) {
|
||||
Class clazz = classes.get(className);
|
||||
|
||||
return invokeMethod(clazz, name, args);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isInstance(String className, Object obj) {
|
||||
if (classes.containsKey(className)) {
|
||||
Class clazz = classes.get(className);
|
||||
return clazz.isInstance(obj);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void storeClass(String name, Class clazz) {
|
||||
classes.put(name, clazz);
|
||||
}
|
||||
|
||||
public void storeMethod(String name, Method method) {
|
||||
methods.put(name, method);
|
||||
}
|
||||
|
||||
public void storeField(String name, Field field) {
|
||||
fields.put(name, field);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package yalter.mousetweaks.api;
|
||||
|
||||
public interface IMTModGuiContainer {
|
||||
/**
|
||||
* Returns the API version.
|
||||
*
|
||||
* @return The API version. Should return 1 for this version.
|
||||
*/
|
||||
public int getAPIVersion();
|
||||
|
||||
/**
|
||||
* Returns the mod name to use in log messages.
|
||||
*
|
||||
* @return The name of the mod.
|
||||
*/
|
||||
public String getModName();
|
||||
|
||||
/**
|
||||
* Returns whether or not Mouse Tweaks should be disabled for this GuiContainer.
|
||||
*
|
||||
* @return True if Mouse Tweaks should be disabled, false otherwise.
|
||||
*/
|
||||
public boolean isMouseTweaksDisabled();
|
||||
|
||||
/**
|
||||
* Returns whether or not wheelTweak should be disabled for this GuiContainer.
|
||||
*
|
||||
* @return True if wheelTweak should be disabled, false otherwise.
|
||||
*/
|
||||
public boolean isWheelTweakDisabled();
|
||||
|
||||
/**
|
||||
* Returns whether or not the given slot is a crafting output slot.
|
||||
*
|
||||
* @param modContainer The container of the given slot.
|
||||
* @param slot The slot to check.
|
||||
* @return True if the given slot is a crafting output slot, false otherwise.
|
||||
*/
|
||||
public boolean isCraftingOutputSlot(Object modContainer, Object slot);
|
||||
|
||||
/**
|
||||
* Returns the container of this GuiContainer. If multiple containers are used, returns the one that is used at the moment of the method execution.
|
||||
*
|
||||
* @return The container that is currently used.
|
||||
*/
|
||||
public Object getModContainer();
|
||||
|
||||
/**
|
||||
* Returns the number of slots present in the given container (for containers with variable slot number - the number of slots at the moment of the method execution).
|
||||
*
|
||||
* @param modContainer The container to retrieve the number of slots from.
|
||||
* @return The number of slots in the given container.
|
||||
*/
|
||||
public int getModSlotCount(Object modContainer);
|
||||
|
||||
/**
|
||||
* Returns a slot from this container with the given slot number.
|
||||
*
|
||||
* @param modContainer The container from which to retrieve the slot.
|
||||
* @param slotNumber The number of the slot to be retrieved.
|
||||
* @return The slot from the given container with the given slot number.
|
||||
*/
|
||||
public Object getModSlot(Object modContainer, int slotNumber);
|
||||
|
||||
/**
|
||||
* Returns the currently selected slot (the one under the player's mouse cursor) of the given container, which has the given number of slots.
|
||||
*
|
||||
* @param modContainer The container to check.
|
||||
* @param slotCount The number of slots that this container has.
|
||||
* @return The slot that is currently selected. Null if none are.
|
||||
*/
|
||||
public Object getModSelectedSlot(Object modContainer, int slotCount);
|
||||
|
||||
/**
|
||||
* The method that clicks the given slot of the given container with the given mouse button and shift key state.
|
||||
*
|
||||
* @param modContainer The container of the given slot.
|
||||
* @param slot The slot to click.
|
||||
* @param mouseButton The mouse button. 0 is the left one, 1 is the right one.
|
||||
* @param shiftPressed True if the shift key is pressed, false otherwise.
|
||||
*/
|
||||
public void clickModSlot(Object modContainer, Object slot, int mouseButton, boolean shiftPressed);
|
||||
|
||||
/**
|
||||
* The method that disables the built-in RMB drag mechanic, if required, in this GuiContainer, with the given first slot in the given container to click if shouldClick is set to true (in vanilla circumstances - your RMB dragging mechanic might work differently).
|
||||
*
|
||||
* @param modContainer The container of the first slot.
|
||||
* @param firstSlot The first slot.
|
||||
* @param shouldClick True, if the first slot is to be clicked.
|
||||
*/
|
||||
public void disableRMBDragIfRequired(Object modContainer, Object firstSlot, boolean shouldClick);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package yalter.mousetweaks.loaders;
|
||||
|
||||
import com.mumfrey.liteloader.RenderListener;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import yalter.mousetweaks.Constants;
|
||||
import yalter.mousetweaks.Main;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LiteModMouseTweaks implements RenderListener {
|
||||
private static LiteModMouseTweaks instance;
|
||||
|
||||
public static LiteModMouseTweaks getInstance() {
|
||||
if (instance == null)
|
||||
instance = new LiteModMouseTweaks();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public LiteModMouseTweaks() { }
|
||||
|
||||
@Override
|
||||
public void init(File file) {
|
||||
Main.initialise(Constants.EntryPoint.LITELOADER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRender() {
|
||||
if (Main.useLiteLoader)
|
||||
Main.onUpdateInGame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Constants.MOD_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return Constants.MOD_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderGui(GuiScreen guiScreen) { }
|
||||
|
||||
@Override
|
||||
public void onRenderWorld() { }
|
||||
|
||||
@Override
|
||||
public void onSetupCameraTransform() { }
|
||||
|
||||
@Override
|
||||
public void upgradeSettings(String s, File file, File file2) { }
|
||||
}
|
||||
Reference in new issue
Block a user