diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-11-05 19:08:04 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-11-05 19:34:31 +0800 |
| commit | ff8cd3e6fb20fffd1d05d59fd34db519e42a0e38 (patch) | |
| tree | a12e4fdf8323b409ff8b9e63cb9a084e5c692c92 /runtime/src/main/java/me/shedaniel/rei/impl | |
| parent | 022975a0166b8e5d35b4ea392db0d36c54c14800 (diff) | |
| download | RoughlyEnoughItems-ff8cd3e6fb20fffd1d05d59fd34db519e42a0e38.tar.gz RoughlyEnoughItems-ff8cd3e6fb20fffd1d05d59fd34db519e42a0e38.tar.bz2 RoughlyEnoughItems-ff8cd3e6fb20fffd1d05d59fd34db519e42a0e38.zip | |
Make auto crafting not evaluate every frame for pinned displays
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/impl')
| -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 90919e2de..279c95940 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 @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.widget.favorites.history; +import com.google.common.base.Suppliers; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Vector4f; import me.shedaniel.clothconfig2.api.LazyResettable; @@ -47,12 +48,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; @@ -72,6 +77,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; } @@ -171,7 +181,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); |
