From 8fd38b968a9a3cc92c4632f65301f7718d97d1bb Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:33:57 +0100 Subject: [PATCH 1/7] chore: update ldlib to 1.0.24.a --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index c098b50ebb..16f164c495 100644 --- a/settings.gradle +++ b/settings.gradle @@ -43,7 +43,7 @@ dependencyResolutionManagement { def vineFlowerVersion = "1.+" def macheteVersion = "1.+" def configurationVersion = "2.2.0" - def ldLibVersion = "1.0.23.a" + def ldLibVersion = "1.0.24.a" def mixinextrasVersion = "0.2.0" def shimmerVersion = "0.2.2" From 4f53e7546f75839b4fd2433713e4f7643d0f4825 Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:49:50 +0100 Subject: [PATCH 2/7] refactor: remove async recipe searching --- .../gtceu/api/machine/trait/RecipeLogic.java | 51 ++----------------- .../gtceu/config/ConfigHolder.java | 3 -- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java index 55cdfe6f60..d3a23276d1 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeLogic.java @@ -75,10 +75,6 @@ public enum Status { protected long totalContinuousRunningTime; protected TickableSubscription subscription; protected Object workingSound; - @Nullable - protected CompletableFuture completableFuture = null; - // if storage is dirty while async searching recipe, it will be set to true. - protected boolean dirtySearching = false; public RecipeLogic(IRecipeLogicMachine machine) { super(machine.self()); @@ -126,9 +122,6 @@ public void updateTickSubscription() { } } else { subscription = getMachine().subscribeServerTick(subscription, this::serverTick); - if (completableFuture != null) { - dirtySearching = true; - } } } @@ -176,11 +169,7 @@ public void serverTick() { boolean unsubscribe = false; if (isSuspend()) { unsubscribe = true; - if (completableFuture != null) { - completableFuture.cancel(true); - completableFuture = null; - } - } else if (completableFuture == null && lastRecipe == null && isIdle() && !machine.keepSubscribing() && !recipeDirty && lastFailedMatches == null) { + } else if (lastRecipe == null && isIdle() && !machine.keepSubscribing() && !recipeDirty && lastFailedMatches == null) { // machine isn't working enabled // or // there is no available recipes, so it will wait for notification. @@ -270,48 +259,19 @@ public void findAndHandleRecipe() { } else { // try to find and handle a new recipe lastRecipe = null; lastOriginRecipe = null; - if (completableFuture == null) { - // try to search recipe in threads. - if (ConfigHolder.INSTANCE.machines.asyncRecipeSearching) { - completableFuture = supplyAsyncSearchingTask(); - } else { - handleSearchingRecipes(searchRecipe()); - } - dirtySearching = false; - } else if (completableFuture.isDone()) { - var lastFuture = this.completableFuture; - completableFuture = null; - if (!lastFuture.isCancelled()) { - // if searching task is done, try to handle searched recipes. - try { - boolean matches = lastFuture.join(); - if (!matches && dirtySearching) { - completableFuture = supplyAsyncSearchingTask(); - } - } catch (Throwable throwable) { - // if error occurred, schedule a new async task. - completableFuture = supplyAsyncSearchingTask(); - } - } else { - handleSearchingRecipes(searchRecipe()); - } - dirtySearching = false; - } + handleSearchingRecipes(searchRecipe()); } recipeDirty = false; } - private CompletableFuture supplyAsyncSearchingTask() { - return CompletableFuture.supplyAsync(Util.wrapThreadWithTaskName("GTCEu Recipe Search", () -> handleSearchingRecipes(searchRecipe())), Util.backgroundExecutor()); - } - - private boolean handleSearchingRecipes(Iterator matches) { + private void handleSearchingRecipes(Iterator matches) { while (matches != null && matches.hasNext()) { GTRecipe match = matches.next(); if (match == null) continue; // If a new recipe was found, cache found recipe. - if (checkMatchedRecipeAvailable(match)) return true; + if (checkMatchedRecipeAvailable(match)) + return; // cache matching recipes. if (lastFailedMatches == null) { @@ -319,7 +279,6 @@ private boolean handleSearchingRecipes(Iterator matches) { } lastFailedMatches.add(match); } - return false; } public boolean handleFuelRecipe() { diff --git a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java index d9aa4dbacc..3fc1a46f74 100644 --- a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java +++ b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java @@ -322,9 +322,6 @@ public static class MachineConfigs { "Other mods can override this to true, regardless of the config file.", "Default: false"}) public boolean highTierContent = false; - @Configurable - @Configurable.Comment({"Whether search for recipes asynchronously.", " Default: true"}) - public boolean asyncRecipeSearching = true; } public static class ToolConfigs { From 2ea5835867cd0a22c837de685c9e9726b786b53b Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:54:30 +0100 Subject: [PATCH 3/7] fix: make UI titles only roll on hover --- .../com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java index d5febc2319..7314c0cc71 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java @@ -24,8 +24,7 @@ public class TitleBarWidget extends WidgetGroup { private static final int HEIGHT = 16; private static final int BTN_WIDTH = 18; - // TODO make this work. The roll speed isn't getting applied currently and it's too fast. - private static final float ROLL_SPEED = 0.2f; + private static final float ROLL_SPEED = 0.7f; private int width; private boolean showBackButton = false; @@ -80,7 +79,7 @@ public void updateState(IFancyUIProvider currentPage, boolean showBackButton, bo titleText = new TextTexture(ChatFormatting.BLACK.toString() + currentPage.getTitle().copy().getString()) .setDropShadow(false) - .setType(TextTexture.TextType.ROLL_ALWAYS); + .setType(TextTexture.TextType.LEFT_ROLL); titleText.setRollSpeed(ROLL_SPEED); tabIcon.setImage(currentPage.getTabIcon()); From c4819424aa60759600ba6ba0cc043db9c1bf6b8d Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Sat, 23 Mar 2024 13:03:25 +0100 Subject: [PATCH 4/7] fix: move titlebar text to center again --- .../com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java index 7314c0cc71..72fc83b41e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/TitleBarWidget.java @@ -79,7 +79,7 @@ public void updateState(IFancyUIProvider currentPage, boolean showBackButton, bo titleText = new TextTexture(ChatFormatting.BLACK.toString() + currentPage.getTitle().copy().getString()) .setDropShadow(false) - .setType(TextTexture.TextType.LEFT_ROLL); + .setType(TextTexture.TextType.ROLL); titleText.setRollSpeed(ROLL_SPEED); tabIcon.setImage(currentPage.getTabIcon()); From 9a28f43e5673dd87ef03c9ac582648d13e2754f0 Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:26:00 +0100 Subject: [PATCH 5/7] refactor: early return in GTRecipe.handlerContentsInternal() --- .../gtceu/api/recipe/GTRecipe.java | 96 ++++++++++--------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java index 269dec15f9..205abb1e2e 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/GTRecipe.java @@ -269,64 +269,66 @@ private Tuple> handlerContentsInternal( RecipeCapability capability, Set> used, List content, Map contentSlot, List contentSearch, Map contentSlotSearch, - boolean simulate) { - if (capabilityProxies.contains(capIO, capability)) { - var handlers = capabilityProxies.get(capIO, capability); - // handle distinct first - for (IRecipeHandler handler : handlers) { - if (!handler.isDistinct()) continue; - var result = handler.handleRecipe(io, this, contentSearch, null, true); - if (result == null) { - // check distint slot handler - if (handler.getSlotNames() != null && handler.getSlotNames().containsAll(contentSlotSearch.keySet())) { - boolean success = true; - for (var entry : contentSlotSearch.entrySet()) { - List left = handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), true); - if (left != null) { - success = false; - break; - } - } - if (success) { - if (!simulate) { - for (var entry : contentSlot.entrySet()) { - handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), false); - } - } - contentSlot.clear(); + boolean simulate + ) { + if (!capabilityProxies.contains(capIO, capability)) + return new Tuple<>(content, contentSlot); + + var handlers = capabilityProxies.get(capIO, capability); + // handle distinct first + for (IRecipeHandler handler : handlers) { + if (!handler.isDistinct()) continue; + var result = handler.handleRecipe(io, this, contentSearch, null, true); + if (result == null) { + // check distint slot handler + if (handler.getSlotNames() != null && handler.getSlotNames().containsAll(contentSlotSearch.keySet())) { + boolean success = true; + for (var entry : contentSlotSearch.entrySet()) { + List left = handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), true); + if (left != null) { + success = false; + break; } } - if (contentSlot.isEmpty()) { + if (success) { if (!simulate) { - handler.handleRecipe(io, this, content, null, false); + for (var entry : contentSlot.entrySet()) { + handler.handleRecipe(io, this, entry.getValue(), entry.getKey(), false); + } } - content = null; + contentSlot.clear(); } } - if (content == null && contentSlot.isEmpty()) { - break; + if (contentSlot.isEmpty()) { + if (!simulate) { + handler.handleRecipe(io, this, content, null, false); + } + content = null; } } - if (content != null || !contentSlot.isEmpty()) { - // handle undistinct later - for (IRecipeHandler proxy : handlers) { - if (used.contains(proxy) || proxy.isDistinct()) continue; - used.add(proxy); - if (content != null) { - content = proxy.handleRecipe(io, this, content, null, simulate); - } - if (proxy.getSlotNames() != null) { - Iterator iterator = contentSlot.keySet().iterator(); - while (iterator.hasNext()) { - String key = iterator.next(); - if (proxy.getSlotNames().contains(key)) { - List left = proxy.handleRecipe(io, this, contentSlot.get(key), key, simulate); - if (left == null) iterator.remove(); - } + if (content == null && contentSlot.isEmpty()) { + break; + } + } + if (content != null || !contentSlot.isEmpty()) { + // handle undistinct later + for (IRecipeHandler proxy : handlers) { + if (used.contains(proxy) || proxy.isDistinct()) continue; + used.add(proxy); + if (content != null) { + content = proxy.handleRecipe(io, this, content, null, simulate); + } + if (proxy.getSlotNames() != null) { + Iterator iterator = contentSlot.keySet().iterator(); + while (iterator.hasNext()) { + String key = iterator.next(); + if (proxy.getSlotNames().contains(key)) { + List left = proxy.handleRecipe(io, this, contentSlot.get(key), key, simulate); + if (left == null) iterator.remove(); } } - if (content == null && contentSlot.isEmpty()) break; } + if (content == null && contentSlot.isEmpty()) break; } } return new Tuple<>(content, contentSlot); From eed0853984c1d522d231a9cb53b0463ecb58eab9 Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:17:45 +0100 Subject: [PATCH 6/7] fix: reintroduce combined inventory for item bus machines (temporary) --- .../multiblock/part/ItemBusPartMachine.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ItemBusPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ItemBusPartMachine.java index 4f943177ba..caecf8cebe 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ItemBusPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/ItemBusPartMachine.java @@ -57,11 +57,14 @@ public class ItemBusPartMachine extends TieredIOPartMachine implements IDistinct @Getter @Persisted protected final NotifiableItemStackHandler circuitInventory; + @Getter + protected final ItemHandlerProxyRecipeTrait combinedInventory; public ItemBusPartMachine(IMachineBlockEntity holder, int tier, IO io, Object... args) { super(holder, tier, io); this.inventory = createInventory(args); this.circuitInventory = createCircuitItemHandler(io); + this.combinedInventory = createCombinedItemHandler(io); } ////////////////////////////////////// @@ -89,6 +92,14 @@ protected NotifiableItemStackHandler createCircuitItemHandler(Object... args) { } } + protected ItemHandlerProxyRecipeTrait createCombinedItemHandler(Object... args) { + if (args.length > 0 && args[0] instanceof IO io && io == IO.IN) { + return new ItemHandlerProxyRecipeTrait(this, Set.of(getInventory(), circuitInventory), IO.IN, IO.NONE); + } else { + return new ItemHandlerProxyRecipeTrait(this, Set.of(getInventory(), circuitInventory), IO.NONE, IO.NONE); + } + } + @Override public void onDrops(List drops, Player entity) { clearInventory(drops, getInventory().storage); @@ -105,6 +116,8 @@ public void onLoad() { serverLevel.getServer().tell(new TickTask(0, this::updateInventorySubscription)); } inventorySubs = getInventory().addChangedListener(this::updateInventorySubscription); + + combinedInventory.recomputeEnabledState(); } @Override @@ -125,6 +138,7 @@ public boolean isDistinct() { public void setDistinct(boolean isDistinct) { getInventory().setDistinct(isDistinct); circuitInventory.setDistinct(isDistinct); + combinedInventory.setDistinct(isDistinct); } ////////////////////////////////////// From 11d7c16c8edfa16de80fb11ed28bc32afdb9f66b Mon Sep 17 00:00:00 2001 From: mikerooni <139889766+mikerooni@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:20:39 +0100 Subject: [PATCH 7/7] fix: only roll multiblock part names on hover --- .../java/com/gregtechceu/gtceu/api/gui/fancy/PageSwitcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/PageSwitcher.java b/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/PageSwitcher.java index b8a3e5a37b..6b86d4d058 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/PageSwitcher.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/fancy/PageSwitcher.java @@ -49,7 +49,7 @@ public Widget createMainPage(FancyMachineUIWidget widget) { new TextTexture(ChatFormatting.BLACK.toString() + page.getTitle().getString()) .setDropShadow(false) .setWidth(118) - .setType(TextTexture.TextType.LEFT_ROLL_ALWAYS) + .setType(TextTexture.TextType.LEFT_ROLL) )); scrollableGroup.addWidget(pageWidget);