From bbc8d1e9fb186d8ff2fd749ddd3220b95fe9f7ae Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sun, 4 Feb 2024 07:56:30 +0100 Subject: [PATCH] attempt to fix https://github.com/sebseb7/autotrade-fabric/issues/1#issuecomment-1925322642 --- gradle.properties | 2 +- .../github/sebseb7/autotrade/config/Configs.java | 4 +++- .../autotrade/event/KeybindCallbacks.java | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index bd02b6e..ef31a66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ mod_name = AutoTrade author = sebseb7 mod_file_name = autotrade-fabric -mod_version = 0.0.10 +mod_version = 0.0.11 malilib_version = 0.18.0 minecraft_version_min = 1.20.3 diff --git a/src/main/java/com/github/sebseb7/autotrade/config/Configs.java b/src/main/java/com/github/sebseb7/autotrade/config/Configs.java index 1f2e775..5bae4a6 100644 --- a/src/main/java/com/github/sebseb7/autotrade/config/Configs.java +++ b/src/main/java/com/github/sebseb7/autotrade/config/Configs.java @@ -55,11 +55,13 @@ public class Configs implements IConfigHandler { public static final ConfigBoolean VOID_TRADING_DELAY_AFTER_TELEPORT = new ConfigBoolean("delayAfterTeleport", true, "true: Start the delay after the villager was unloaded; false: Start the delay after the trade has been initiated"); + public static final ConfigInteger CONTAINER_CLOSE_DELAY = new ConfigInteger("containerCloseDelay", 0, 0, + 30000000, "delay in ticks; to get signal from trapped chest"); public static final ImmutableList OPTIONS = ImmutableList.of(ENABLED, ITEM_FRAME, GLASS_BLOCK, SELECTOR_OFFSET, ENABLE_SELL, SELL_ITEM, SELL_LIMIT, ENABLE_BUY, BUY_ITEM, BUY_LIMIT, MAX_INPUT_ITEMS, INPUT_CONTAINER_X, INPUT_CONTAINER_Y, INPUT_CONTAINER_Z, OUTPUT_CONTAINER_X, OUTPUT_CONTAINER_Y, - OUTPUT_CONTAINER_Z, VOID_TRADING_DELAY, VOID_TRADING_DELAY_AFTER_TELEPORT); + OUTPUT_CONTAINER_Z, VOID_TRADING_DELAY, VOID_TRADING_DELAY_AFTER_TELEPORT, CONTAINER_CLOSE_DELAY); } public static void loadFromFile() { diff --git a/src/main/java/com/github/sebseb7/autotrade/event/KeybindCallbacks.java b/src/main/java/com/github/sebseb7/autotrade/event/KeybindCallbacks.java index 12f7bb9..6769507 100644 --- a/src/main/java/com/github/sebseb7/autotrade/event/KeybindCallbacks.java +++ b/src/main/java/com/github/sebseb7/autotrade/event/KeybindCallbacks.java @@ -59,6 +59,7 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { private boolean outputOpened = false; private int tickCount = 0; private int voidDelay = 0; + private int containerDelay = 0; private int screenOpened = 0; public static KeybindCallbacks getInstance() { @@ -227,6 +228,11 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { return; } + if (containerDelay > 0) { + + containerDelay--; + } + if (this.functionalityEnabled() == false || mc.player == null) { return; } @@ -371,11 +377,11 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { if (GuiUtils.getCurrentScreen() instanceof ShulkerBoxScreen) { ShulkerBoxScreen screen = (ShulkerBoxScreen) GuiUtils.getCurrentScreen(); ShulkerBoxScreenHandler handler = screen.getScreenHandler(); - if (inputOpened) { + if ((containerDelay == 0) && inputOpened) { processInput(handler); screen.close(); } - if (outputOpened) { + if ((containerDelay == 0) && outputOpened) { processOutput(handler); screen.close(); } @@ -383,11 +389,11 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { if (GuiUtils.getCurrentScreen() instanceof GenericContainerScreen) { GenericContainerScreen screen = (GenericContainerScreen) GuiUtils.getCurrentScreen(); GenericContainerScreenHandler handler = screen.getScreenHandler(); - if (inputOpened) { + if ((containerDelay == 0) && inputOpened) { processInput(handler); screen.close(); } - if (outputOpened) { + if ((containerDelay == 0) && outputOpened) { processOutput(handler); screen.close(); } @@ -437,6 +443,7 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { inputInRange = true; ActionResult result = mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, new BlockHitResult(input.toCenterPos(), Direction.UP, input, false)); + containerDelay = Configs.Generic.CONTAINER_CLOSE_DELAY.getIntegerValue(); inputOpened = true; return; } @@ -444,6 +451,7 @@ public class KeybindCallbacks implements IHotkeyCallback, IClientTickHandler { outputInRange = true; ActionResult result = mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, new BlockHitResult(output.toCenterPos(), Direction.UP, output, false)); + containerDelay = Configs.Generic.CONTAINER_CLOSE_DELAY.getIntegerValue(); outputOpened = true; return; }