diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-11-05 19:08:04 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2023-05-29 21:19:20 +0800 |
| commit | 377937ecd45a15df16b07ba3741d2928881d2fc2 (patch) | |
| tree | 19bbea6fd3ac7987e28ed02000dfd043656869b5 /runtime/src/main/java | |
| parent | 8c6e469113e637a378c7659d2aee3c9ae108184d (diff) | |
| download | RoughlyEnoughItems-377937ecd45a15df16b07ba3741d2928881d2fc2.tar.gz RoughlyEnoughItems-377937ecd45a15df16b07ba3741d2928881d2fc2.tar.bz2 RoughlyEnoughItems-377937ecd45a15df16b07ba3741d2928881d2fc2.zip | |
Make auto crafting not evaluate every frame for pinned displays
Diffstat (limited to 'runtime/src/main/java')
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java index 2f374c796..95546309a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.impl.client.gui.widget.favorites.history; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; +import com.google.common.base.Suppliers; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector4f; import me.shedaniel.clothconfig2.api.LazyResettable; @@ -49,12 +50,16 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; public class DisplayEntry extends WidgetWithBounds { private final LazyResettable<List<Widget>> widgets = new LazyResettable<>(this::setupWidgets); private final DisplayHistoryWidget parent; private final Display display; private final Dimension size = new Dimension(1, 1); + private final Supplier<AutoCraftingEvaluator.AutoCraftingResult> autoCraftingResult = + Suppliers.memoizeWithExpiration(this::evaluateAutoCrafting, 1000, TimeUnit.MILLISECONDS); private boolean hasInitialBounds; private final ValueAnimator<FloatingRectangle> bounds = ValueAnimator.ofFloatingRectangle(); private final Button plusButton; @@ -74,6 +79,11 @@ public class DisplayEntry extends WidgetWithBounds { } } + private AutoCraftingEvaluator.AutoCraftingResult evaluateAutoCrafting() { + if (this.display == null) return new AutoCraftingEvaluator.AutoCraftingResult(); + return AutoCraftingEvaluator.evaluateAutoCrafting(false, false, this.display, this.display::provideInternalDisplayIds); + } + public UUID getUuid() { return uuid; } @@ -173,7 +183,7 @@ public class DisplayEntry extends WidgetWithBounds { Vector4f mouse = new Vector4f((float) mouseX, (float) mouseY, 0, 1); mouse.transform(poses.last().pose()); - AutoCraftingEvaluator.AutoCraftingResult result = AutoCraftingEvaluator.evaluateAutoCrafting(false, false, display, display::provideInternalDisplayIds); + AutoCraftingEvaluator.AutoCraftingResult result = this.autoCraftingResult.get(); plusButton.setEnabled(result.successful); plusButton.setTint(result.tint); |
