From 7676ce2b4932fcf26280324b05d75c7882bbdedd Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Sun, 29 Jan 2023 11:48:18 -0800 Subject: [PATCH] [ci skip] spotlessApply with the new settings --- src/main/java/yalter/mousetweaks/Config.java | 4 +- .../java/yalter/mousetweaks/Constants.java | 1 + .../mousetweaks/DeobfuscationLayer.java | 8 +- src/main/java/yalter/mousetweaks/Main.java | 83 +++++++++---------- .../yalter/mousetweaks/ModCompatibility.java | 40 ++++----- .../java/yalter/mousetweaks/Reflection.java | 23 +++-- .../yalter/mousetweaks/ReflectionCache.java | 1 + .../mousetweaks/api/IMTModGuiContainer.java | 14 +++- .../mousetweaks/loaders/MouseTweaksForge.java | 4 +- 9 files changed, 96 insertions(+), 82 deletions(-) diff --git a/src/main/java/yalter/mousetweaks/Config.java b/src/main/java/yalter/mousetweaks/Config.java index 453a722..844ef90 100644 --- a/src/main/java/yalter/mousetweaks/Config.java +++ b/src/main/java/yalter/mousetweaks/Config.java @@ -4,6 +4,7 @@ import java.io.*; import java.util.Properties; public class Config { + private String fileName; private Properties properties = new Properties(); @@ -22,8 +23,7 @@ public class Config { if (properties.size() == 0) return false; return true; - } catch (FileNotFoundException ignored) { - } catch (IOException e) { + } catch (FileNotFoundException ignored) {} catch (IOException e) { Constants.LOGGER.error("Failed to read the config file: " + fileName, e); } diff --git a/src/main/java/yalter/mousetweaks/Constants.java b/src/main/java/yalter/mousetweaks/Constants.java index 2974d41..4a0abc4 100644 --- a/src/main/java/yalter/mousetweaks/Constants.java +++ b/src/main/java/yalter/mousetweaks/Constants.java @@ -1,6 +1,7 @@ package yalter.mousetweaks; import net.minecraft.launchwrapper.Launch; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/main/java/yalter/mousetweaks/DeobfuscationLayer.java b/src/main/java/yalter/mousetweaks/DeobfuscationLayer.java index b210d40..8ddbb81 100644 --- a/src/main/java/yalter/mousetweaks/DeobfuscationLayer.java +++ b/src/main/java/yalter/mousetweaks/DeobfuscationLayer.java @@ -1,6 +1,7 @@ package yalter.mousetweaks; import java.util.List; + import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.gui.GuiScreen; @@ -16,6 +17,7 @@ import net.minecraft.inventory.ContainerRepair; import net.minecraft.inventory.ContainerWorkbench; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; + import org.lwjgl.input.Mouse; public class DeobfuscationLayer { @@ -31,8 +33,7 @@ public class DeobfuscationLayer { } protected static boolean isValidGuiContainer(GuiScreen guiScreen) { - return (guiScreen != null) - && !(guiScreen.getClass().getSimpleName().contains("CJB_GuiCrafting")) + return (guiScreen != null) && !(guiScreen.getClass().getSimpleName().contains("CJB_GuiCrafting")) && !(guiScreen.getClass().equals(GuiContainerCreative.class)); } @@ -135,7 +136,8 @@ public class DeobfuscationLayer { } /** - * 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. + * 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. */ diff --git a/src/main/java/yalter/mousetweaks/Main.java b/src/main/java/yalter/mousetweaks/Main.java index a7e66d1..3cdc89b 100644 --- a/src/main/java/yalter/mousetweaks/Main.java +++ b/src/main/java/yalter/mousetweaks/Main.java @@ -1,10 +1,12 @@ package yalter.mousetweaks; import java.io.File; + 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; @@ -109,17 +111,14 @@ public class Main extends DeobfuscationLayer { disableForThisContainer = isDisabledForThisContainer(currentScreen); if (Constants.DEV_ENV) { - Constants.LOGGER.debug(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()); + Constants.LOGGER.debug( + 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); @@ -127,19 +126,19 @@ public class Main extends DeobfuscationLayer { if (guiContainerID == Constants.NOTGUICONTAINER) return; - if ((Main.DisableRMBTweak || (Main.RMBTweak == 0)) - && (Main.LMBTweakWithoutItem == 0) + if ((Main.DisableRMBTweak || (Main.RMBTweak == 0)) && (Main.LMBTweakWithoutItem == 0) && (Main.LMBTweakWithItem == 0) - && (Main.WheelTweak == 0)) return; + && (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 + 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; + return; int wheel = ((Main.WheelTweak == 1) && !disableWheelForThisContainer) ? Mouse.getDWheel() / 120 : 0; @@ -188,10 +187,9 @@ public class Main extends DeobfuscationLayer { } if (Constants.DEV_ENV) { - Constants.LOGGER.debug(new StringBuilder() - .append("You have selected a new slot, it's slot number is ") - .append(getSlotNumber(selectedSlot)) - .toString()); + Constants.LOGGER.debug( + 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); @@ -199,8 +197,7 @@ public class Main extends DeobfuscationLayer { if (Mouse.isButtonDown(1)) { // Right mouse button if ((Main.RMBTweak == 1) && !Main.DisableRMBTweak) { - if ((stackOnMouse != null) - && areStacksCompatible(stackOnMouse, targetStack) + if ((stackOnMouse != null) && areStacksCompatible(stackOnMouse, targetStack) && !isCraftingOutputSlot(currentScreen, selectedSlot)) { if ((firstSlot != null) && !firstSlotClicked) { firstSlotClicked = true; @@ -260,11 +257,9 @@ public class Main extends DeobfuscationLayer { ItemStack originalStack = getSlotStack(selectedSlot); boolean isCraftingOutput = isCraftingOutputSlot(currentScreen, selectedSlot); - if ((originalStack != null) - && ((stackOnMouse == null) - || (isCraftingOutput - ? areStacksCompatible(originalStack, stackOnMouse) - : !areStacksCompatible(originalStack, stackOnMouse)))) { + if ((originalStack != null) && ((stackOnMouse == null) + || (isCraftingOutput ? areStacksCompatible(originalStack, stackOnMouse) + : !areStacksCompatible(originalStack, stackOnMouse)))) { do { Slot applicableSlot = null; @@ -281,8 +276,7 @@ public class Main extends DeobfuscationLayer { ItemStack stackSl = getSlotStack(sl); if (stackSl == null) { - if ((applicableSlot == null) - && (wheel < 0) + if ((applicableSlot == null) && (wheel < 0) && sl.isItemValid(originalStack) && !isCraftingOutputSlot(currentScreen, sl)) { applicableSlot = sl; @@ -337,16 +331,15 @@ public class Main extends DeobfuscationLayer { 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 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)) { + if ((stackTo != null) && ((getMaxItemStackSize(stackTo) - getItemStackSize(stackTo)) + <= numItemsToMove)) { clickSlot(currentScreen, slotFrom, 0, false); clickSlot(currentScreen, slotTo, 0, false); clickSlot(currentScreen, slotFrom, 0, false); @@ -405,11 +398,11 @@ public class Main extends DeobfuscationLayer { } public static int getGuiContainerID(GuiScreen currentScreen) { - int containerID = ModCompatibility.getModGuiContainerID( - currentScreen); // This first because a lot of mod containers extend the vanilla Minecraft one. + 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 + return (isGuiContainer(currentScreen) && isValidGuiContainer(currentScreen)) ? Constants.MINECRAFT : Constants.NOTGUICONTAINER; else return containerID; } @@ -420,8 +413,7 @@ public class Main extends DeobfuscationLayer { } public static int getSlotCountWithID(GuiScreen currentScreen) { - if (guiContainerID == Constants.MINECRAFT) - return getSlots(asContainer(container)).size(); + if (guiContainerID == Constants.MINECRAFT) return getSlots(asContainer(container)).size(); else return ModCompatibility.getModSlotCount(guiContainerID, currentScreen, container); } @@ -458,10 +450,13 @@ public class Main extends DeobfuscationLayer { 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); + getWindowId(asContainer(container)), + getSlotNumber(targetSlot), + mouseButton, + shiftPressed ? 1 : 0); } else { - ModCompatibility.modClickSlot( - guiContainerID, currentScreen, container, targetSlot, mouseButton, shiftPressed); + ModCompatibility + .modClickSlot(guiContainerID, currentScreen, container, targetSlot, mouseButton, shiftPressed); } } diff --git a/src/main/java/yalter/mousetweaks/ModCompatibility.java b/src/main/java/yalter/mousetweaks/ModCompatibility.java index 111afe8..d4aa1a8 100644 --- a/src/main/java/yalter/mousetweaks/ModCompatibility.java +++ b/src/main/java/yalter/mousetweaks/ModCompatibility.java @@ -2,9 +2,11 @@ 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; @@ -41,7 +43,8 @@ public class ModCompatibility extends DeobfuscationLayer { return Constants.CODECHICKENCORE; if ((NEIInstalled && (Reflection.NEI.isInstance("GuiRecipe", guiScreen))) - || Reflection.NEI.isInstance("GuiEnchantmentModifier", guiScreen)) return Constants.NEI; + || Reflection.NEI.isInstance("GuiEnchantmentModifier", guiScreen)) + return Constants.NEI; return Constants.NOTGUICONTAINER; } @@ -88,15 +91,15 @@ public class ModCompatibility extends DeobfuscationLayer { } } - public static boolean modIsCraftingOutputSlot( - int modGuiContainerID, GuiScreen guiScreen, Object modContainer, Slot selectedSlot) { + 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))) + && ((getSlotNumber(selectedSlot) == 9) || (getSlotNumber(selectedSlot) == 11))) || (Reflection.is(modContainer, "ContainerMoistener") && (getSlotNumber(selectedSlot) == 9)) || (Reflection.is(modContainer, "ContainerCentrifuge") && ((getSlotNumber(selectedSlot) >= 1) && (getSlotNumber(selectedSlot) <= 9))) @@ -109,21 +112,16 @@ public class ModCompatibility extends DeobfuscationLayer { } } - public static void modClickSlot( - int modGuiContainerID, - GuiScreen guiScreen, - Object modContainer, - Slot targetSlot, - int mouseButton, - boolean shiftPressed) { + 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); + Reflection.forestry + .invokeMethod(guiScreen, "handleMouseClick", targetSlot, 0, mouseButton, shiftPressed ? 1 : 0); return; case Constants.NEI: @@ -139,15 +137,19 @@ public class ModCompatibility extends DeobfuscationLayer { } } - public static Slot getModSelectedSlot( - int modGuiContainerID, GuiScreen guiScreen, Object modContainer, int slotCount) { + 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())); + return asSlot( + Reflection.forestry.invokeMethod( + guiScreen, + "getSlotAtPosition", + getRequiredMouseX(), + getRequiredMouseY())); case Constants.NEI: return getSelectedSlot(asGuiContainer(guiScreen), asContainer(modContainer), slotCount); @@ -186,8 +188,8 @@ public class ModCompatibility extends DeobfuscationLayer { } } - public static void disableRMBDragIfRequired( - int guiContainerID, GuiScreen guiScreen, Object modContainer, Slot firstSlot, boolean shouldClick) { + 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); diff --git a/src/main/java/yalter/mousetweaks/Reflection.java b/src/main/java/yalter/mousetweaks/Reflection.java index 262cd6d..0e26f9d 100644 --- a/src/main/java/yalter/mousetweaks/Reflection.java +++ b/src/main/java/yalter/mousetweaks/Reflection.java @@ -3,6 +3,7 @@ package yalter.mousetweaks; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; + import net.minecraft.inventory.Slot; public class Reflection { @@ -28,7 +29,12 @@ public class Reflection { forestry.storeMethod("getSlotAtPosition", getSlotAtPositionMethod); Method handleMouseClickMethod = getMethod( - guiForestryClass, "handleMouseClick", Slot.class, int.class, int.class, int.class); + guiForestryClass, + "handleMouseClick", + Slot.class, + int.class, + int.class, + int.class); if (handleMouseClickMethod != null) { forestry.storeMethod("handleMouseClick", handleMouseClickMethod); @@ -123,8 +129,8 @@ public class Reflection { return field; } catch (Exception e) { if (name != "ofProfiler") { - Constants.LOGGER.error( - "Could not retrieve field \"" + name + "\" from class \"" + clazz.getName() + "\"", e); + Constants.LOGGER + .error("Could not retrieve field \"" + name + "\" from class \"" + clazz.getName() + "\"", e); } } @@ -153,8 +159,8 @@ public class Reflection { field.setAccessible(true); return field; } catch (Exception e) { - Constants.LOGGER.error( - "Could not retrieve field \"" + name + "\" from class \"" + clazz.getName() + "\"", e); + Constants.LOGGER + .error("Could not retrieve field \"" + name + "\" from class \"" + clazz.getName() + "\"", e); } return null; @@ -181,8 +187,8 @@ public class Reflection { method.setAccessible(true); return method; } catch (Exception e) { - Constants.LOGGER.error( - "Could not retrieve method \"" + name + "\" from class \"" + clazz.getName() + "\"", e); + Constants.LOGGER + .error("Could not retrieve method \"" + name + "\" from class \"" + clazz.getName() + "\"", e); } return null; @@ -190,7 +196,8 @@ public class Reflection { public static String methodToString(Method method) { return Modifier.toString(method.getModifiers()) + " " - + ((method.getReturnType() != null) ? method.getReturnType().getName() : "void") + " " + + ((method.getReturnType() != null) ? method.getReturnType().getName() : "void") + + " " + method.getName(); } } diff --git a/src/main/java/yalter/mousetweaks/ReflectionCache.java b/src/main/java/yalter/mousetweaks/ReflectionCache.java index e6401d4..4c9560a 100644 --- a/src/main/java/yalter/mousetweaks/ReflectionCache.java +++ b/src/main/java/yalter/mousetweaks/ReflectionCache.java @@ -5,6 +5,7 @@ import java.lang.reflect.Method; import java.util.HashMap; public class ReflectionCache { + public boolean available = false; public boolean compatible = false; public HashMap> classes = new HashMap<>(); diff --git a/src/main/java/yalter/mousetweaks/api/IMTModGuiContainer.java b/src/main/java/yalter/mousetweaks/api/IMTModGuiContainer.java index 490dc5d..ddf4749 100644 --- a/src/main/java/yalter/mousetweaks/api/IMTModGuiContainer.java +++ b/src/main/java/yalter/mousetweaks/api/IMTModGuiContainer.java @@ -1,6 +1,7 @@ package yalter.mousetweaks.api; public interface IMTModGuiContainer { + /** * Returns the API version. * @@ -39,14 +40,16 @@ public interface IMTModGuiContainer { 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. + * 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). + * 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. @@ -63,7 +66,8 @@ public interface IMTModGuiContainer { 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. + * 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. @@ -82,7 +86,9 @@ public interface IMTModGuiContainer { 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). + * 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. diff --git a/src/main/java/yalter/mousetweaks/loaders/MouseTweaksForge.java b/src/main/java/yalter/mousetweaks/loaders/MouseTweaksForge.java index 3b59b0e..7c26646 100644 --- a/src/main/java/yalter/mousetweaks/loaders/MouseTweaksForge.java +++ b/src/main/java/yalter/mousetweaks/loaders/MouseTweaksForge.java @@ -1,12 +1,12 @@ package yalter.mousetweaks.loaders; +import yalter.mousetweaks.Constants; +import yalter.mousetweaks.Main; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; -import yalter.mousetweaks.Constants; -import yalter.mousetweaks.Main; @Mod( modid = Constants.MOD_ID,