mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-19 23:09:32 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@a80d31b Log command execution exceptions if debug=true (#10130) PaperMC/Paper@ec19620 Use a ConcurrentHashMap for enum mappings for BlockData (#10161) PaperMC/Paper@f28caff Limit ResourceLocation length to nbt string tag length PaperMC/Paper@a0ffb57 [ci skip] Small cleanup to mc utils patch PaperMC/Paper@8c8862f Also check for the actual character length in ResourceLocation validation PaperMC/Paper@e84621a [ci skip] Add more patch identifying comments PaperMC/Paper@c0e4697 [ci skip] Add more patch identifying comments PaperMC/Paper@17275ff [ci skip] add more comments & move 1 hunk to correct patch PaperMC/Paper@78fcb8e [ci skip] Update contributing guidelines to include identifying commit titles in comments (#10162) PaperMC/Paper@8657cd9 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164) PaperMC/Paper@c151c95 Fixup AsyncPreLoginEvent patches PaperMC/Paper@93a848c Readd missed line PaperMC/Paper@f9fdedf [ci skip] Add more patch identifying comments, merge related patches PaperMC/Paper@0ef5984 [ci skip] Add more patch identifying comments, merge related patches PaperMC/Paper@848a396 Add mob goal generator (#9980) PaperMC/Paper@ebf97bd [ci skip] Add more patch identifying comments PaperMC/Paper@94807a1 [ci skip] Minor cleanup and patch merges PaperMC/Paper@5e73c55 [ci skip] Add more identifying patch comments PaperMC/Paper@3e20d3a [ci skip] Add more identifying patch comments PaperMC/Paper@f61ebdc Fix issue with kick event causes being passed improperly PaperMC/Paper@106c67a [ci skip] Add more identifying patch comments PaperMC/Paper@cc693ce [ci skip] Add more identifying patch comments, merge related patches PaperMC/Paper@eeb6afc [ci skip] Add more identifying patch comments, merge related patches PaperMC/Paper@1c956ab [ci skip] Add more identifying patch comments, merge related patches PaperMC/Paper@42e88a8 [ci skip] Add more identifying patch comments PaperMC/Paper@8e41ef4 Add visual blockdata api for primed tnt (#10146) PaperMC/Paper@68c3297 [ci skip] Add more identifying patch comments PaperMC/Paper@4a98986 Add back Reduce allocation of Vec3D by entity tracker patch (#10179) PaperMC/Paper@b48d737 Async world data IO saving (#10171) PaperMC/Paper@8d94596 [ci skip] Add more identifying patch comments PaperMC/Paper@f7dd304 [ci skip] Add more identifying patch comments PaperMC/Paper@98e6d20 [ci skip] Add more identifying patch comments PaperMC/Paper@e9e0bc1 [ci skip] Add more identifying patch comments PaperMC/Paper@d9df6bc [ci skip] Add more patch identifying comments, cleanup PaperMC/Paper@27cabc1 [ci skip] Add more patch identifying comments PaperMC/Paper@684319f [ci skip] Add more patch identifying comments PaperMC/Paper@9eb0b38 [ci skip] Add more patch identifying comments PaperMC/Paper@25013d9 [ci skip] Move some disruptive patches back PaperMC/Paper@484d6bf [ci skip] Move some disruptive patches back PaperMC/Paper@52619e7 [ci skip] Add more patch identifying comments PaperMC/Paper@e660379 [ci skip] Move some disruptive patches back PaperMC/Paper@c57d1aa Move diffs around to compile without later ones applied PaperMC/Paper@581b101 Add world to Entity AddTo/RemoveFrom Events (#10183) PaperMC/Paper@24dc2bf Add BlockStateMeta#clearBlockState (#10160) PaperMC/Paper@76da4bc Expose LootTable of DecoratedPot (#10023) PaperMC/Paper@11645e3 [ci skip] (Mostly) finish adding identifying patch comments PaperMC/Paper@51bef80 [ci skip] Remove removed patches PaperMC/Paper@ad2cf68 [ci skip] Move chunk system patch back a bit PaperMC/Paper@d405ff1 [ci skip] Fixup last commit PaperMC/Paper@a4a08b7 [ci skip] Move chunk system patch a bit back PaperMC/Paper@b700460 Convert average tick value in the GUI to the correct granularity PaperMC/Paper@1831240 [ci skip] Move chunk system patch back PaperMC/Paper@b03f255 Finish moving patches back and improving compilable state PaperMC/Paper@bd2fd61 [ci skip] Fixup a few bad comments PaperMC/Paper@fe53b0e Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@1ed50da Fix javadoc errors, remove unused classes PaperMC/Paper@7f7d05a [ci skip] Remove IRC link from the README (#10194) PaperMC/Paper@ed130f1 [ci skip] clarify javadocs for Block#getDrops (#10153) PaperMC/Paper@4643b0d Shulker duplicate event (#10135) PaperMC/Paper@b333831 Make spawn egg colours visible (#10158) PaperMC/Paper@0cc3a7e Disable memory reserve allocating (#10180) PaperMC/Paper@3841722 Properly check if a loot table exists (#10190) PaperMC/Paper@b3c8108 [ci skip] Fix incorrect documentation for BlockDropItemEvent (#10175) PaperMC/Paper@294347b [ci skip] Cleanup events (#10202) PaperMC/Paper@87ce7c7 Small refactor of Paper plugin context preparation PaperMC/Paper@7f856a1 Fix sleeping pos desync PaperMC/Paper@8bc5be8 Add missing catch PaperMC/Paper@c5d168c More provider source fixup PaperMC/Paper@9e171ef Improve tag parser handling, move hunks out of chunk system patch PaperMC/Paper@934cd77 Lifecycle Event System (#9629) PaperMC/Paper@534659e Fix NotNull locales (#10216) PaperMC/Paper@9c04729 Add Arrow/Stinger Removal Time API (#10193) PaperMC/Paper@69b52b4 Check for server JARs in plugin directory (#10228) PaperMC/Paper@cbe62d9 Add Conduit API (#10195) PaperMC/Paper@97c0120 Fix fox drops on death (#8862) PaperMC/Paper@581fb30 itemstack expose tooltip lines (#10185) PaperMC/Paper@99bae59 Propagate failed to bind to port error (#10235) PaperMC/Paper@bf6e803 Fix WaterBottleSplashEvent not forwarding hit result (#10203) PaperMC/Paper@2fa2d32 Fix possible StackOverflowError for some dispenser iteractions (#8524) PaperMC/Paper@e6a5215 Properly track the changed item from dispense events (#8658) PaperMC/Paper@4b58a85 Fire BlockPreDispenseEvent for droppers (#10226) PaperMC/Paper@cde5587 Add getChunkSnapshot includeLightData parameter (#10234) PaperMC/Paper@31699ae Updated Upstream (Bukkit/CraftBukkit) (#10242) PaperMC/Paper@37df121 Fix BlockState being set to null for damage events (#10252) PaperMC/Paper@7f85940 Updated Upstream (Bukkit) (#10255) PaperMC/Paper@7ccefdc Fire entity knockback event for ownerless tnt (#7171) PaperMC/Paper@a07d526 [ci skip] Fix JavaDoc mistake in BlockPistonRetractEvent (#10250) PaperMC/Paper@9a66f2b [ci skip] Fix javadoc mistake in PluginMeta (#10258) PaperMC/Paper@1964b22 Scoreboard objective number format api (#10036) PaperMC/Paper@d95341e FluidState API (#9951) PaperMC/Paper@351923d Run round-trip adventure codec tests with JSON, NBT, and Java ops. Use JavaOps for conversions. (#10031) PaperMC/Paper@4939f87 Add more ResourceLocation checks, some cleanup
269 lines
10 KiB
Diff
269 lines
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
|
|
Date: Tue, 21 Nov 2023 23:24:24 +0000
|
|
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..3508755c11cc8f577d27a440f2f4a08d9856f5ae
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/local/config/LocalConfigManager.java
|
|
@@ -0,0 +1,143 @@
|
|
+package me.samsuik.sakura.local.config;
|
|
+
|
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap;
|
|
+import it.unimi.dsi.fastutil.longs.Long2ObjectSortedMap;
|
|
+import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
+import me.samsuik.sakura.local.LocalRegion;
|
|
+import me.samsuik.sakura.local.storage.LocalStorageHandler;
|
|
+import me.samsuik.sakura.local.storage.LocalValueStorage;
|
|
+import me.samsuik.sakura.utils.objects.Expiry;
|
|
+import net.minecraft.core.BlockPos;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.world.level.ChunkPos;
|
|
+import net.minecraft.world.level.Level;
|
|
+import org.bukkit.Location;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.List;
|
|
+import java.util.Map;
|
|
+
|
|
+public class LocalConfigManager implements LocalStorageHandler {
|
|
+
|
|
+ private final Map<LocalRegion, LocalValueStorage> storageMap = new Object2ObjectOpenHashMap<>();
|
|
+ // tree is a tree. it may not be correct but it works.
|
|
+ private final Long2ObjectRBTreeMap<LocalRegion> regionTree = new Long2ObjectRBTreeMap<>();
|
|
+ private final Long2ObjectMap<LocalValueConfig> configMap = new Long2ObjectOpenHashMap<>();
|
|
+ private final Level level;
|
|
+
|
|
+ public LocalConfigManager(Level level) {
|
|
+ this.level = level;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public LocalRegion locate(Location location, int searchDistance) {
|
|
+ return this.locate(location.getBlockX(), location.getBlockZ(), searchDistance);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public LocalRegion locate(int x, int z, int searchDistance) {
|
|
+ long search = (long) searchDistance << 32;
|
|
+ long coordinate = ChunkPos.asLong(x, z);
|
|
+
|
|
+ // all regions below the coordinate (they're stored with the minX, minZ)
|
|
+ Long2ObjectSortedMap<LocalRegion> head = this.regionTree.headMap(coordinate);
|
|
+
|
|
+ if (head.isEmpty()) return null;
|
|
+
|
|
+ for (Long2ObjectMap.Entry<LocalRegion> entry : head.long2ObjectEntrySet()) {
|
|
+ // this has no respect for the x coordinate, but it works
|
|
+ if (coordinate - entry.getLongKey() > search) {
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ // check if the region we found contains the position
|
|
+ if (entry.getValue().contains(x, z)) {
|
|
+ return entry.getValue();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public LocalValueStorage get(LocalRegion region) {
|
|
+ return this.storageMap.get(region);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean has(LocalRegion region) {
|
|
+ return this.storageMap.containsKey(region);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void put(LocalRegion region, LocalValueStorage storage) {
|
|
+ assert region != null : "region cannot be null";
|
|
+ assert storage != null : "storage cannot be null";
|
|
+
|
|
+ long base = ChunkPos.asLong(region.minX(), region.minZ());
|
|
+ this.ensureNotOverlapping(region);
|
|
+
|
|
+ this.storageMap.put(region, storage);
|
|
+ this.regionTree.put(base, region);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void remove(LocalRegion region) {
|
|
+ assert region != null : "region cannot be null";
|
|
+
|
|
+ long base = ChunkPos.asLong(region.minX(), region.minZ());
|
|
+
|
|
+ this.storageMap.remove(region);
|
|
+ this.regionTree.remove(base);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<LocalRegion> regions() {
|
|
+ return new ArrayList<>(this.storageMap.keySet());
|
|
+ }
|
|
+
|
|
+ public LocalValueConfig config(BlockPos position) {
|
|
+ long chunkKey = ChunkPos.asLong(position.getX() >> 4, position.getZ() >> 4);
|
|
+
|
|
+ LocalValueConfig local = this.configMap.computeIfAbsent(chunkKey, (key) -> {
|
|
+ LocalValueConfig config = new LocalValueConfig(new Expiry(MinecraftServer.currentTickLong, 600));
|
|
+
|
|
+ // defaults from sakura config
|
|
+ config.init(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));
|
|
+ }
|
|
+
|
|
+ return config;
|
|
+ });
|
|
+
|
|
+ local.expiry().refresh(MinecraftServer.currentTickLong);
|
|
+ return local;
|
|
+ }
|
|
+
|
|
+ public void expire(long tick) {
|
|
+ if (tick % 200 != 0) return;
|
|
+
|
|
+ // remove expired
|
|
+ this.configMap.values().removeIf(obj -> obj.expiry().isExpired(tick));
|
|
+ }
|
|
+
|
|
+ private void ensureNotOverlapping(LocalRegion region) {
|
|
+ long top = ChunkPos.asLong(region.maxX(), region.maxZ());
|
|
+ Long2ObjectSortedMap<LocalRegion> head = this.regionTree.headMap(top);
|
|
+
|
|
+ for (LocalRegion present : head.values()) {
|
|
+ if (present != region && present.intersects(region)) {
|
|
+ throw new UnsupportedOperationException("overlapping regions");
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
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..fbd877356594f0cf8934452522cef4349801e5d7
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
|
|
@@ -0,0 +1,59 @@
|
|
+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.storage.LocalValueStorage;
|
|
+import me.samsuik.sakura.physics.PhysicsVersion;
|
|
+import me.samsuik.sakura.utils.objects.Expiry;
|
|
+import net.minecraft.world.level.Level;
|
|
+import net.minecraft.world.level.block.Block;
|
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
|
+
|
|
+import java.util.Map;
|
|
+
|
|
+public class LocalValueConfig {
|
|
+
|
|
+ private final Expiry expiry;
|
|
+ public Map<Block, DurableMaterial> durableMaterials;
|
|
+ public PhysicsVersion physicsVersion;
|
|
+ public RedstoneImplementation redstoneImplementation;
|
|
+
|
|
+ LocalValueConfig(Expiry expiry) {
|
|
+ this.expiry = expiry;
|
|
+ }
|
|
+
|
|
+ void init(Level level) {
|
|
+ // default materials
|
|
+ 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;
|
|
+ }
|
|
+
|
|
+ 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
|
|
+ if (storage.exists(LocalValueKey.PHYSICS_VERSION)) {
|
|
+ this.physicsVersion = storage.value(LocalValueKey.PHYSICS_VERSION);
|
|
+ }
|
|
+
|
|
+ // redstone implementation
|
|
+ if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) {
|
|
+ this.redstoneImplementation = RedstoneImplementation.values()[storage.value(LocalValueKey.REDSTONE_IMPLEMENTATION).ordinal()];
|
|
+ }
|
|
+ }
|
|
+
|
|
+ Expiry expiry() {
|
|
+ return expiry;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index eb04fab84e266b11ef4e531cb7ea8504a1e46aac..23e5fcffe6e1b1a12af5c7399dd8b2f6e0d2f5ff 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1733,6 +1733,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.profiler.pop();
|
|
this.profiler.pop();
|
|
worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions
|
|
+ worldserver.localConfig().expire(currentTickLong); // Sakura
|
|
}
|
|
this.isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 18a26062c114ef2b67cb7fbbffc8e2dc14b4e097..65a9b601204eb8e958e579a47cb0241d134228e2 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -177,6 +177,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
return this.sakuraConfig;
|
|
}
|
|
// Sakura end
|
|
+ // Sakura start
|
|
+ private final me.samsuik.sakura.local.config.LocalConfigManager localConfig = new me.samsuik.sakura.local.config.LocalConfigManager(this);
|
|
+
|
|
+ public me.samsuik.sakura.local.config.LocalConfigManager localConfig() {
|
|
+ return this.localConfig;
|
|
+ }
|
|
+ // Sakura end
|
|
|
|
public final com.destroystokyo.paper.antixray.ChunkPacketBlockController chunkPacketBlockController; // Paper - Anti-Xray
|
|
public final co.aikar.timings.WorldTimingsHandler timings; // Paper
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index bfb178c69026e9759e9afaebb9da141b62d1f144..6491e3bda3e56165cd1c82986e712b62d764f0d5 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -243,6 +243,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
}
|
|
// Paper end
|
|
|
|
+ // Sakura start
|
|
+ @Override
|
|
+ public me.samsuik.sakura.local.storage.LocalStorageHandler getStorageHandler() {
|
|
+ return this.getHandle().localConfig();
|
|
+ }
|
|
+ // Sakura end
|
|
+
|
|
private static final Random rand = new Random();
|
|
|
|
public CraftWorld(ServerLevel world, ChunkGenerator gen, BiomeProvider biomeProvider, Environment env) {
|