From 26d5e0f1308385bbe6db16405bc634e9f92bbc4a Mon Sep 17 00:00:00 2001 From: Andrew S Date: Wed, 18 Aug 2021 15:01:58 -0400 Subject: [PATCH] Remove packet limit and add masscraftmultiplier --- build.properties | 2 +- .../dy/masa/itemscroller/config/Configs.java | 6 +- .../masa/itemscroller/event/InputHandler.java | 15 -- .../itemscroller/event/KeybindCallbacks.java | 226 ++++++------------ .../event/RenderEventHandler.java | 8 - .../itemscroller/event/WorldLoadListener.java | 7 - .../MixinClientPlayerInteractionManager.java | 37 --- .../mixin/MixinCraftingScreenHandler.java | 1 - .../itemscroller/util/ClickPacketBuffer.java | 59 ----- .../itemscroller/util/InventoryUtils.java | 27 +-- src/main/resources/mixins.itemscroller.json | 1 - 11 files changed, 86 insertions(+), 303 deletions(-) delete mode 100644 src/main/java/fi/dy/masa/itemscroller/mixin/MixinClientPlayerInteractionManager.java delete mode 100644 src/main/java/fi/dy/masa/itemscroller/util/ClickPacketBuffer.java diff --git a/build.properties b/build.properties index f77ddd7eb..ac0aafd63 100644 --- a/build.properties +++ b/build.properties @@ -6,7 +6,7 @@ author = masa mod_file_name = itemscroller-fabric # Current mod version -mod_version = craftfix-1.2.5 +mod_version = craftfix-1.2.6 # Required malilib version malilib_version = 0.10.0-dev.23 diff --git a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java index bbb352fe2..aa409ac0a 100644 --- a/src/main/java/fi/dy/masa/itemscroller/config/Configs.java +++ b/src/main/java/fi/dy/masa/itemscroller/config/Configs.java @@ -31,10 +31,9 @@ public static class Generic public static final ConfigBoolean CRAFTING_RENDER_RECIPE_ITEMS = new ConfigBoolean("craftingRenderRecipeItems", true, "If enabled, then the recipe items are also rendered\nin the crafting recipe view."); public static final ConfigBoolean DROP_RECIPE_REMAINDER = new ConfigBoolean("dropRecipeRemainder", true, "If enabled, recipe remainders are dropped."); public static final ConfigBoolean DROP_NON_RECIPE_ITEMS = new ConfigBoolean("dropNonRecipeItems", false, "If enabled, non recipe items in crafting grid are dropped."); - public static final ConfigInteger PACKET_RATE_LIMIT = new ConfigInteger("packetRateLimit", 4, 1, 1024, "The limit of sent emulated slot click packets per game tick,\nif 'rateLimitClickPackets' is enabled"); + public static final ConfigInteger MASS_CRAFT_MULTIPLIER = new ConfigInteger("massCraftMultiplier", 1, 1, 50, "Specifies Masscraft operations per tick"); public static final ConfigBoolean SCROLL_CRAFT_STORE_RECIPES_TO_FILE = new ConfigBoolean("craftingRecipesSaveToFile", true, "If enabled, then the crafting features recipes are saved to a file\ninside minecraft/itemscroller/recipes_worldorservername.nbt.\nThis makes the recipes persistent across game restarts."); public static final ConfigBoolean SCROLL_CRAFT_RECIPE_FILE_GLOBAL = new ConfigBoolean("craftingRecipesSaveFileIsGlobal", false, "If true, then the recipe file is global, instead\n of being saved per-world or server"); - public static final ConfigBoolean RATE_LIMIT_CLICK_PACKETS = new ConfigBoolean("rateLimitClickPackets", false, "This is meant for compatibility with Spigot servers and similar,\nwhich apply rate limits to packets from the client.\nThis queues up the emulated slot click packets and sends\nthem rate limited over time. The limit per game tick can be set in 'packetRateLimit´."); public static final ConfigBoolean REVERSE_SCROLL_DIRECTION_SINGLE = new ConfigBoolean("reverseScrollDirectionSingle", false, "Reverse the scrolling direction for single item mode."); public static final ConfigBoolean REVERSE_SCROLL_DIRECTION_STACKS = new ConfigBoolean("reverseScrollDirectionStacks", false, "Reverse the scrolling direction for full stacks mode."); public static final ConfigBoolean SLOT_POSITION_AWARE_SCROLL_DIRECTION = new ConfigBoolean("useSlotPositionAwareScrollDirection", false, "When enabled, the item movement direction depends\non the slots' y-position on screen. Might be derpy with more\ncomplex inventories, use with caution!"); @@ -46,8 +45,7 @@ public static class Generic CRAFTING_RENDER_RECIPE_ITEMS, DROP_RECIPE_REMAINDER, DROP_NON_RECIPE_ITEMS, - PACKET_RATE_LIMIT, - RATE_LIMIT_CLICK_PACKETS, + MASS_CRAFT_MULTIPLIER, SCROLL_CRAFT_STORE_RECIPES_TO_FILE, SCROLL_CRAFT_RECIPE_FILE_GLOBAL, REVERSE_SCROLL_DIRECTION_SINGLE, diff --git a/src/main/java/fi/dy/masa/itemscroller/event/InputHandler.java b/src/main/java/fi/dy/masa/itemscroller/event/InputHandler.java index f998792a1..32e20979f 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/InputHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/InputHandler.java @@ -14,7 +14,6 @@ import fi.dy.masa.itemscroller.config.Hotkeys; import fi.dy.masa.itemscroller.recipes.RecipeStorage; import fi.dy.masa.itemscroller.util.AccessorUtils; -import fi.dy.masa.itemscroller.util.ClickPacketBuffer; import fi.dy.masa.itemscroller.util.InputUtils; import fi.dy.masa.itemscroller.util.InventoryUtils; import fi.dy.masa.itemscroller.util.MoveAction; @@ -108,15 +107,8 @@ public boolean onMouseClick(int mouseX, int mouseY, int eventButton, boolean eve private boolean handleInput(int keyCode, boolean keyState, double dWheel) { - if (Configs.Generic.RATE_LIMIT_CLICK_PACKETS.getBooleanValue()) - { - ClickPacketBuffer.setShouldBufferClickPackets(true); - } - boolean cancel = this.handleInputImpl(keyCode, keyState, dWheel); - ClickPacketBuffer.setShouldBufferClickPackets(false); - return cancel; } @@ -247,11 +239,6 @@ private boolean handleDragging(HandledScreen gui, MinecraftClient mc, int mou boolean cancel = false; MoveAction action = InventoryUtils.getActiveMoveAction(); - if (Configs.Generic.RATE_LIMIT_CLICK_PACKETS.getBooleanValue()) - { - ClickPacketBuffer.setShouldBufferClickPackets(true); - } - if (InputUtils.isActionKeyActive(action)) { cancel = InventoryUtils.dragMoveItems(gui, mc, action, mouseX, mouseY, false); @@ -261,8 +248,6 @@ else if (action != MoveAction.NONE) InventoryUtils.stopDragging(); } - ClickPacketBuffer.setShouldBufferClickPackets(false); - return cancel; } } diff --git a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java index ba4a744ff..8fac8506e 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/KeybindCallbacks.java @@ -16,7 +16,6 @@ import fi.dy.masa.itemscroller.recipes.RecipePattern; import fi.dy.masa.itemscroller.recipes.RecipeStorage; import fi.dy.masa.itemscroller.util.AccessorUtils; -import fi.dy.masa.itemscroller.util.ClickPacketBuffer; import fi.dy.masa.itemscroller.util.InputUtils; import fi.dy.masa.itemscroller.util.InventoryUtils; import fi.dy.masa.itemscroller.util.MoveAction; @@ -29,85 +28,61 @@ import fi.dy.masa.malilib.util.GuiUtils; import fi.dy.masa.malilib.hotkeys.KeyCallbackToggleBooleanConfigWithMessage; -public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler -{ +public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { private static final KeybindCallbacks INSTANCE = new KeybindCallbacks(); private boolean disabled; - public static KeybindCallbacks getInstance() - { + public static KeybindCallbacks getInstance() { return INSTANCE; } - private KeybindCallbacks() - { + private KeybindCallbacks() { } - public void setCallbacks() - { - for (ConfigHotkey hotkey : Hotkeys.HOTKEY_LIST) - { + public void setCallbacks() { + for (ConfigHotkey hotkey : Hotkeys.HOTKEY_LIST) { hotkey.getKeybind().setCallback(this); } - Hotkeys.KEY_MASS_CRAFT_TOGGLE.getKeybind().setCallback(new KeyCallbackToggleBooleanConfigWithMessage(Configs.Generic.MASS_CRAFT_HOLD)); + Hotkeys.KEY_MASS_CRAFT_TOGGLE.getKeybind() + .setCallback(new KeyCallbackToggleBooleanConfigWithMessage(Configs.Generic.MASS_CRAFT_HOLD)); } - public boolean functionalityEnabled() - { + public boolean functionalityEnabled() { return this.disabled == false; } @Override - public boolean onKeyAction(KeyAction action, IKeybind key) - { - if (Configs.Generic.RATE_LIMIT_CLICK_PACKETS.getBooleanValue()) - { - ClickPacketBuffer.setShouldBufferClickPackets(true); - } - + public boolean onKeyAction(KeyAction action, IKeybind key) { boolean cancel = this.onKeyActionImpl(action, key); - - ClickPacketBuffer.setShouldBufferClickPackets(false); - return cancel; } - private boolean onKeyActionImpl(KeyAction action, IKeybind key) - { + private boolean onKeyActionImpl(KeyAction action, IKeybind key) { MinecraftClient mc = MinecraftClient.getInstance(); - if (mc.player == null || mc.world == null) - { + if (mc.player == null || mc.world == null) { return false; } - if (key == Hotkeys.KEY_MAIN_TOGGLE.getKeybind()) - { - this.disabled = ! this.disabled; + if (key == Hotkeys.KEY_MAIN_TOGGLE.getKeybind()) { + this.disabled = !this.disabled; - if (this.disabled) - { + if (this.disabled) { mc.player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_BASS, 0.8f, 0.8f); - } - else - { + } else { mc.player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_PLING, 0.5f, 1.0f); } return true; - } - else if (key == Hotkeys.KEY_OPEN_CONFIG_GUI.getKeybind()) - { + } else if (key == Hotkeys.KEY_OPEN_CONFIG_GUI.getKeybind()) { GuiBase.openGui(new GuiConfigs()); return true; } - if (this.disabled || - (GuiUtils.getCurrentScreen() instanceof HandledScreen) == false || - Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName())) - { + if (this.disabled || (GuiUtils.getCurrentScreen() instanceof HandledScreen) == false + || Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName())) { return false; } @@ -116,167 +91,108 @@ else if (key == Hotkeys.KEY_OPEN_CONFIG_GUI.getKeybind()) RecipeStorage recipes = RecipeStorage.getInstance(); MoveAction moveAction = InputUtils.getDragMoveAction(key); - if (slot != null) - { - if (moveAction != MoveAction.NONE) - { + if (slot != null) { + if (moveAction != MoveAction.NONE) { final int mouseX = fi.dy.masa.malilib.util.InputUtils.getMouseX(); final int mouseY = fi.dy.masa.malilib.util.InputUtils.getMouseY(); return InventoryUtils.dragMoveItems(gui, mc, moveAction, mouseX, mouseY, true); - } - else if (key == Hotkeys.KEY_MOVE_EVERYTHING.getKeybind()) - { + } else if (key == Hotkeys.KEY_MOVE_EVERYTHING.getKeybind()) { InventoryUtils.tryMoveStacks(slot, gui, false, true, false); return true; - } - else if (key == Hotkeys.KEY_DROP_ALL_MATCHING.getKeybind()) - { - if (Configs.Toggles.DROP_MATCHING.getBooleanValue() && - Configs.GUI_BLACKLIST.contains(gui.getClass().getName()) == false && - slot.hasStack()) - { + } else if (key == Hotkeys.KEY_DROP_ALL_MATCHING.getKeybind()) { + if (Configs.Toggles.DROP_MATCHING.getBooleanValue() + && Configs.GUI_BLACKLIST.contains(gui.getClass().getName()) == false && slot.hasStack()) { InventoryUtils.dropStacks(gui, slot.getStack(), slot, true); return true; } - } - else if (key == Hotkeys.KEY_MOVE_STACK_TO_OFFHAND.getKeybind()) - { + } else if (key == Hotkeys.KEY_MOVE_STACK_TO_OFFHAND.getKeybind()) { // Swap the hovered stack to the Offhand - if ((gui instanceof InventoryScreen) && slot != null) - { + if ((gui instanceof InventoryScreen) && slot != null) { InventoryUtils.swapSlots(gui, slot.id, 45); return true; } } } - if (key == Hotkeys.KEY_CRAFT_EVERYTHING.getKeybind()) - { + if (key == Hotkeys.KEY_CRAFT_EVERYTHING.getKeybind()) { InventoryUtils.craftEverythingPossibleWithCurrentRecipe(recipes.getSelectedRecipe(), gui); return true; - } - else if (key == Hotkeys.KEY_THROW_CRAFT_RESULTS.getKeybind()) - { + } else if (key == Hotkeys.KEY_THROW_CRAFT_RESULTS.getKeybind()) { InventoryUtils.throwAllCraftingResultsToGround(recipes.getSelectedRecipe(), gui); return true; - } - else if (key == Hotkeys.KEY_MOVE_CRAFT_RESULTS.getKeybind()) - { + } else if (key == Hotkeys.KEY_MOVE_CRAFT_RESULTS.getKeybind()) { InventoryUtils.moveAllCraftingResultsToOtherInventory(recipes.getSelectedRecipe(), gui); return true; - } - else if (key == Hotkeys.KEY_STORE_RECIPE.getKeybind()) - { - if (InputUtils.isRecipeViewOpen() && InventoryUtils.isCraftingSlot(gui, slot)) - { + } else if (key == Hotkeys.KEY_STORE_RECIPE.getKeybind()) { + if (InputUtils.isRecipeViewOpen() && InventoryUtils.isCraftingSlot(gui, slot)) { recipes.storeCraftingRecipeToCurrentSelection(slot, gui, true); return true; } - } - else if (key == Hotkeys.KEY_VILLAGER_TRADE_FAVORITES.getKeybind()) - { + } else if (key == Hotkeys.KEY_VILLAGER_TRADE_FAVORITES.getKeybind()) { return InventoryUtils.villagerTradeEverythingPossibleWithAllFavoritedTrades(); - } - else if (key == Hotkeys.KEY_SLOT_DEBUG.getKeybind()) - { - if (slot != null) - { + } else if (key == Hotkeys.KEY_SLOT_DEBUG.getKeybind()) { + if (slot != null) { InventoryUtils.debugPrintSlotInfo(gui, slot); - } - else - { + } else { ItemScroller.logger.info("GUI class: {}", gui.getClass().getName()); } return true; } else if (key == Hotkeys.KEY_DUPE.getKeybind()) { - - if (GuiUtils.getCurrentScreen() instanceof HandledScreen && - (GuiUtils.getCurrentScreen() instanceof CreativeInventoryScreen) == false && - Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false) - { - Slot outputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); - - if (outputSlot != null) - { - InventoryUtils.dropStack(gui, outputSlot.id); + if (GuiUtils.getCurrentScreen() instanceof HandledScreen + && (GuiUtils.getCurrentScreen() instanceof CreativeInventoryScreen) == false + && Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false) { + + Slot outputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); + + if (outputSlot != null) { + InventoryUtils.dropStack(gui, outputSlot.id); + } + } - } - } return false; } @Override - public void onClientTick(MinecraftClient mc) - { - if (this.disabled || mc.player == null) - { - return; - } - - ClickPacketBuffer.sendBufferedPackets(Configs.Generic.PACKET_RATE_LIMIT.getIntegerValue()); - - if (ClickPacketBuffer.shouldCancelWindowClicks()) - { + public void onClientTick(MinecraftClient mc) { + if (this.disabled || mc.player == null) { return; } - if (GuiUtils.getCurrentScreen() instanceof HandledScreen && - (GuiUtils.getCurrentScreen() instanceof CreativeInventoryScreen) == false && - Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false && - (Hotkeys.KEY_MASS_CRAFT.getKeybind().isKeybindHeld() || Configs.Generic.MASS_CRAFT_HOLD.getBooleanValue())) - { + if (GuiUtils.getCurrentScreen() instanceof HandledScreen + && (GuiUtils.getCurrentScreen() instanceof CreativeInventoryScreen) == false + && Configs.GUI_BLACKLIST.contains(GuiUtils.getCurrentScreen().getClass().getName()) == false + && (Hotkeys.KEY_MASS_CRAFT.getKeybind().isKeybindHeld() + || Configs.Generic.MASS_CRAFT_HOLD.getBooleanValue())) { Screen guiScreen = GuiUtils.getCurrentScreen(); HandledScreen gui = (HandledScreen) guiScreen; Slot outputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); - - - - if (outputSlot != null) - { - if (Configs.Generic.RATE_LIMIT_CLICK_PACKETS.getBooleanValue()) - { - ClickPacketBuffer.setShouldBufferClickPackets(true); - } - - RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe(); - - // InventoryUtils.tryClearCursor(gui, mc); - //InventoryUtils.throwAllCraftingResultsToGround(recipe, gui); - - CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); - if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible - // System.out.println("recipe"); - mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); - } else { - //System.out.println("move"); - InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); - } - //System.out.println("output " + outputSlot.id); - //InventoryUtils.dropStacksWhileHasItem(gui, outputSlot.id, recipe.getResult()); - - for (int i = 0; i < recipe.getResult().getMaxCount(); i++) - { - InventoryUtils.dropStack(gui, outputSlot.id); + if (outputSlot != null) { + for (int j = 0; j < Configs.Generic.MASS_CRAFT_MULTIPLIER.getIntegerValue(); j++) { + RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe(); + + CraftingRecipe bookRecipe = InventoryUtils.getBookRecipeFromPattern(recipe); + if (bookRecipe != null && !bookRecipe.isIgnoredInRecipeBook()) { // Use recipe book if possible + // System.out.println("recipe"); + mc.interactionManager.clickRecipe(gui.getScreenHandler().syncId, bookRecipe, true); + } else { + // System.out.println("move"); + InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); + } + + for (int i = 0; i < recipe.getResult().getMaxCount(); i++) { + InventoryUtils.dropStack(gui, outputSlot.id); + } + + InventoryUtils.tryClearCursor(gui, mc); + InventoryUtils.throwAllCraftingResultsToGround(recipe, gui); } - - - InventoryUtils.tryClearCursor(gui, mc); - InventoryUtils.throwAllCraftingResultsToGround(recipe, gui); - - - - //InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, true); - - - ClickPacketBuffer.setShouldBufferClickPackets(false); } - } } } diff --git a/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java b/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java index a823a9356..c9aff1aab 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java @@ -11,7 +11,6 @@ import fi.dy.masa.itemscroller.recipes.RecipePattern; import fi.dy.masa.itemscroller.recipes.RecipeStorage; import fi.dy.masa.itemscroller.util.AccessorUtils; -import fi.dy.masa.itemscroller.util.ClickPacketBuffer; import fi.dy.masa.itemscroller.util.InputUtils; import fi.dy.masa.itemscroller.util.InventoryUtils; import fi.dy.masa.malilib.render.InventoryOverlay; @@ -93,13 +92,6 @@ public void onDrawScreenPost(MinecraftClient mc) { HandledScreen gui = (HandledScreen) this.mc.currentScreen; - int bufferedCount = ClickPacketBuffer.getBufferedActionsCount(); - - if (bufferedCount > 0) - { - mc.textRenderer.draw(FRESH_MATRIX_STACK, "Buffered slot clicks: " + bufferedCount, 10, 10, 0xFFD0D0D0); - } - if (InputUtils.isRecipeViewOpen() == false) { return; diff --git a/src/main/java/fi/dy/masa/itemscroller/event/WorldLoadListener.java b/src/main/java/fi/dy/masa/itemscroller/event/WorldLoadListener.java index 67adf9cae..ef3f15807 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/WorldLoadListener.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/WorldLoadListener.java @@ -5,7 +5,6 @@ import net.minecraft.client.world.ClientWorld; import fi.dy.masa.itemscroller.config.Configs; import fi.dy.masa.itemscroller.recipes.RecipeStorage; -import fi.dy.masa.itemscroller.util.ClickPacketBuffer; import fi.dy.masa.itemscroller.villager.VillagerDataStorage; import fi.dy.masa.malilib.interfaces.IWorldLoadListener; @@ -31,12 +30,6 @@ public void onWorldLoadPost(@Nullable ClientWorld worldBefore, @Nullable ClientW this.readStoredData(); VillagerDataStorage.getInstance().readFromDisk(); } - - // Logging out - if (worldAfter == null) - { - ClickPacketBuffer.reset(); - } } private void writeData() diff --git a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinClientPlayerInteractionManager.java b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinClientPlayerInteractionManager.java deleted file mode 100644 index 621f2337f..000000000 --- a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinClientPlayerInteractionManager.java +++ /dev/null @@ -1,37 +0,0 @@ -package fi.dy.masa.itemscroller.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.network.Packet; -import fi.dy.masa.itemscroller.util.ClickPacketBuffer; - -@Mixin(ClientPlayerInteractionManager.class) -public class MixinClientPlayerInteractionManager -{ - @Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true) - private void cancelWindowClicksWhileReplayingBufferedPackets(CallbackInfo ci) - { - if (ClickPacketBuffer.shouldCancelWindowClicks()) - { - ci.cancel(); - } - } - - @Redirect(method = "clickSlot", at = @At(value = "INVOKE", - target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V")) - private void bufferClickPacketsAndCancel(ClientPlayNetworkHandler netHandler, Packet packet) - { - if (ClickPacketBuffer.shouldBufferClickPackets()) - { - ClickPacketBuffer.bufferPacket(packet); - return; - } - - netHandler.sendPacket(packet); - } -} diff --git a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java index 6c0da1e15..2e57298d6 100644 --- a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java @@ -11,7 +11,6 @@ import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.screen.ScreenHandler; import net.minecraft.world.World; -import fi.dy.masa.itemscroller.util.InventoryUtils; @Mixin(net.minecraft.screen.CraftingScreenHandler.class) public abstract class MixinCraftingScreenHandler diff --git a/src/main/java/fi/dy/masa/itemscroller/util/ClickPacketBuffer.java b/src/main/java/fi/dy/masa/itemscroller/util/ClickPacketBuffer.java deleted file mode 100644 index 3fa989159..000000000 --- a/src/main/java/fi/dy/masa/itemscroller/util/ClickPacketBuffer.java +++ /dev/null @@ -1,59 +0,0 @@ -package fi.dy.masa.itemscroller.util; - -import java.util.ArrayList; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.network.Packet; - -public class ClickPacketBuffer -{ - private static final ArrayList> BUFFER = new ArrayList<>(); - private static boolean shouldBufferPackets; - - public static void reset() - { - shouldBufferPackets = false; - BUFFER.clear(); - } - - public static int getBufferedActionsCount() - { - return BUFFER.size(); - } - - public static boolean shouldBufferClickPackets() - { - return shouldBufferPackets; - } - - public static boolean shouldCancelWindowClicks() - { - // Don't cancel the clicks on the client if we have some Item Scroller actions in progress - return shouldBufferPackets == false && BUFFER.isEmpty() == false; - } - - public static void setShouldBufferClickPackets(boolean shouldBuffer) - { - shouldBufferPackets = shouldBuffer; - } - - public static void bufferPacket(Packet packet) - { - BUFFER.add(packet); - } - - public static void sendBufferedPackets(int maxCount) - { - ClientPlayerEntity player = MinecraftClient.getInstance().player; - - if (player != null && BUFFER.isEmpty() == false) - { - maxCount = Math.min(maxCount, BUFFER.size()); - - for (int i = 0; i < maxCount; ++i) - { - player.networkHandler.sendPacket(BUFFER.remove(0)); - } - } - } -} diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 27b29f86d..2c3a5c93d 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -9,19 +9,28 @@ import java.util.Map; import java.util.Optional; import java.util.Set; + import javax.annotation.Nullable; + +import fi.dy.masa.itemscroller.ItemScroller; +import fi.dy.masa.itemscroller.config.Configs; +import fi.dy.masa.itemscroller.config.Hotkeys; +import fi.dy.masa.itemscroller.recipes.CraftingHandler; +import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange; +import fi.dy.masa.itemscroller.recipes.RecipePattern; +import fi.dy.masa.itemscroller.recipes.RecipeStorage; +import fi.dy.masa.itemscroller.villager.VillagerDataStorage; +import fi.dy.masa.itemscroller.villager.VillagerUtils; +import fi.dy.masa.malilib.util.GuiUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; import net.minecraft.client.gui.screen.ingame.MerchantScreen; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.CraftingInventory; -import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -39,18 +48,6 @@ import net.minecraft.util.registry.Registry; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOfferList; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import fi.dy.masa.itemscroller.ItemScroller; -import fi.dy.masa.itemscroller.config.Configs; -import fi.dy.masa.itemscroller.config.Hotkeys; -import fi.dy.masa.itemscroller.recipes.CraftingHandler; -import fi.dy.masa.itemscroller.recipes.CraftingHandler.SlotRange; -import fi.dy.masa.itemscroller.recipes.RecipePattern; -import fi.dy.masa.itemscroller.recipes.RecipeStorage; -import fi.dy.masa.itemscroller.villager.VillagerDataStorage; -import fi.dy.masa.itemscroller.villager.VillagerUtils; -import fi.dy.masa.malilib.util.GuiUtils; public class InventoryUtils { private static MoveAction activeMoveAction = MoveAction.NONE; diff --git a/src/main/resources/mixins.itemscroller.json b/src/main/resources/mixins.itemscroller.json index 1eae0cf65..6e15f0c8b 100644 --- a/src/main/resources/mixins.itemscroller.json +++ b/src/main/resources/mixins.itemscroller.json @@ -8,7 +8,6 @@ "IMixinScreenWithHandler", "IMixinSlot", "MixinAbstractInventoryScreen", - "MixinClientPlayerInteractionManager", "MixinCraftingScreenHandler", "MixinGameRenderer", "MixinMerchantScreen",