From 14de245b965cdc449628acfd04e7bcd1ff45daed Mon Sep 17 00:00:00 2001 From: Siphalor Date: Sun, 19 May 2019 16:46:54 +0200 Subject: [PATCH] Version 1.1.10 * Restructured a lot * Updated mappings + Added config --- build.gradle | 21 ++++- gradle.properties | 8 +- .../java/de/siphalor/mousewheelie/Core.java | 81 ------------------ ...{ClientFabricCore.java => ClientCore.java} | 9 +- .../siphalor/mousewheelie/client/Config.java | 38 +++++++++ .../client/InteractionManager.java | 83 +++++++++++++++++++ .../client/ModMenuEntryPoint.java | 19 +++++ .../mixin/MixinAbstractContainerScreen.java | 35 ++++---- .../mixin/MixinAbstractFurnaceScreen.java | 4 +- .../mixin/MixinClientPlayNetworkHandler.java | 6 +- .../client/mixin/MixinClientPlayerEntity.java | 4 +- .../mixin/MixinCraftingTableScreen.java | 4 +- .../mixin/MixinCreativeInventoryScreen.java | 12 +-- .../client/mixin/MixinInventoryScreen.java | 4 +- .../mousewheelie/client/mixin/MixinMouse.java | 6 +- .../client/mixin/MixinRecipeBookScreen.java | 10 +-- .../mousewheelie/client/mixin/MixinSlot.java | 2 +- .../util/FabricCreativeGuiHelper.java | 2 +- .../{ => client}/util/IContainerScreen.java | 2 +- .../{ => client}/util/IRecipeBookGui.java | 2 +- .../client/util/IScrollableRecipeBook.java | 5 ++ .../mousewheelie/{ => client}/util/ISlot.java | 2 +- .../util/ISpecialScrollableScreen.java | 2 +- .../{ => client}/util/InventorySorter.java | 22 ++--- .../mousewheelie/client/util/SortMode.java | 5 ++ .../util/IScrollableRecipeBook.java | 5 -- .../siphalor/mousewheelie/util/SortMode.java | 5 -- .../assets/mousewheelie/lang/en_us.json | 12 ++- src/main/resources/fabric.mod.json | 7 +- 29 files changed, 261 insertions(+), 156 deletions(-) rename src/main/java/de/siphalor/mousewheelie/client/{ClientFabricCore.java => ClientCore.java} (80%) create mode 100644 src/main/java/de/siphalor/mousewheelie/client/Config.java create mode 100644 src/main/java/de/siphalor/mousewheelie/client/InteractionManager.java create mode 100644 src/main/java/de/siphalor/mousewheelie/client/ModMenuEntryPoint.java rename src/main/java/de/siphalor/mousewheelie/{ => client}/util/FabricCreativeGuiHelper.java (95%) rename src/main/java/de/siphalor/mousewheelie/{ => client}/util/IContainerScreen.java (74%) rename src/main/java/de/siphalor/mousewheelie/{ => client}/util/IRecipeBookGui.java (74%) create mode 100644 src/main/java/de/siphalor/mousewheelie/client/util/IScrollableRecipeBook.java rename src/main/java/de/siphalor/mousewheelie/{ => client}/util/ISlot.java (56%) rename src/main/java/de/siphalor/mousewheelie/{ => client}/util/ISpecialScrollableScreen.java (76%) rename src/main/java/de/siphalor/mousewheelie/{ => client}/util/InventorySorter.java (87%) create mode 100644 src/main/java/de/siphalor/mousewheelie/client/util/SortMode.java delete mode 100644 src/main/java/de/siphalor/mousewheelie/util/IScrollableRecipeBook.java delete mode 100644 src/main/java/de/siphalor/mousewheelie/util/SortMode.java diff --git a/build.gradle b/build.gradle index c06ffb36..ed426891 100644 --- a/build.gradle +++ b/build.gradle @@ -7,12 +7,24 @@ sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 archivesBaseName = project.archives_base_name -version = project.mod_version +version = project.mod_version + "+" + project.minecraft_version group = project.maven_group minecraft { } +repositories { + mavenLocal() + maven { + name "jitpack" + url "https://jitpack.io" + } + maven { + name "curseforge" + url "https://minecraft.curseforge.com/api/maven" + } +} + dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -25,6 +37,13 @@ dependencies { include "net.fabricmc.fabric-api:fabric-resource-loader:+" modCompile "net.fabricmc.fabric-api:fabric-item-groups:+" + modCompile "io.github.prospector.modmenu:ModMenu:+" + + modCompile "com.github.siphalor:tweed-api:${project.tweed_version}" + include "com.github.siphalor:tweed-api:${project.tweed_version}" + + include "cloth-config:ClothConfig:${project.clothconfig_version}" + modCompile "cloth-config:ClothConfig:${project.clothconfig_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index dbd890d3..c2979088 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,11 +4,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use minecraft_version=1.14.2 Pre-Release 2 - yarn_build=+ + yarn_build=2 loader_version=0.4.7+build.147 # Mod Properties mod_id = mousewheelie - mod_version = 1.1.9+1.14.1 + mod_version = 1.1.10 maven_group = de.siphalor archives_base_name = mousewheelie + +# Dependencies + tweed_version = 2.1.0-beta.3 + clothconfig_version = 0.2.1.14 diff --git a/src/main/java/de/siphalor/mousewheelie/Core.java b/src/main/java/de/siphalor/mousewheelie/Core.java index 59accbff..1492fc76 100644 --- a/src/main/java/de/siphalor/mousewheelie/Core.java +++ b/src/main/java/de/siphalor/mousewheelie/Core.java @@ -1,86 +1,5 @@ package de.siphalor.mousewheelie; -import net.minecraft.client.MinecraftClient; -import net.minecraft.container.SlotActionType; -import net.minecraft.network.Packet; - -import java.util.ArrayDeque; - public class Core { public static final String MOD_ID = "mousewheelie"; - public static int scrollFactor = -1; - - public static ArrayDeque interactionEventQueue = new ArrayDeque<>(); - public static boolean sending = false; - - public static void push(InteractionEvent interactionEvent) { - interactionEventQueue.add(interactionEvent); - if(!sending) - triggerSend(); - } - - public static void pushClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) { - ClickEvent clickEvent = new ClickEvent(containerSyncId, slotId, buttonId, slotAction); - push(clickEvent); - } - - public static void triggerSend() { - if(interactionEventQueue.size() > 0) { - while(interactionEventQueue.pop().send()) { - if(interactionEventQueue.isEmpty()) { - sending = false; - break; - } - } - } else - sending = false; - } - - public static void stopSending() { - sending = false; - interactionEventQueue.clear(); - } - - public interface InteractionEvent { - /** - * Sends the interaction to the server - * @return a boolean determining whether to continue sending packets - */ - boolean send(); - } - - public static class ClickEvent implements InteractionEvent { - private int containerSyncId; - private int slotId; - private int buttonId; - private SlotActionType slotAction; - - public ClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) { - this.containerSyncId = containerSyncId; - this.slotId = slotId; - this.buttonId = buttonId; - this.slotAction = slotAction; - } - - @Override - public boolean send() { - sending = true; - MinecraftClient.getInstance().interactionManager.method_2906(containerSyncId, slotId, buttonId, slotAction, MinecraftClient.getInstance().player); - return false; - } - } - - public static class PacketEvent implements InteractionEvent { - private Packet packet; - - public PacketEvent(Packet packet) { - this.packet = packet; - } - - @Override - public boolean send() { - MinecraftClient.getInstance().getNetworkHandler().sendPacket(packet); - return true; - } - } } diff --git a/src/main/java/de/siphalor/mousewheelie/client/ClientFabricCore.java b/src/main/java/de/siphalor/mousewheelie/client/ClientCore.java similarity index 80% rename from src/main/java/de/siphalor/mousewheelie/client/ClientFabricCore.java rename to src/main/java/de/siphalor/mousewheelie/client/ClientCore.java index 6d569ebf..aa217aa1 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/ClientFabricCore.java +++ b/src/main/java/de/siphalor/mousewheelie/client/ClientCore.java @@ -1,21 +1,28 @@ package de.siphalor.mousewheelie.client; import de.siphalor.mousewheelie.Core; +import de.siphalor.tweed.client.TweedClothBridge; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; import net.minecraft.client.util.InputUtil; import net.minecraft.util.Identifier; -public class ClientFabricCore implements ClientModInitializer { +public class ClientCore implements ClientModInitializer { public static final String KEY_BINDING_CATEGORY = "key.categories." + Core.MOD_ID; public static final FabricKeyBinding SORT_KEY_BINDING = FabricKeyBinding.Builder.create(new Identifier(Core.MOD_ID, "sort_inventory"), InputUtil.Type.KEYSYM, -1, KEY_BINDING_CATEGORY).build(); // TODO public static final FabricKeyBinding FILL_INVENTORY_KEY_BINDING = FabricKeyBinding.Builder.create(new Identifier(Core.MOD_ID, "fill_inventory"), InputUtil.Type.KEYSYM, 71, KEY_BINDING_CATEGORY).build(); + public static TweedClothBridge tweedClothBridge; + @Override public void onInitializeClient() { KeyBindingRegistry.INSTANCE.addCategory(KEY_BINDING_CATEGORY); KeyBindingRegistry.INSTANCE.register(SORT_KEY_BINDING); + + Config.initialize(); + + tweedClothBridge = new TweedClothBridge(Config.configFile); } } diff --git a/src/main/java/de/siphalor/mousewheelie/client/Config.java b/src/main/java/de/siphalor/mousewheelie/client/Config.java new file mode 100644 index 00000000..07e46c65 --- /dev/null +++ b/src/main/java/de/siphalor/mousewheelie/client/Config.java @@ -0,0 +1,38 @@ +package de.siphalor.mousewheelie.client; + +import de.siphalor.mousewheelie.Core; +import de.siphalor.mousewheelie.client.util.SortMode; +import de.siphalor.tweed.config.ConfigCategory; +import de.siphalor.tweed.config.ConfigEnvironment; +import de.siphalor.tweed.config.ConfigFile; +import de.siphalor.tweed.config.TweedRegistry; +import de.siphalor.tweed.config.entry.EnumEntry; +import de.siphalor.tweed.config.entry.FloatEntry; + +@SuppressWarnings("unchecked") +public class Config { + public static ConfigFile configFile = TweedRegistry.registerConfigFile(Core.MOD_ID); + + public static ConfigCategory sortCategory = configFile.register("sort", new ConfigCategory()) + .setComment("Change sort modes. Existing sort modes are ALPHABET, RAW_ID and QUANTITY"); + public static EnumEntry primarySort = (EnumEntry) sortCategory.register("primary-sort", new EnumEntry<>(SortMode.RAW_ID)) + .setEnvironment(ConfigEnvironment.CLIENT) + .setComment("Sets the sort mode for sorting via middle mouse click.") + ; + public static EnumEntry shiftSort = (EnumEntry) sortCategory.register("shift-sort", new EnumEntry<>(SortMode.QUANTITY)) + .setEnvironment(ConfigEnvironment.CLIENT) + .setComment("Sets the sort mode for sorting via shift + middle mouse click."); + public static EnumEntry controlSort = (EnumEntry) sortCategory.register("control-sort", new EnumEntry<>(SortMode.ALPHABET)) + .setEnvironment(ConfigEnvironment.CLIENT) + .setComment("Sets the sort mode for sorting via control + middle mouse click."); + ; + + public static ConfigCategory generalCategory = configFile.register("general", new ConfigCategory()); + public static FloatEntry scrollFactor = generalCategory.register("scroll-factor", new FloatEntry(-1.0F)) + .setComment("Set the scroll factor for item scrolling." + System.lineSeparator() + + "To invert the scrolling use negative numbers"); + + public static void initialize() { + + } +} diff --git a/src/main/java/de/siphalor/mousewheelie/client/InteractionManager.java b/src/main/java/de/siphalor/mousewheelie/client/InteractionManager.java new file mode 100644 index 00000000..62613adb --- /dev/null +++ b/src/main/java/de/siphalor/mousewheelie/client/InteractionManager.java @@ -0,0 +1,83 @@ +package de.siphalor.mousewheelie.client; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.container.SlotActionType; +import net.minecraft.network.Packet; + +import java.util.ArrayDeque; + +public class InteractionManager { + public static ArrayDeque interactionEventQueue = new ArrayDeque<>(); + public static boolean sending = false; + + public static void push(InteractionEvent interactionEvent) { + interactionEventQueue.add(interactionEvent); + if(!sending) + triggerSend(); + } + + public static void pushClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) { + ClickEvent clickEvent = new ClickEvent(containerSyncId, slotId, buttonId, slotAction); + push(clickEvent); + } + + public static void triggerSend() { + if(interactionEventQueue.size() > 0) { + while(interactionEventQueue.pop().send()) { + if(interactionEventQueue.isEmpty()) { + sending = false; + break; + } + } + } else + sending = false; + } + + public static void stopSending() { + sending = false; + interactionEventQueue.clear(); + } + + public interface InteractionEvent { + /** + * Sends the interaction to the server + * @return a boolean determining whether to continue sending packets + */ + boolean send(); + } + + public static class ClickEvent implements InteractionEvent { + private int containerSyncId; + private int slotId; + private int buttonId; + private SlotActionType slotAction; + + public ClickEvent(int containerSyncId, int slotId, int buttonId, SlotActionType slotAction) { + this.containerSyncId = containerSyncId; + this.slotId = slotId; + this.buttonId = buttonId; + this.slotAction = slotAction; + } + + @Override + public boolean send() { + sending = true; + MinecraftClient.getInstance().interactionManager.method_2906(containerSyncId, slotId, buttonId, slotAction, MinecraftClient.getInstance().player); + return false; + } + } + + public static class PacketEvent implements InteractionEvent { + private Packet packet; + + public PacketEvent(Packet packet) { + this.packet = packet; + } + + @Override + public boolean send() { + MinecraftClient.getInstance().getNetworkHandler().sendPacket(packet); + return true; + } + } +} diff --git a/src/main/java/de/siphalor/mousewheelie/client/ModMenuEntryPoint.java b/src/main/java/de/siphalor/mousewheelie/client/ModMenuEntryPoint.java new file mode 100644 index 00000000..15e6f673 --- /dev/null +++ b/src/main/java/de/siphalor/mousewheelie/client/ModMenuEntryPoint.java @@ -0,0 +1,19 @@ +package de.siphalor.mousewheelie.client; + +import de.siphalor.mousewheelie.Core; +import io.github.prospector.modmenu.api.ModMenuApi; +import net.minecraft.client.gui.screen.Screen; + +import java.util.function.Function; + +public class ModMenuEntryPoint implements ModMenuApi { + @Override + public String getModId() { + return Core.MOD_ID; + } + + @Override + public Function getConfigScreenFactory() { + return screen -> ClientCore.tweedClothBridge.buildScreen(); + } +} diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractContainerScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractContainerScreen.java index 34342ead..1139b263 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractContainerScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractContainerScreen.java @@ -1,11 +1,12 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.Core; -import de.siphalor.mousewheelie.client.ClientFabricCore; -import de.siphalor.mousewheelie.util.IContainerScreen; -import de.siphalor.mousewheelie.util.ISlot; -import de.siphalor.mousewheelie.util.InventorySorter; -import de.siphalor.mousewheelie.util.SortMode; +import de.siphalor.mousewheelie.client.ClientCore; +import de.siphalor.mousewheelie.client.Config; +import de.siphalor.mousewheelie.client.InteractionManager; +import de.siphalor.mousewheelie.client.util.IContainerScreen; +import de.siphalor.mousewheelie.client.util.ISlot; +import de.siphalor.mousewheelie.client.util.InventorySorter; +import de.siphalor.mousewheelie.client.util.SortMode; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; @@ -58,21 +59,21 @@ public void onKeyPressed(int key, int scanCode, int int_3, CallbackInfoReturnabl putBack = true; if(!focusedSlot.getStack().isEmpty()) { swapStack = focusedSlot.getStack().copy(); - Core.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP); + InteractionManager.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP); } else if(offHandStack.isEmpty()) { return; } } - Core.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP); - Core.push(new Core.PacketEvent(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN))); - Core.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP); + InteractionManager.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP); + InteractionManager.push(new InteractionManager.PacketEvent(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, Direction.DOWN))); + InteractionManager.pushClickEvent(container.syncId, swapSlot.id, 0, SlotActionType.PICKUP); if(putBack) { - Core.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP); + InteractionManager.pushClickEvent(container.syncId, focusedSlot.id, 0, SlotActionType.PICKUP); } ItemStack finalSwapStack = swapStack; boolean finalPutBack = putBack; // Fix the display up since swapping items doesn't have a confirm packet so we have to trigger the click event too quick afterwards - Core.push(() -> { + InteractionManager.push(() -> { playerInventory.offHand.set(0, finalSwapStack); if(finalPutBack) { focusedSlot.setStack(offHandStack); @@ -84,7 +85,7 @@ public void onKeyPressed(int key, int scanCode, int int_3, CallbackInfoReturnabl return true; }); } else if(FabricLoader.getInstance().isModLoaded("fabric")) { - if(ClientFabricCore.SORT_KEY_BINDING.matchesKey(key, scanCode)) { + if(ClientCore.SORT_KEY_BINDING.matchesKey(key, scanCode)) { mouseWheelie_triggerSort(); } } @@ -116,7 +117,7 @@ public boolean mouseWheelie_onMouseScroll(double mouseX, double mouseY, double s return false; ItemStack hoveredStack = hoveredSlot.getStack(); boolean changeInventory; - boolean moveUp = scrollAmount * Core.scrollFactor < 0; + boolean moveUp = scrollAmount * Config.scrollFactor.value < 0; BiFunction slotsInSameScope; //noinspection ConstantConditions if((Screen) this instanceof InventoryScreen) { @@ -189,11 +190,11 @@ private boolean mouseWheelie_triggerSort() { InventorySorter sorter = new InventorySorter(container, focusedSlot); SortMode sortMode; if(hasShiftDown()) { - sortMode = SortMode.QUANTITY; + sortMode = Config.shiftSort.value; } else if(hasControlDown()) { - sortMode = SortMode.RAWID; + sortMode = Config.controlSort.value; } else { - sortMode = SortMode.ALPHABET; + sortMode = Config.primarySort.value; } sorter.sort(sortMode); return true; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractFurnaceScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractFurnaceScreen.java index 5e302816..039a4624 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractFurnaceScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinAbstractFurnaceScreen.java @@ -1,7 +1,7 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.util.IRecipeBookGui; -import de.siphalor.mousewheelie.util.IScrollableRecipeBook; +import de.siphalor.mousewheelie.client.util.IRecipeBookGui; +import de.siphalor.mousewheelie.client.util.IScrollableRecipeBook; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen; import net.minecraft.client.gui.screen.recipebook.AbstractFurnaceRecipeBookScreen; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayNetworkHandler.java index e3fc454f..ddb7a76c 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayNetworkHandler.java @@ -1,6 +1,6 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.Core; +import de.siphalor.mousewheelie.client.InteractionManager; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.packet.ConfirmGuiActionS2CPacket; import org.spongepowered.asm.mixin.Mixin; @@ -12,7 +12,7 @@ public class MixinClientPlayNetworkHandler { @Inject(method = "onGuiActionConfirm", at = @At("RETURN")) public void onGuiActionConfirmed(ConfirmGuiActionS2CPacket packet, CallbackInfo callbackInfo) { - if(Core.sending) - Core.triggerSend(); + if(InteractionManager.sending) + InteractionManager.triggerSend(); } } diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayerEntity.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayerEntity.java index 1c6f6596..fa67fa3d 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayerEntity.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinClientPlayerEntity.java @@ -1,7 +1,7 @@ package de.siphalor.mousewheelie.client.mixin; import com.mojang.authlib.GameProfile; -import de.siphalor.mousewheelie.Core; +import de.siphalor.mousewheelie.client.InteractionManager; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; @@ -18,6 +18,6 @@ public MixinClientPlayerEntity(ClientWorld clientWorld_1, GameProfile gameProfil @Inject(method = "closeScreen", at = @At("HEAD")) public void onScreenClosed(CallbackInfo callbackInfo) { - Core.stopSending(); + InteractionManager.stopSending(); } } diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCraftingTableScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCraftingTableScreen.java index 9b7dcc5b..fcaa682e 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCraftingTableScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCraftingTableScreen.java @@ -1,7 +1,7 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.util.IRecipeBookGui; -import de.siphalor.mousewheelie.util.IScrollableRecipeBook; +import de.siphalor.mousewheelie.client.util.IRecipeBookGui; +import de.siphalor.mousewheelie.client.util.IScrollableRecipeBook; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; import net.minecraft.client.gui.screen.ingame.CraftingTableScreen; import net.minecraft.client.gui.screen.recipebook.RecipeBookScreen; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCreativeInventoryScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCreativeInventoryScreen.java index 00f2a9ae..b0bca5e4 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCreativeInventoryScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinCreativeInventoryScreen.java @@ -1,9 +1,9 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.Core; -import de.siphalor.mousewheelie.util.FabricCreativeGuiHelper; -import de.siphalor.mousewheelie.util.IContainerScreen; -import de.siphalor.mousewheelie.util.ISpecialScrollableScreen; +import de.siphalor.mousewheelie.client.Config; +import de.siphalor.mousewheelie.client.util.FabricCreativeGuiHelper; +import de.siphalor.mousewheelie.client.util.IContainerScreen; +import de.siphalor.mousewheelie.client.util.ISpecialScrollableScreen; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; @@ -38,7 +38,7 @@ public boolean mouseWheelie_onMouseScrolledSpecial(double mouseX, double mouseY, if(mouseY < this.top + 4 || mouseY >= this.top + this.containerHeight - 4) { if(FabricLoader.getInstance().isModLoaded("fabric") || FabricLoader.getInstance().isModLoaded("fabric-item-groups")) { FabricCreativeGuiHelper helper = new FabricCreativeGuiHelper((CreativeInventoryScreen)(Object) this); - int newIndex = MathHelper.clamp(selectedTab + (int) Math.round(scrollAmount * Core.scrollFactor), 0, ItemGroup.GROUPS.length - 1); + int newIndex = MathHelper.clamp(selectedTab + (int) Math.round(scrollAmount * Config.scrollFactor.value), 0, ItemGroup.GROUPS.length - 1); int newPage = helper.getPageForTabIndex(newIndex); if(newPage < helper.getCurrentPage()) helper.previousPage(); @@ -46,7 +46,7 @@ public boolean mouseWheelie_onMouseScrolledSpecial(double mouseX, double mouseY, helper.nextPage(); setSelectedTab(ItemGroup.GROUPS[newIndex]); } else - setSelectedTab(ItemGroup.GROUPS[MathHelper.clamp((int) (selectedTab + Math.round(scrollAmount * Core.scrollFactor)), 0, ItemGroup.GROUPS.length - 1)]); + setSelectedTab(ItemGroup.GROUPS[MathHelper.clamp((int) (selectedTab + Math.round(scrollAmount * Config.scrollFactor.value)), 0, ItemGroup.GROUPS.length - 1)]); return false; } return false; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinInventoryScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinInventoryScreen.java index bec7d97e..e9435619 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinInventoryScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinInventoryScreen.java @@ -1,7 +1,7 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.util.IRecipeBookGui; -import de.siphalor.mousewheelie.util.IScrollableRecipeBook; +import de.siphalor.mousewheelie.client.util.IRecipeBookGui; +import de.siphalor.mousewheelie.client.util.IScrollableRecipeBook; import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.client.gui.screen.recipebook.RecipeBookScreen; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinMouse.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinMouse.java index f79b3f6b..62e02f89 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinMouse.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinMouse.java @@ -1,8 +1,8 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.util.IContainerScreen; -import de.siphalor.mousewheelie.util.IScrollableRecipeBook; -import de.siphalor.mousewheelie.util.ISpecialScrollableScreen; +import de.siphalor.mousewheelie.client.util.IContainerScreen; +import de.siphalor.mousewheelie.client.util.IScrollableRecipeBook; +import de.siphalor.mousewheelie.client.util.ISpecialScrollableScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.Mouse; import org.spongepowered.asm.mixin.Final; diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinRecipeBookScreen.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinRecipeBookScreen.java index d3f7bad8..e28b744c 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinRecipeBookScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinRecipeBookScreen.java @@ -1,7 +1,7 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.Core; -import de.siphalor.mousewheelie.util.IRecipeBookGui; +import de.siphalor.mousewheelie.client.Config; +import de.siphalor.mousewheelie.client.util.IRecipeBookGui; import net.minecraft.client.gui.screen.recipebook.RecipeBookResults; import net.minecraft.client.gui.screen.recipebook.RecipeBookScreen; import net.minecraft.client.gui.screen.recipebook.RecipeGroupButtonWidget; @@ -15,7 +15,7 @@ @Mixin(RecipeBookScreen.class) public abstract class MixinRecipeBookScreen implements IRecipeBookGui { - @Shadow protected RecipeBookResults recipesArea; + @Shadow @Final protected RecipeBookResults recipesArea; @Shadow private int parentWidth; @@ -42,12 +42,12 @@ public boolean mouseWheelie_scrollRecipeBook(double mouseX, double mouseY, doubl if(mouseX >= left && mouseX < left + 147) { // Ugly approach since assigning the casted value causes a runtime mixin error int maxPage = ((RecipeBookResultsAccessor) recipesArea).getPageCount() - 1; - ((RecipeBookResultsAccessor) recipesArea).setCurrentPage(MathHelper.clamp((int) (((RecipeBookResultsAccessor) recipesArea).getCurrentPage() + Math.round(scrollAmount * Core.scrollFactor)), 0, maxPage < 0 ? 0 : maxPage)); + ((RecipeBookResultsAccessor) recipesArea).setCurrentPage(MathHelper.clamp((int) (((RecipeBookResultsAccessor) recipesArea).getCurrentPage() + Math.round(scrollAmount * Config.scrollFactor.value)), 0, maxPage < 0 ? 0 : maxPage)); ((RecipeBookResultsAccessor) recipesArea).callRefreshResultButtons(); return true; } else if(mouseX >= left - 30 && mouseX < left) { int index = tabButtons.indexOf(currentTab); - int newIndex = MathHelper.clamp(index + (int) (Math.round(scrollAmount * Core.scrollFactor)), 0, tabButtons.size() - 1); + int newIndex = MathHelper.clamp(index + (int) (Math.round(scrollAmount * Config.scrollFactor.value)), 0, tabButtons.size() - 1); if(newIndex != index) { currentTab.setToggled(false); currentTab = tabButtons.get(newIndex); diff --git a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinSlot.java b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinSlot.java index 5108c1b1..f0f7e4c9 100644 --- a/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinSlot.java +++ b/src/main/java/de/siphalor/mousewheelie/client/mixin/MixinSlot.java @@ -1,6 +1,6 @@ package de.siphalor.mousewheelie.client.mixin; -import de.siphalor.mousewheelie.util.ISlot; +import de.siphalor.mousewheelie.client.util.ISlot; import net.minecraft.container.Slot; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/de/siphalor/mousewheelie/util/FabricCreativeGuiHelper.java b/src/main/java/de/siphalor/mousewheelie/client/util/FabricCreativeGuiHelper.java similarity index 95% rename from src/main/java/de/siphalor/mousewheelie/util/FabricCreativeGuiHelper.java rename to src/main/java/de/siphalor/mousewheelie/client/util/FabricCreativeGuiHelper.java index 932ac705..4c4c0e7e 100644 --- a/src/main/java/de/siphalor/mousewheelie/util/FabricCreativeGuiHelper.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/FabricCreativeGuiHelper.java @@ -1,4 +1,4 @@ -package de.siphalor.mousewheelie.util; +package de.siphalor.mousewheelie.client.util; import net.fabricmc.fabric.impl.itemgroup.CreativeGuiExtensions; import net.fabricmc.fabric.impl.itemgroup.FabricCreativeGuiComponents; diff --git a/src/main/java/de/siphalor/mousewheelie/util/IContainerScreen.java b/src/main/java/de/siphalor/mousewheelie/client/util/IContainerScreen.java similarity index 74% rename from src/main/java/de/siphalor/mousewheelie/util/IContainerScreen.java rename to src/main/java/de/siphalor/mousewheelie/client/util/IContainerScreen.java index faa413c6..7ef403e4 100644 --- a/src/main/java/de/siphalor/mousewheelie/util/IContainerScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/IContainerScreen.java @@ -1,4 +1,4 @@ -package de.siphalor.mousewheelie.util; +package de.siphalor.mousewheelie.client.util; public interface IContainerScreen { public boolean mouseWheelie_onMouseScroll(double mouseX, double mouseY, double scrollAmount); diff --git a/src/main/java/de/siphalor/mousewheelie/util/IRecipeBookGui.java b/src/main/java/de/siphalor/mousewheelie/client/util/IRecipeBookGui.java similarity index 74% rename from src/main/java/de/siphalor/mousewheelie/util/IRecipeBookGui.java rename to src/main/java/de/siphalor/mousewheelie/client/util/IRecipeBookGui.java index f5db6ce1..44ba3cc7 100644 --- a/src/main/java/de/siphalor/mousewheelie/util/IRecipeBookGui.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/IRecipeBookGui.java @@ -1,4 +1,4 @@ -package de.siphalor.mousewheelie.util; +package de.siphalor.mousewheelie.client.util; public interface IRecipeBookGui { public boolean mouseWheelie_scrollRecipeBook(double mouseX, double mouseY, double scrollAmount); diff --git a/src/main/java/de/siphalor/mousewheelie/client/util/IScrollableRecipeBook.java b/src/main/java/de/siphalor/mousewheelie/client/util/IScrollableRecipeBook.java new file mode 100644 index 00000000..66a6cb21 --- /dev/null +++ b/src/main/java/de/siphalor/mousewheelie/client/util/IScrollableRecipeBook.java @@ -0,0 +1,5 @@ +package de.siphalor.mousewheelie.client.util; + +public interface IScrollableRecipeBook { + boolean mouseWheelie_onMouseScrollRecipeBook(double mouseX, double mouseY, double scrollAmount); +} diff --git a/src/main/java/de/siphalor/mousewheelie/util/ISlot.java b/src/main/java/de/siphalor/mousewheelie/client/util/ISlot.java similarity index 56% rename from src/main/java/de/siphalor/mousewheelie/util/ISlot.java rename to src/main/java/de/siphalor/mousewheelie/client/util/ISlot.java index f1399705..496f08f4 100644 --- a/src/main/java/de/siphalor/mousewheelie/util/ISlot.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/ISlot.java @@ -1,4 +1,4 @@ -package de.siphalor.mousewheelie.util; +package de.siphalor.mousewheelie.client.util; public interface ISlot { int mouseWheelie_getInvSlot(); diff --git a/src/main/java/de/siphalor/mousewheelie/util/ISpecialScrollableScreen.java b/src/main/java/de/siphalor/mousewheelie/client/util/ISpecialScrollableScreen.java similarity index 76% rename from src/main/java/de/siphalor/mousewheelie/util/ISpecialScrollableScreen.java rename to src/main/java/de/siphalor/mousewheelie/client/util/ISpecialScrollableScreen.java index 3370f057..de6d292e 100644 --- a/src/main/java/de/siphalor/mousewheelie/util/ISpecialScrollableScreen.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/ISpecialScrollableScreen.java @@ -1,4 +1,4 @@ -package de.siphalor.mousewheelie.util; +package de.siphalor.mousewheelie.client.util; public interface ISpecialScrollableScreen { public boolean mouseWheelie_onMouseScrolledSpecial(double mouseX, double mouseY, double scrollAmount); diff --git a/src/main/java/de/siphalor/mousewheelie/util/InventorySorter.java b/src/main/java/de/siphalor/mousewheelie/client/util/InventorySorter.java similarity index 87% rename from src/main/java/de/siphalor/mousewheelie/util/InventorySorter.java rename to src/main/java/de/siphalor/mousewheelie/client/util/InventorySorter.java index 3e071e07..09f696f0 100644 --- a/src/main/java/de/siphalor/mousewheelie/util/InventorySorter.java +++ b/src/main/java/de/siphalor/mousewheelie/client/util/InventorySorter.java @@ -1,6 +1,6 @@ -package de.siphalor.mousewheelie.util; +package de.siphalor.mousewheelie.client.util; -import de.siphalor.mousewheelie.Core; +import de.siphalor.mousewheelie.client.InteractionManager; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.client.resource.language.I18n; @@ -54,13 +54,13 @@ private void collectSlots(Slot originSlot) { private void combineStacks() { ItemStack stack; - ArrayDeque clickEvents = new ArrayDeque<>(); + ArrayDeque clickEvents = new ArrayDeque<>(); for(int i = stacks.size() - 1; i >= 0; i--) { stack = stacks.get(i); if(stack.isEmpty()) continue; int stackSize = stack.getAmount(); if(stackSize >= stack.getItem().getMaxAmount()) continue; - clickEvents.add(new Core.ClickEvent(container.syncId, inventorySlots.get(i).id, 0, SlotActionType.PICKUP)); + clickEvents.add(new InteractionManager.ClickEvent(container.syncId, inventorySlots.get(i).id, 0, SlotActionType.PICKUP)); for(int j = 0; j < i; j++) { ItemStack targetStack = stacks.get(j); if(targetStack.isEmpty()) continue; @@ -70,7 +70,7 @@ private void combineStacks() { delta = Math.min(delta, stackSize); stackSize -= delta; targetStack.setAmount(targetStack.getAmount() + delta); - clickEvents.add(new Core.ClickEvent(container.syncId, inventorySlots.get(j).id, 0, SlotActionType.PICKUP)); + clickEvents.add(new InteractionManager.ClickEvent(container.syncId, inventorySlots.get(j).id, 0, SlotActionType.PICKUP)); if(stackSize <= 0) break; } } @@ -78,11 +78,11 @@ private void combineStacks() { clickEvents.clear(); continue; } - Core.interactionEventQueue.addAll(clickEvents); - Core.triggerSend(); + InteractionManager.interactionEventQueue.addAll(clickEvents); + InteractionManager.triggerSend(); clickEvents.clear(); if(stackSize > 0) { - Core.pushClickEvent(container.syncId, inventorySlots.get(i).id, 0, SlotActionType.PICKUP); + InteractionManager.pushClickEvent(container.syncId, inventorySlots.get(i).id, 0, SlotActionType.PICKUP); stack.setAmount(stackSize); } else { stacks.set(i, ItemStack.EMPTY); @@ -146,7 +146,7 @@ public void sort(SortMode sortMode) { return Integer.compare(a2, a); }); break; - case RAWID: + case RAW_ID: Integer[] rawIds = inventorySlots.stream().map(slot -> slot.getStack().isEmpty() ? Integer.MAX_VALUE : Registry.ITEM.getRawId(slot.getStack().getItem())).toArray(Integer[]::new); sortIds.sort(Comparator.comparingInt(o -> rawIds[o])); break; @@ -166,11 +166,11 @@ public void sort(SortMode sortMode) { doneSlashEmpty.set(i); continue; } - Core.pushClickEvent(container.syncId, inventorySlots.get(sortIds.get(i)).id, 0, SlotActionType.PICKUP); + InteractionManager.pushClickEvent(container.syncId, inventorySlots.get(sortIds.get(i)).id, 0, SlotActionType.PICKUP); doneSlashEmpty.clear(slotCount + sortIds.get(i)); int id = i; while(!doneSlashEmpty.get(id)) { - Core.pushClickEvent(container.syncId, inventorySlots.get(id).id, 0, SlotActionType.PICKUP); + InteractionManager.pushClickEvent(container.syncId, inventorySlots.get(id).id, 0, SlotActionType.PICKUP); doneSlashEmpty.set(id); if(doneSlashEmpty.get(slotCount + id)) { doneSlashEmpty.set(slotCount + id); diff --git a/src/main/java/de/siphalor/mousewheelie/client/util/SortMode.java b/src/main/java/de/siphalor/mousewheelie/client/util/SortMode.java new file mode 100644 index 00000000..b81049c2 --- /dev/null +++ b/src/main/java/de/siphalor/mousewheelie/client/util/SortMode.java @@ -0,0 +1,5 @@ +package de.siphalor.mousewheelie.client.util; + +public enum SortMode { + ALPHABET, QUANTITY, RAW_ID +} diff --git a/src/main/java/de/siphalor/mousewheelie/util/IScrollableRecipeBook.java b/src/main/java/de/siphalor/mousewheelie/util/IScrollableRecipeBook.java deleted file mode 100644 index 8960fed7..00000000 --- a/src/main/java/de/siphalor/mousewheelie/util/IScrollableRecipeBook.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.siphalor.mousewheelie.util; - -public interface IScrollableRecipeBook { - public boolean mouseWheelie_onMouseScrollRecipeBook(double mouseX, double mouseY, double scrollAmount); -} diff --git a/src/main/java/de/siphalor/mousewheelie/util/SortMode.java b/src/main/java/de/siphalor/mousewheelie/util/SortMode.java deleted file mode 100644 index 8ee764f9..00000000 --- a/src/main/java/de/siphalor/mousewheelie/util/SortMode.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.siphalor.mousewheelie.util; - -public enum SortMode { - ALPHABET, QUANTITY, RAWID -} diff --git a/src/main/resources/assets/mousewheelie/lang/en_us.json b/src/main/resources/assets/mousewheelie/lang/en_us.json index 3810ccaa..a3845ba5 100644 --- a/src/main/resources/assets/mousewheelie/lang/en_us.json +++ b/src/main/resources/assets/mousewheelie/lang/en_us.json @@ -1,4 +1,14 @@ { "key.categories.mousewheelie": "Mouse Wheelie", - "key.mousewheelie.sort_inventory": "Sort Inventory" + "key.mousewheelie.sort_inventory": "Sort Inventory", + + "tweed.cloth.mousewheelie": "Mouse Wheelie Config", + + "tweed.cloth.mousewheelie.general": "General", + "tweed.cloth.mousewheelie.general.scroll-factor": "Scroll factor", + + "tweed.cloth.mousewheelie.sort": "Sorting", + "tweed.cloth.mousewheelie.sort.primary-sort": "Middle mouse click", + "tweed.cloth.mousewheelie.sort.shift-sort": "Shift + middle mouse click", + "tweed.cloth.mousewheelie.sort.control-sort": "Control + middle mouse click" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7c19f10f..1c8b0bbf 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,7 +28,12 @@ "entrypoints": { "client": [ { - "value": "de.siphalor.mousewheelie.client.ClientFabricCore" + "value": "de.siphalor.mousewheelie.client.ClientCore" + } + ], + "modmenu": [ + { + "value": "de.siphalor.mousewheelie.client.ModMenuEntryPoint" } ] },