diff --git a/patches/api/0006-Local-Value-Storage-API.patch b/patches/api/0006-Local-Value-Storage-API.patch index 3da52d3..ef34b46 100644 --- a/patches/api/0006-Local-Value-Storage-API.patch +++ b/patches/api/0006-Local-Value-Storage-API.patch @@ -6,18 +6,23 @@ Subject: [PATCH] Local Value Storage API diff --git a/src/main/java/me/samsuik/sakura/local/LocalRegion.java b/src/main/java/me/samsuik/sakura/local/LocalRegion.java new file mode 100644 -index 0000000000000000000000000000000000000000..6f76eae76ab40c0aa9e53d66df9af9827d067dda +index 0000000000000000000000000000000000000000..e9c29d22dc734854244c2e91f8b186abe0e34443 --- /dev/null +++ b/src/main/java/me/samsuik/sakura/local/LocalRegion.java -@@ -0,0 +1,41 @@ +@@ -0,0 +1,46 @@ +package me.samsuik.sakura.local; + +import io.papermc.paper.math.Position; ++import org.bukkit.util.BoundingBox; +import org.bukkit.util.Vector; +import org.jspecify.annotations.NullMarked; + +@NullMarked +public record LocalRegion(int minX, int minZ, int maxX, int maxZ) { ++ public static LocalRegion from(BoundingBox boundingBox) { ++ return of(boundingBox.getMin(), boundingBox.getMax()); ++ } ++ + public static LocalRegion of(Vector min, Vector max) { + return of(min.getBlockX(), min.getBlockZ(), max.getBlockX(), max.getBlockZ()); + } @@ -53,22 +58,19 @@ index 0000000000000000000000000000000000000000..6f76eae76ab40c0aa9e53d66df9af982 +} diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java new file mode 100644 -index 0000000000000000000000000000000000000000..adb2048a02e71433618b26a14f4c71f0e26fe943 +index 0000000000000000000000000000000000000000..4a1540d4f6125bd2a8a4f6b7e645a3eb30e35837 --- /dev/null +++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -@@ -0,0 +1,26 @@ +@@ -0,0 +1,23 @@ +package me.samsuik.sakura.local; + +import org.bukkit.NamespacedKey; +import org.jspecify.annotations.NullMarked; + -+import java.util.Objects; +import java.util.function.Supplier; + +@NullMarked +public record LocalValueKey(NamespacedKey key, Supplier defaultSupplier) { -+ // ... -+ + @Override + public boolean equals(Object o) { + if (this == o) return true; @@ -83,6 +85,36 @@ index 0000000000000000000000000000000000000000..adb2048a02e71433618b26a14f4c71f0 + return this.key.hashCode(); + } +} +diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKeys.java b/src/main/java/me/samsuik/sakura/local/LocalValueKeys.java +new file mode 100644 +index 0000000000000000000000000000000000000000..43070da3fc644e22ef3825301d1d42bba27b945d +--- /dev/null ++++ b/src/main/java/me/samsuik/sakura/local/LocalValueKeys.java +@@ -0,0 +1,24 @@ ++package me.samsuik.sakura.local; ++ ++import me.samsuik.sakura.physics.PhysicsVersion; ++import me.samsuik.sakura.redstone.RedstoneImplementation; ++import org.bukkit.Material; ++import org.bukkit.NamespacedKey; ++ ++import java.util.HashMap; ++import java.util.Map; ++import java.util.function.Supplier; ++ ++public final class LocalValueKeys { ++ private static final String NAMESPACE = "sakura"; ++ ++ public static final LocalValueKey PHYSICS_VERSION = create("physics-version", () -> PhysicsVersion.LATEST); ++ public static final LocalValueKey>> DURABLE_MATERIALS = create("durable-materials", HashMap::new); ++ public static final LocalValueKey REDSTONE_IMPLEMENTATION = create("redstone-implementation", () -> RedstoneImplementation.VANILLA); ++ public static final LocalValueKey CONSISTENT_EXPLOSION_RADIUS = create("consistent-radius", () -> false); ++ public static final LocalValueKey REDSTONE_CACHE = create("redstone-cache", () -> false); ++ ++ private static LocalValueKey create(String key, Supplier supplier) { ++ return new LocalValueKey<>(new NamespacedKey(NAMESPACE, key), supplier); ++ } ++} diff --git a/src/main/java/me/samsuik/sakura/local/storage/LocalStorageHandler.java b/src/main/java/me/samsuik/sakura/local/storage/LocalStorageHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..220a12eddf3aeaeb7adfd6404b5225e392439ca8 @@ -113,27 +145,47 @@ index 0000000000000000000000000000000000000000..220a12eddf3aeaeb7adfd6404b5225e3 +} 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 -index 0000000000000000000000000000000000000000..791637f4c817b32e30b47a88adc5a525389cdcdd +index 0000000000000000000000000000000000000000..cbaaa24b504f3a2478c9db4e3b8ef0095b6e2c80 --- /dev/null +++ b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java -@@ -0,0 +1,42 @@ +@@ -0,0 +1,50 @@ +package me.samsuik.sakura.local.storage; + ++import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import me.samsuik.sakura.local.LocalValueKey; +import org.jspecify.annotations.NullMarked; ++import org.jspecify.annotations.Nullable; + -+import java.util.HashMap; +import java.util.Map; ++import java.util.Optional; + +@NullMarked +@SuppressWarnings("unchecked") +public final class LocalValueStorage { -+ private final Map, Object> map = new HashMap<>(); ++ private final Map, Object> map = new Object2ObjectOpenHashMap<>(); ++ ++ public void set(LocalValueKey key, T insert) { ++ this.map.put(key, insert); ++ } ++ ++ public void remove(LocalValueKey key) { ++ this.map.remove(key); ++ } ++ ++ public Optional get(LocalValueKey key) { ++ T value = (T) this.map.get(key); ++ return Optional.ofNullable(value); ++ } ++ ++ public T getOrDefault(LocalValueKey key, T def) { ++ return (T) this.map.getOrDefault(key, def); ++ } + + public boolean exists(LocalValueKey key) { + return this.map.containsKey(key); + } + ++ @Nullable + public T value(LocalValueKey key) { + return (T) this.map.get(key); + } @@ -146,21 +198,115 @@ index 0000000000000000000000000000000000000000..791637f4c817b32e30b47a88adc5a525 + this.set(key, val = key.defaultSupplier().get()); + return val; + } ++} +diff --git a/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java +new file mode 100644 +index 0000000000000000000000000000000000000000..685fefb4ac36153f038b28452e3b29ded52cff07 +--- /dev/null ++++ b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java +@@ -0,0 +1,74 @@ ++package me.samsuik.sakura.physics; + -+ public T getOrDefault(LocalValueKey key, T def) { -+ return (T) this.map.getOrDefault(key, def); ++import org.jspecify.annotations.NullMarked; ++ ++@NullMarked ++public enum PhysicsVersion { ++ LEGACY("legacy", 1_0_0), // replicates patched 1.8.8 paper mechanics ++ v1_8_2("1.8.2", 1_8_2), // vanilla mechanics ++ v1_9("1.9", 1_9_0), ++ v1_10("1.10", 1_10_0), ++ v1_11("1.11", 1_11_0), ++ v1_12("1.12", 1_12_0), ++ v1_13("1.13", 1_13_0), ++ v1_14("1.14", 1_14_0), ++ v1_16("1.16", 1_16_0), ++ v1_17("1.17", 1_17_0), ++ v1_18_2("1.18.2", 1_18_2), ++ v1_19_3("1.19.3", 1_19_3), ++ v1_20("1.20", 1_20_0), ++ v1_21_2("1.21.2", 1_21_2), ++ LATEST("latest", 9_99_9); // latest version ++ ++ private final String friendlyName; ++ private final int version; ++ ++ PhysicsVersion(String friendlyName, int version) { ++ this.friendlyName = friendlyName; ++ this.version = version; + } + -+ public void set(LocalValueKey key, T insert) { -+ this.map.put(key, insert); ++ public boolean isLegacy() { ++ return this == LEGACY; + } + -+ public void remove(LocalValueKey key) { -+ this.map.remove(key); ++ public boolean afterOrEqual(int version) { ++ return this.version >= version; ++ } ++ ++ public boolean before(int version) { ++ return this.version < version; ++ } ++ ++ public boolean is(int version) { ++ return this.version == version; ++ } ++ ++ public boolean isWithin(int min, int max) { ++ return this.version >= min && this.version <= max; ++ } ++ ++ public int getVersion() { ++ return this.version; ++ } ++ ++ public String getFriendlyName() { ++ return this.friendlyName; ++ } ++ ++ public static PhysicsVersion from(String string) { ++ int parsedVersion = Integer.MIN_VALUE; ++ try { ++ String versionString = string.replace(".", ""); ++ parsedVersion = Integer.parseInt(versionString); ++ } catch (NumberFormatException nfe) { ++ // ignored ++ } ++ for (PhysicsVersion ver : values()) { ++ if (ver.name().equalsIgnoreCase(string) || ver.getFriendlyName().equalsIgnoreCase(string) || ver.is(parsedVersion)) { ++ return ver; ++ } ++ } ++ return LATEST; ++ } ++} +diff --git a/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java +new file mode 100644 +index 0000000000000000000000000000000000000000..bfb5e9ec99dfdd6f4664ddb8191496706bc0d2a1 +--- /dev/null ++++ b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java +@@ -0,0 +1,20 @@ ++package me.samsuik.sakura.redstone; ++ ++import org.jspecify.annotations.NullMarked; ++ ++@NullMarked ++public enum RedstoneImplementation { ++ VANILLA("vanilla"), ++ EIGENCRAFT("eigencraft"), ++ ALTERNATE_CURRENT("alternate-current"); ++ ++ private final String friendlyName; ++ ++ RedstoneImplementation(String friendlyName) { ++ this.friendlyName = friendlyName; ++ } ++ ++ public String getFriendlyName() { ++ return this.friendlyName; + } +} diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java -index ef32a937e6faf1e8a5d6b1207986715bae5a246c..9ef129370e7773e256fe4d2d3bfe93abc625b26a 100644 +index bef54a6c8290e09cbaac20b03dde8dfb902c96b0..93236dc21f2373983bca1fcfb470690395e7406c 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -205,6 +205,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient diff --git a/patches/api/0007-Add-physics-version-API.patch b/patches/api/0007-Add-physics-version-API.patch deleted file mode 100644 index 6f0a3ac..0000000 --- a/patches/api/0007-Add-physics-version-API.patch +++ /dev/null @@ -1,107 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Samsuik <40902469+Samsuik@users.noreply.github.com> -Date: Tue, 21 Nov 2023 14:53:27 +0000 -Subject: [PATCH] Add physics version API - - -diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -index adb2048a02e71433618b26a14f4c71f0e26fe943..f80f7f299c2208c5160bcf763f686f7bd6375eec 100644 ---- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -@@ -1,5 +1,6 @@ - package me.samsuik.sakura.local; - -+import me.samsuik.sakura.physics.PhysicsVersion; - import org.bukkit.NamespacedKey; - import org.jspecify.annotations.NullMarked; - -@@ -9,6 +10,9 @@ import java.util.function.Supplier; - @NullMarked - public record LocalValueKey(NamespacedKey key, Supplier defaultSupplier) { - // ... -+ public static final LocalValueKey PHYSICS_VERSION = new LocalValueKey<>( -+ new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST -+ ); - - @Override - public boolean equals(Object o) { -diff --git a/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java -new file mode 100644 -index 0000000000000000000000000000000000000000..685fefb4ac36153f038b28452e3b29ded52cff07 ---- /dev/null -+++ b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java -@@ -0,0 +1,74 @@ -+package me.samsuik.sakura.physics; -+ -+import org.jspecify.annotations.NullMarked; -+ -+@NullMarked -+public enum PhysicsVersion { -+ LEGACY("legacy", 1_0_0), // replicates patched 1.8.8 paper mechanics -+ v1_8_2("1.8.2", 1_8_2), // vanilla mechanics -+ v1_9("1.9", 1_9_0), -+ v1_10("1.10", 1_10_0), -+ v1_11("1.11", 1_11_0), -+ v1_12("1.12", 1_12_0), -+ v1_13("1.13", 1_13_0), -+ v1_14("1.14", 1_14_0), -+ v1_16("1.16", 1_16_0), -+ v1_17("1.17", 1_17_0), -+ v1_18_2("1.18.2", 1_18_2), -+ v1_19_3("1.19.3", 1_19_3), -+ v1_20("1.20", 1_20_0), -+ v1_21_2("1.21.2", 1_21_2), -+ LATEST("latest", 9_99_9); // latest version -+ -+ private final String friendlyName; -+ private final int version; -+ -+ PhysicsVersion(String friendlyName, int version) { -+ this.friendlyName = friendlyName; -+ this.version = version; -+ } -+ -+ public boolean isLegacy() { -+ return this == LEGACY; -+ } -+ -+ public boolean afterOrEqual(int version) { -+ return this.version >= version; -+ } -+ -+ public boolean before(int version) { -+ return this.version < version; -+ } -+ -+ public boolean is(int version) { -+ return this.version == version; -+ } -+ -+ public boolean isWithin(int min, int max) { -+ return this.version >= min && this.version <= max; -+ } -+ -+ public int getVersion() { -+ return this.version; -+ } -+ -+ public String getFriendlyName() { -+ return this.friendlyName; -+ } -+ -+ public static PhysicsVersion from(String string) { -+ int parsedVersion = Integer.MIN_VALUE; -+ try { -+ String versionString = string.replace(".", ""); -+ parsedVersion = Integer.parseInt(versionString); -+ } catch (NumberFormatException nfe) { -+ // ignored -+ } -+ for (PhysicsVersion ver : values()) { -+ if (ver.name().equalsIgnoreCase(string) || ver.getFriendlyName().equalsIgnoreCase(string) || ver.is(parsedVersion)) { -+ return ver; -+ } -+ } -+ return LATEST; -+ } -+} diff --git a/patches/api/0012-Entity-tracking-range-modifier.patch b/patches/api/0007-Entity-tracking-range-modifier.patch similarity index 90% rename from patches/api/0012-Entity-tracking-range-modifier.patch rename to patches/api/0007-Entity-tracking-range-modifier.patch index b35a45c..e2a64bd 100644 --- a/patches/api/0012-Entity-tracking-range-modifier.patch +++ b/patches/api/0007-Entity-tracking-range-modifier.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Entity tracking range modifier diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java -index 0560784e8b71a927db6d8cdf9d36a23e3b56ef74..7cf2361157ac64c1bb959a0c911e27505acf25d0 100644 +index 5b95970ff306212a71e0f880a4968fe36243202b..9fd8f198acf87eb2ed613a54057536bf46032953 100644 --- a/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java @@ -70,6 +70,12 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM diff --git a/patches/api/0008-Add-durable-material-API.patch b/patches/api/0008-Add-durable-material-API.patch deleted file mode 100644 index 06bbce9..0000000 --- a/patches/api/0008-Add-durable-material-API.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Samsuik <40902469+Samsuik@users.noreply.github.com> -Date: Wed, 29 Nov 2023 22:18:17 +0000 -Subject: [PATCH] Add durable material API - - -diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -index f80f7f299c2208c5160bcf763f686f7bd6375eec..8a688431aaa56166afd2c95731220c0aba2147ed 100644 ---- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -@@ -1,10 +1,12 @@ - package me.samsuik.sakura.local; - - import me.samsuik.sakura.physics.PhysicsVersion; -+import org.bukkit.Material; - import org.bukkit.NamespacedKey; - import org.jspecify.annotations.NullMarked; - --import java.util.Objects; -+import java.util.HashMap; -+import java.util.Map; - import java.util.function.Supplier; - - @NullMarked -@@ -14,6 +16,10 @@ public record LocalValueKey(NamespacedKey key, Supplier defaultSupplier) { - new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST - ); - -+ public static final LocalValueKey>> DURABLE_MATERIALS = new LocalValueKey<>( -+ new NamespacedKey("sakura", "durable-materials"), HashMap::new -+ ); -+ - @Override - public boolean equals(Object o) { - if (this == o) return true; diff --git a/patches/api/0009-Add-redstone-implementation-API.patch b/patches/api/0009-Add-redstone-implementation-API.patch deleted file mode 100644 index 4a9b370..0000000 --- a/patches/api/0009-Add-redstone-implementation-API.patch +++ /dev/null @@ -1,55 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Samsuik <40902469+Samsuik@users.noreply.github.com> -Date: Wed, 29 Nov 2023 22:11:36 +0000 -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 -index 8a688431aaa56166afd2c95731220c0aba2147ed..346f6392c82ff27ec4439c645948337ce1832ba3 100644 ---- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java -@@ -1,6 +1,7 @@ - package me.samsuik.sakura.local; - - import me.samsuik.sakura.physics.PhysicsVersion; -+import me.samsuik.sakura.redstone.RedstoneImplementation; - import org.bukkit.Material; - import org.bukkit.NamespacedKey; - import org.jspecify.annotations.NullMarked; -@@ -20,6 +21,10 @@ public record LocalValueKey(NamespacedKey key, Supplier defaultSupplier) { - new NamespacedKey("sakura", "durable-materials"), HashMap::new - ); - -+ public static final LocalValueKey REDSTONE_IMPLEMENTATION = new LocalValueKey<>( -+ new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA -+ ); -+ - @Override - public boolean equals(Object o) { - if (this == o) return true; -diff --git a/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java -new file mode 100644 -index 0000000000000000000000000000000000000000..bfb5e9ec99dfdd6f4664ddb8191496706bc0d2a1 ---- /dev/null -+++ b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java -@@ -0,0 +1,20 @@ -+package me.samsuik.sakura.redstone; -+ -+import org.jspecify.annotations.NullMarked; -+ -+@NullMarked -+public enum RedstoneImplementation { -+ VANILLA("vanilla"), -+ EIGENCRAFT("eigencraft"), -+ ALTERNATE_CURRENT("alternate-current"); -+ -+ private final String friendlyName; -+ -+ RedstoneImplementation(String friendlyName) { -+ this.friendlyName = friendlyName; -+ } -+ -+ public String getFriendlyName() { -+ return this.friendlyName; -+ } -+} diff --git a/patches/api/0010-Add-consistent-explosion-radius-api.patch b/patches/api/0010-Add-consistent-explosion-radius-api.patch deleted file mode 100644 index f823928..0000000 --- a/patches/api/0010-Add-consistent-explosion-radius-api.patch +++ /dev/null @@ -1,21 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Samsuik -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 346f6392c82ff27ec4439c645948337ce1832ba3..07807b9a3c7c1ccd2074333eda82fcdd850ce655 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(NamespacedKey key, Supplier defaultSupplier) { - new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA - ); - -+ public static final LocalValueKey CONSISTENT_EXPLOSION_RADIUS = new LocalValueKey<>( -+ new NamespacedKey("sakura", "consistent-radius"), () -> false -+ ); -+ - @Override - public boolean equals(Object o) { - if (this == o) return true; diff --git a/patches/api/0011-Add-redstone-cache-api.patch b/patches/api/0011-Add-redstone-cache-api.patch deleted file mode 100644 index 276b002..0000000 --- a/patches/api/0011-Add-redstone-cache-api.patch +++ /dev/null @@ -1,21 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Samsuik -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 07807b9a3c7c1ccd2074333eda82fcdd850ce655..741e5466f00b34832ac69ff01503146278e952a9 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(NamespacedKey key, Supplier defaultSupplier) { - new NamespacedKey("sakura", "consistent-radius"), () -> false - ); - -+ public static final LocalValueKey REDSTONE_CACHE = new LocalValueKey<>( -+ new NamespacedKey("sakura", "redstone-cache"), () -> false -+ ); -+ - @Override - public boolean equals(Object o) { - if (this == o) return true; diff --git a/patches/server/0004-Local-Config-and-Value-Storage-API.patch b/patches/server/0004-Local-Config-and-Value-Storage-API.patch index 311efa3..4f90ac9 100644 --- a/patches/server/0004-Local-Config-and-Value-Storage-API.patch +++ b/patches/server/0004-Local-Config-and-Value-Storage-API.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Local Config and Value Storage API diff --git a/src/main/java/me/samsuik/sakura/local/config/LocalConfigManager.java b/src/main/java/me/samsuik/sakura/local/config/LocalConfigManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..58e2bada4d9120a4802def5caece906fd1628f67 +index 0000000000000000000000000000000000000000..2b77b942b1733380c566683ba0516a74ee5c6389 --- /dev/null +++ b/src/main/java/me/samsuik/sakura/local/config/LocalConfigManager.java @@ -0,0 +1,141 @@ @@ -35,7 +35,7 @@ index 0000000000000000000000000000000000000000..58e2bada4d9120a4802def5caece906f + private final Map storageMap = new Object2ObjectOpenHashMap<>(); + // tree is a tree. it may not be correct but it works. + private final Long2ObjectRBTreeMap regionTree = new Long2ObjectRBTreeMap<>(); -+ private final Long2ObjectMap configMap = new Long2ObjectOpenHashMap<>(); ++ private final Long2ObjectMap chunkConfigs = new Long2ObjectOpenHashMap<>(); + private final Level level; + + public LocalConfigManager(Level level) { @@ -112,18 +112,18 @@ index 0000000000000000000000000000000000000000..58e2bada4d9120a4802def5caece906f + public synchronized LocalValueConfig config(BlockPos position) { + long chunkKey = ChunkPos.asLong(position.getX() >> 4, position.getZ() >> 4); + -+ LocalValueConfig local = this.configMap.computeIfAbsent(chunkKey, (key) -> { ++ LocalValueConfig local = this.chunkConfigs.computeIfAbsent(chunkKey, key -> { + LocalValueConfig config = new LocalValueConfig(new Expiry(MinecraftServer.currentTick, 600)); + + // defaults from sakura config -+ config.init(level); ++ config.loadDefaults(this.level); + + // search the entire map if we have to for a region + LocalRegion region = this.locate(position.getX(), position.getZ(), Integer.MAX_VALUE); + + if (region != null) { + // load local values -+ config.load(this.storageMap.get(region)); ++ config.loadFromStorage(this.storageMap.get(region)); + } + + return config; @@ -137,7 +137,7 @@ index 0000000000000000000000000000000000000000..58e2bada4d9120a4802def5caece906f + if (tick % 200 != 0) return; + + // remove expired -+ this.configMap.values().removeIf(obj -> obj.expiry().isExpired(tick)); ++ this.chunkConfigs.values().removeIf(obj -> obj.expiry().isExpired(tick)); + } + + private void ensureNotOverlapping(LocalRegion region) { @@ -153,16 +153,16 @@ index 0000000000000000000000000000000000000000..58e2bada4d9120a4802def5caece906f +} 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 -index 0000000000000000000000000000000000000000..5b3e2cca7ee16bc6ecfa0f29438fa6588fa39a99 +index 0000000000000000000000000000000000000000..b445166f38202ec250bcaf124b88746b3559a952 --- /dev/null +++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java -@@ -0,0 +1,69 @@ +@@ -0,0 +1,55 @@ +package me.samsuik.sakura.local.config; + +import io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation; +import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; +import me.samsuik.sakura.explosion.durable.DurableMaterial; -+import me.samsuik.sakura.local.LocalValueKey; ++import me.samsuik.sakura.local.LocalValueKeys; +import me.samsuik.sakura.local.storage.LocalValueStorage; +import me.samsuik.sakura.physics.PhysicsVersion; +import me.samsuik.sakura.utils.objects.Expiry; @@ -175,8 +175,8 @@ index 0000000000000000000000000000000000000000..5b3e2cca7ee16bc6ecfa0f29438fa658 +public final class LocalValueConfig { + private final Expiry expiry; + public Map durableMaterials; -+ public PhysicsVersion physicsVersion; + public RedstoneImplementation redstoneImplementation; ++ public PhysicsVersion physicsVersion; + public boolean consistentRadius; + public boolean redstoneCache; + @@ -184,42 +184,28 @@ index 0000000000000000000000000000000000000000..5b3e2cca7ee16bc6ecfa0f29438fa658 + this.expiry = expiry; + } + -+ void init(Level level) { -+ // default materials ++ void loadDefaults(Level level) { + this.durableMaterials = new Reference2ObjectOpenHashMap<>(level.sakuraConfig().cannons.explosion.durableMaterials); -+ -+ // physics version -+ this.physicsVersion = level.sakuraConfig().cannons.mechanics.physicsVersion; -+ -+ // redstone implementation + this.redstoneImplementation = level.paperConfig().misc.redstoneImplementation; -+ -+ // consistent explosion radius ++ this.physicsVersion = level.sakuraConfig().cannons.mechanics.physicsVersion; + this.consistentRadius = level.sakuraConfig().cannons.explosion.consistentRadius; -+ -+ // redstone cache + this.redstoneCache = level.sakuraConfig().technical.redstone.redstoneCache; + } + -+ void load(LocalValueStorage storage) { -+ // local materials -+ storage.value(LocalValueKey.DURABLE_MATERIALS, true).forEach(((material, entry) -> { -+ this.durableMaterials.put(CraftMagicNumbers.getBlock(material), new DurableMaterial(entry.getKey(), entry.getValue())); -+ })); -+ -+ // physics version -+ this.physicsVersion = storage.getOrDefault(LocalValueKey.PHYSICS_VERSION, this.physicsVersion); -+ -+ // redstone implementation -+ if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) { -+ this.redstoneImplementation = RedstoneImplementation.values()[storage.value(LocalValueKey.REDSTONE_IMPLEMENTATION).ordinal()]; -+ } -+ -+ // consistent explosion radius -+ this.consistentRadius = storage.getOrDefault(LocalValueKey.CONSISTENT_EXPLOSION_RADIUS, this.consistentRadius); -+ -+ // redstone cache -+ this.redstoneCache = storage.getOrDefault(LocalValueKey.REDSTONE_CACHE, this.redstoneCache); ++ void loadFromStorage(LocalValueStorage storage) { ++ storage.get(LocalValueKeys.DURABLE_MATERIALS).ifPresent(materials -> { ++ materials.forEach((materialType, materialProperties) -> { ++ Block nmsBlock = CraftMagicNumbers.getBlock(materialType); ++ DurableMaterial durableMaterial = new DurableMaterial(materialProperties.getKey(), materialProperties.getValue()); ++ this.durableMaterials.put(nmsBlock, durableMaterial); ++ }); ++ }); ++ storage.get(LocalValueKeys.REDSTONE_IMPLEMENTATION).ifPresent(implementation -> { ++ this.redstoneImplementation = RedstoneImplementation.values()[implementation.ordinal()]; ++ }); ++ this.physicsVersion = storage.getOrDefault(LocalValueKeys.PHYSICS_VERSION, this.physicsVersion); ++ this.consistentRadius = storage.getOrDefault(LocalValueKeys.CONSISTENT_EXPLOSION_RADIUS, this.consistentRadius); ++ this.redstoneCache = storage.getOrDefault(LocalValueKeys.REDSTONE_CACHE, this.redstoneCache); + } + + Expiry expiry() {