mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 07:49:29 +00:00
Add redstone cache to api
This commit is contained in:
@@ -111,10 +111,10 @@ index 0000000000000000000000000000000000000000..5c971fb4266f46de258767fccaf7fe55
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java
|
diff --git a/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0f7da96d434cd699470e050898712898b54fa356
|
index 0000000000000000000000000000000000000000..de18836d1a2a6038a661cdc60161d3bacdcb8bfe
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java
|
+++ b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java
|
||||||
@@ -0,0 +1,37 @@
|
@@ -0,0 +1,39 @@
|
||||||
+package me.samsuik.sakura.local.storage;
|
+package me.samsuik.sakura.local.storage;
|
||||||
+
|
+
|
||||||
+import me.samsuik.sakura.local.LocalValueKey;
|
+import me.samsuik.sakura.local.LocalValueKey;
|
||||||
@@ -123,7 +123,6 @@ index 0000000000000000000000000000000000000000..0f7da96d434cd699470e050898712898
|
|||||||
+import java.util.Map;
|
+import java.util.Map;
|
||||||
+
|
+
|
||||||
+public final class LocalValueStorage {
|
+public final class LocalValueStorage {
|
||||||
+
|
|
||||||
+ private final Map<LocalValueKey<?>, Object> map = new HashMap<>();
|
+ private final Map<LocalValueKey<?>, Object> map = new HashMap<>();
|
||||||
+
|
+
|
||||||
+ public boolean exists(LocalValueKey<?> key) {
|
+ public boolean exists(LocalValueKey<?> key) {
|
||||||
@@ -134,15 +133,19 @@ index 0000000000000000000000000000000000000000..0f7da96d434cd699470e050898712898
|
|||||||
+ return (T) this.map.get(key);
|
+ return (T) this.map.get(key);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public <T> T value(LocalValueKey<T> key, boolean def) {
|
+ public <T> T value(LocalValueKey<T> key, boolean returnDefault) {
|
||||||
+ T val = (T) this.map.get(key);
|
+ T val = (T) this.map.get(key);
|
||||||
+ if (!def || val != null)
|
+ if (!returnDefault || val != null)
|
||||||
+ return val;
|
+ return val;
|
||||||
+ // update value
|
+ // update value
|
||||||
+ this.set(key, val = key.defaultSupplier().get());
|
+ this.set(key, val = key.defaultSupplier().get());
|
||||||
+ return val;
|
+ return val;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ public <T> T getOrDefault(LocalValueKey<T> key, T def) {
|
||||||
|
+ return (T) this.map.getOrDefault(key, def);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ public <T> void set(LocalValueKey<T> key, T insert) {
|
+ public <T> void set(LocalValueKey<T> key, T insert) {
|
||||||
+ this.map.put(key, insert);
|
+ this.map.put(key, insert);
|
||||||
+ }
|
+ }
|
||||||
@@ -150,10 +153,9 @@ index 0000000000000000000000000000000000000000..0f7da96d434cd699470e050898712898
|
|||||||
+ public void remove(LocalValueKey<?> key) {
|
+ public void remove(LocalValueKey<?> key) {
|
||||||
+ this.map.remove(key);
|
+ this.map.remove(key);
|
||||||
+ }
|
+ }
|
||||||
+
|
|
||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
||||||
index c5fe36050eeaff80cfb989fe2f38370215af6fe5..c91d6af3cc13a1b290e2b362a3017f6536046831 100644
|
index e6f66d70d024cf4f0536a5bf8e51bf7b306335df..d554b1f54e706500153718527a6b60c7743901ea 100644
|
||||||
--- a/src/main/java/org/bukkit/World.java
|
--- a/src/main/java/org/bukkit/World.java
|
||||||
+++ b/src/main/java/org/bukkit/World.java
|
+++ b/src/main/java/org/bukkit/World.java
|
||||||
@@ -157,6 +157,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
@@ -157,6 +157,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Add redstone implementation API
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
index 4735e5d8dcea4835061b5cada9d601794efdf390..4d8c83f48d8ef739a00ea1b8a17ac8cdf10ac396 100644
|
index 4735e5d8dcea4835061b5cada9d601794efdf390..098ce4d0356fb1dddbd4e34c02f77848da1fb546 100644
|
||||||
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
@@ -1,6 +1,7 @@
|
@@ -1,6 +1,7 @@
|
||||||
@@ -16,17 +16,13 @@ index 4735e5d8dcea4835061b5cada9d601794efdf390..4d8c83f48d8ef739a00ea1b8a17ac8cd
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
|
||||||
@@ -20,6 +21,14 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
@@ -20,6 +21,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||||
new NamespacedKey("sakura", "durable-materials"), HashMap::new
|
new NamespacedKey("sakura", "durable-materials"), HashMap::new
|
||||||
);
|
);
|
||||||
|
|
||||||
+ public static final LocalValueKey<RedstoneImplementation> REDSTONE_IMPLEMENTATION = new LocalValueKey<>(
|
+ public static final LocalValueKey<RedstoneImplementation> REDSTONE_IMPLEMENTATION = new LocalValueKey<>(
|
||||||
+ new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA
|
+ new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA
|
||||||
+ );
|
+ );
|
||||||
+
|
|
||||||
+ public static final LocalValueKey<Boolean> CONSISTENT_EXPLOSION_RADIUS = new LocalValueKey<>(
|
|
||||||
+ new NamespacedKey("saskua", "consistent-radius"), () -> false
|
|
||||||
+ );
|
|
||||||
+
|
+
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
|||||||
21
patches/api/0011-Add-consistent-explosion-radius-api.patch
Normal file
21
patches/api/0011-Add-consistent-explosion-radius-api.patch
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Samsuik <kfian294ma4@gmail.com>
|
||||||
|
Date: Tue, 11 Jun 2024 13:56:47 +0100
|
||||||
|
Subject: [PATCH] Add consistent explosion radius api
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
|
index 098ce4d0356fb1dddbd4e34c02f77848da1fb546..34434bf1fa8018bd79a0af8ae0f8e7ca24da6ec6 100644
|
||||||
|
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
|
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
|
@@ -25,6 +25,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||||
|
new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA
|
||||||
|
);
|
||||||
|
|
||||||
|
+ public static final LocalValueKey<Boolean> CONSISTENT_EXPLOSION_RADIUS = new LocalValueKey<>(
|
||||||
|
+ new NamespacedKey("sakura", "consistent-radius"), () -> false
|
||||||
|
+ );
|
||||||
|
+
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
21
patches/api/0012-Add-redstone-cache-api.patch
Normal file
21
patches/api/0012-Add-redstone-cache-api.patch
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Samsuik <kfian294ma4@gmail.com>
|
||||||
|
Date: Tue, 11 Jun 2024 13:57:26 +0100
|
||||||
|
Subject: [PATCH] Add redstone cache api
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
|
index 34434bf1fa8018bd79a0af8ae0f8e7ca24da6ec6..780a02fb451d5b4b98f6895b488b90c75a6507a8 100644
|
||||||
|
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
|
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||||
|
@@ -29,6 +29,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||||
|
new NamespacedKey("sakura", "consistent-radius"), () -> false
|
||||||
|
);
|
||||||
|
|
||||||
|
+ public static final LocalValueKey<Boolean> REDSTONE_CACHE = new LocalValueKey<>(
|
||||||
|
+ new NamespacedKey("sakura", "redstone-cache"), () -> false
|
||||||
|
+ );
|
||||||
|
+
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
@@ -155,10 +155,10 @@ index 0000000000000000000000000000000000000000..a3a09b8d58589883c7c465597bc64502
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
|
diff --git a/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..dd61d4e8811ffb1e8a842df1db6ac6ce5a8258c6
|
index 0000000000000000000000000000000000000000..3f518f3f1241d3dc1f76fab42e9fd789fab4d53e
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
|
+++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
|
||||||
@@ -0,0 +1,68 @@
|
@@ -0,0 +1,71 @@
|
||||||
+package me.samsuik.sakura.local.config;
|
+package me.samsuik.sakura.local.config;
|
||||||
+
|
+
|
||||||
+import io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation;
|
+import io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation;
|
||||||
@@ -181,6 +181,7 @@ index 0000000000000000000000000000000000000000..dd61d4e8811ffb1e8a842df1db6ac6ce
|
|||||||
+ public PhysicsVersion physicsVersion;
|
+ public PhysicsVersion physicsVersion;
|
||||||
+ public RedstoneImplementation redstoneImplementation;
|
+ public RedstoneImplementation redstoneImplementation;
|
||||||
+ public boolean consistentRadius;
|
+ public boolean consistentRadius;
|
||||||
|
+ public boolean redstoneCache;
|
||||||
+
|
+
|
||||||
+ LocalValueConfig(Expiry expiry) {
|
+ LocalValueConfig(Expiry expiry) {
|
||||||
+ this.expiry = expiry;
|
+ this.expiry = expiry;
|
||||||
@@ -198,6 +199,9 @@ index 0000000000000000000000000000000000000000..dd61d4e8811ffb1e8a842df1db6ac6ce
|
|||||||
+
|
+
|
||||||
+ // consistent explosion radius
|
+ // consistent explosion radius
|
||||||
+ this.consistentRadius = level.sakuraConfig().cannons.explosion.consistentRadius;
|
+ this.consistentRadius = level.sakuraConfig().cannons.explosion.consistentRadius;
|
||||||
|
+
|
||||||
|
+ // redstone cache
|
||||||
|
+ this.redstoneCache = level.sakuraConfig().technical.redstone.redstoneCache;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ void load(LocalValueStorage storage) {
|
+ void load(LocalValueStorage storage) {
|
||||||
@@ -207,9 +211,7 @@ index 0000000000000000000000000000000000000000..dd61d4e8811ffb1e8a842df1db6ac6ce
|
|||||||
+ }));
|
+ }));
|
||||||
+
|
+
|
||||||
+ // physics version
|
+ // physics version
|
||||||
+ if (storage.exists(LocalValueKey.PHYSICS_VERSION)) {
|
+ this.physicsVersion = storage.getOrDefault(LocalValueKey.PHYSICS_VERSION, this.physicsVersion);
|
||||||
+ this.physicsVersion = storage.value(LocalValueKey.PHYSICS_VERSION);
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ // redstone implementation
|
+ // redstone implementation
|
||||||
+ if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) {
|
+ if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) {
|
||||||
@@ -217,9 +219,10 @@ index 0000000000000000000000000000000000000000..dd61d4e8811ffb1e8a842df1db6ac6ce
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // consistent explosion radius
|
+ // consistent explosion radius
|
||||||
+ if (storage.exists(LocalValueKey.CONSISTENT_EXPLOSION_RADIUS)) {
|
+ this.consistentRadius = storage.getOrDefault(LocalValueKey.CONSISTENT_EXPLOSION_RADIUS, this.consistentRadius);
|
||||||
+ this.consistentRadius = storage.value(LocalValueKey.CONSISTENT_EXPLOSION_RADIUS);
|
+
|
||||||
+ }
|
+ // redstone cache
|
||||||
|
+ this.redstoneCache = storage.getOrDefault(LocalValueKey.REDSTONE_CACHE, this.redstoneCache);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ Expiry expiry() {
|
+ Expiry expiry() {
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ index fa062e6543e8a0377e3d4715996955dba005ee80..ca8b5066e2db3dc5df97091fa8821493
|
|||||||
|
|
||||||
diff --git a/src/main/java/me/samsuik/sakura/redstone/RedstoneTracker.java b/src/main/java/me/samsuik/sakura/redstone/RedstoneTracker.java
|
diff --git a/src/main/java/me/samsuik/sakura/redstone/RedstoneTracker.java b/src/main/java/me/samsuik/sakura/redstone/RedstoneTracker.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..9dea1825a3d5d69f2f1a320a6990a30feff087c8
|
index 0000000000000000000000000000000000000000..4f5af6e241b0194ed982144fd9320315f68d7b00
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/me/samsuik/sakura/redstone/RedstoneTracker.java
|
+++ b/src/main/java/me/samsuik/sakura/redstone/RedstoneTracker.java
|
||||||
@@ -0,0 +1,288 @@
|
@@ -0,0 +1,285 @@
|
||||||
+package me.samsuik.sakura.redstone;
|
+package me.samsuik.sakura.redstone;
|
||||||
+
|
+
|
||||||
+import it.unimi.dsi.fastutil.HashCommon;
|
+import it.unimi.dsi.fastutil.HashCommon;
|
||||||
@@ -131,7 +131,7 @@ index 0000000000000000000000000000000000000000..9dea1825a3d5d69f2f1a320a6990a30f
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public boolean applyFromCache(BlockPos position, int previous, int next) {
|
+ public boolean applyFromCache(BlockPos position, int previous, int next) {
|
||||||
+ if (this.level.sakuraConfig().technical.redstone.redstoneCache && this.depth == 0) {
|
+ if (this.level.localConfig().config(position).redstoneCache && this.depth == 0) {
|
||||||
+ long key = cacheKey(position, previous, next);
|
+ long key = cacheKey(position, previous, next);
|
||||||
+ RedstoneCache cache = this.wireCaches.get(key);
|
+ RedstoneCache cache = this.wireCaches.get(key);
|
||||||
+
|
+
|
||||||
@@ -180,9 +180,6 @@ index 0000000000000000000000000000000000000000..9dea1825a3d5d69f2f1a320a6990a30f
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public boolean isTracked(BlockPos position) {
|
+ public boolean isTracked(BlockPos position) {
|
||||||
+ if (!this.level.sakuraConfig().technical.redstone.redstoneCache) {
|
|
||||||
+ return false;
|
|
||||||
+ }
|
|
||||||
+ List<RedstoneCache> wires = this.adjacent.get(position.asLong());
|
+ List<RedstoneCache> wires = this.adjacent.get(position.asLong());
|
||||||
+ return wires != null && wires.stream().anyMatch(cache -> !cache.expiry().isExpired(MinecraftServer.currentTickLong));
|
+ return wires != null && wires.stream().anyMatch(cache -> !cache.expiry().isExpired(MinecraftServer.currentTickLong));
|
||||||
+ }
|
+ }
|
||||||
@@ -192,7 +189,7 @@ index 0000000000000000000000000000000000000000..9dea1825a3d5d69f2f1a320a6990a30f
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ public void beginTracking(BlockPos position, int previous, int next) {
|
+ public void beginTracking(BlockPos position, int previous, int next) {
|
||||||
+ if (this.level.sakuraConfig().technical.redstone.redstoneCache && ++this.depth == 1) {
|
+ if (this.level.localConfig().config(position).redstoneCache && ++this.depth == 1) {
|
||||||
+ long key = cacheKey(position, previous, next);
|
+ long key = cacheKey(position, previous, next);
|
||||||
+
|
+
|
||||||
+ if (this.wireCaches.containsKey(key)) {
|
+ if (this.wireCaches.containsKey(key)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user