aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java
diff options
context:
space:
mode:
authorRoman / Nea <roman.graef@gmail.com>2021-12-30 14:37:02 +0100
committerGitHub <noreply@github.com>2021-12-30 14:37:02 +0100
commitb0b0b7567ec0656c60f2f3e4730c0edace353fb7 (patch)
tree0e2b23fe4c52b0242cefc8caee9ed887797542b2 /src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java
parentfc642887639d1918d68f4706e27ea59605a16fcb (diff)
downloadnotenoughupdates-b0b0b7567ec0656c60f2f3e4730c0edace353fb7.tar.gz
notenoughupdates-b0b0b7567ec0656c60f2f3e4730c0edace353fb7.tar.bz2
notenoughupdates-b0b0b7567ec0656c60f2f3e4730c0edace353fb7.zip
Adding support for more recipe types and forge recipes (#40)
* Foundations for support of different crafting recipe types. NeuRecipe is now a base class for a recipe which provides common concepts, such as inputs, outputs and a rendering task. GuiItemRecipe has been reworked to work with this new NeuRecipe. NeuManager now parses said recipes. This should be reworked to be a two step process (first register items, then register recipes). To keep compatibility with older repo versions, NeuRecipes are parse lenient and default to a crafting recipe. New recipes should be added in the `recipes` json field which is an array of json dictionaries, which have a `type` and other fields depending on the `type` of that recipe. This also adds support for having multiple recipes for a single item (e.g. uncrafting storage blocks). * Remove references in existing code * Recipe Generation * ring recipes * recipe generator v2 * quick forge * bugfixes and performance improvements * fix raw craft cost * reload hotm if you open the hotm tree inv * add myself to the changelog * replace quickforge formular with lookup table * do not crash anymore when opening recipes outside of skyblock * format coins differently * remove debug logs * change recipe generator so that it doesnt crash old versions
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java
new file mode 100644
index 00000000..be42364a
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Debouncer.java
@@ -0,0 +1,34 @@
+package io.github.moulberry.notenoughupdates.util;
+
+/**
+ * This debouncer always triggers on the leading edge.
+ * <p>
+ * Calling {@link #trigger} will only result in a truthy return value the first time it is called
+ * within {@link #getDelayInNanoSeconds()} nanoseconds.
+ */
+public class Debouncer {
+ private long lastPinged = 0L;
+ private final long delay;
+
+ public Debouncer(long minimumDelayInNanoSeconds) {
+ this.delay = minimumDelayInNanoSeconds;
+ }
+
+ public long getDelayInNanoSeconds() {
+ return delay;
+ }
+
+ public synchronized long timePassed() {
+ // longs are technically not atomic reads since they use two 32 bit registers
+ // so, yes, this technically has to be synchronized
+ return System.nanoTime() - lastPinged;
+ }
+
+ public synchronized boolean trigger() {
+ long newPingTime = System.nanoTime();
+ long newDelay = newPingTime - lastPinged;
+ lastPinged = newPingTime;
+ return newDelay >= this.delay;
+ }
+
+}