From 26565ea357c8d507dd4c0739609f91eb0d4d470e Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Fri, 24 Jan 2025 04:51:24 -0500 Subject: [PATCH] [ci skip] cleanup --- build-data/leaf.at | 3 + ...0006-Purpur-Server-Minecraft-Changes.patch | 12 +- .../features/0084-Multithreaded-Tracker.patch | 94 +++----------- .../0085-Nitori-Async-playerdata-Save.patch | 5 +- ...> 0087-Cache-blockstate-cache-array.patch} | 2 +- .../features/0088-Asynchronous-locator.patch | 66 +++++----- .../0091-Optimize-Entity-distanceToSqr.patch | 76 +++++++----- ...se-snapshots-for-TileEntity-getOwner.patch | 4 +- .../0093-Cache-tile-entity-position.patch | 6 +- .../features/0094-TT20-Lag-compensation.patch | 18 +-- .../0098-Lithium-CompactSineLUT.patch | 11 +- ...099-Lithium-cached-iterate-outwards.patch} | 8 +- .../0100-Smooth-teleport-config.patch | 8 +- ...hread-safe-ban-list-date-format-pars.patch | 22 ++-- ...startEachNonRunningBehavior-in-Brain.patch | 6 +- .../0103-Lithium-equipment-tracking.patch | 115 ++++++++---------- .../0104-C2ME-Optimize-world-gen-math.patch | 28 +++-- ...07-Cache-part-of-canHoldFluid-result.patch | 13 +- .../leaf/async/AsyncPlayerDataSaving.java | 1 + 19 files changed, 216 insertions(+), 282 deletions(-) rename leaf-server/minecraft-patches/features/{0087-Cache-blockstate-cache.patch => 0087-Cache-blockstate-cache-array.patch} (98%) rename leaf-server/minecraft-patches/features/{0099-Lithium-IterateOutwardsCache.patch => 0099-Lithium-cached-iterate-outwards.patch} (85%) diff --git a/build-data/leaf.at b/build-data/leaf.at index 3cec7a3a..f0c75d48 100644 --- a/build-data/leaf.at +++ b/build-data/leaf.at @@ -2,8 +2,10 @@ # See CONTRIBUTING.md on how to add access transformers. protected net.minecraft.world.entity.Entity dimensions protected-f net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase$Cache largeCollisionShape +public net.minecraft.util.Mth SIN public net.minecraft.world.entity.Entity updateInWaterStateAndDoWaterCurrentPushing()V public net.minecraft.world.entity.LivingEntity canGlide()Z +public net.minecraft.world.entity.decoration.ArmorStand noTickEquipmentDirty public net.minecraft.world.entity.monster.Shulker MAX_SCALE public net.minecraft.world.entity.player.Player canGlide()Z public net.minecraft.world.level.block.entity.FuelValues values @@ -12,6 +14,7 @@ public net.minecraft.world.level.chunk.storage.RegionFile isOversized(II)Z public net.minecraft.world.level.chunk.storage.RegionFile recalculateHeader()Z public net.minecraft.world.level.chunk.storage.RegionFile setOversized(IIZ)V public net.minecraft.world.level.chunk.storage.RegionFile write(Lnet/minecraft/world/level/ChunkPos;Ljava/nio/ByteBuffer;)V +public net.minecraft.world.level.material.FlowingFluid canHoldAnyFluid(Lnet/minecraft/world/level/block/state/BlockState;)Z public net.minecraft.world.level.pathfinder.SwimNodeEvaluator allowBreaching public-f net.minecraft.world.entity.EntityType dimensions public-f net.minecraft.world.level.block.state.BlockBehaviour explosionResistance diff --git a/leaf-server/minecraft-patches/features/0006-Purpur-Server-Minecraft-Changes.patch b/leaf-server/minecraft-patches/features/0006-Purpur-Server-Minecraft-Changes.patch index cdba0c6d..bdf6ed90 100644 --- a/leaf-server/minecraft-patches/features/0006-Purpur-Server-Minecraft-Changes.patch +++ b/leaf-server/minecraft-patches/features/0006-Purpur-Server-Minecraft-Changes.patch @@ -292,7 +292,7 @@ index 208efae06c7c44f220d4192219a86ec55c98a2fe..3baf29818d82aa7ba1cc565aaeb26288 } // Paper end - Buffer joins to world diff --git a/net/minecraft/server/Main.java b/net/minecraft/server/Main.java -index 841546cef2a98427ae78ca2a07693391eb0d3035..d6ab395d1081196fb690dc872b243524e684e70c 100644 +index 748816e3f325468f523bdb8dfb94992883ed1989..427788e8747ae8d3a49c0dc094e04b6d7727daa2 100644 --- a/net/minecraft/server/Main.java +++ b/net/minecraft/server/Main.java @@ -108,6 +108,12 @@ public class Main { @@ -309,7 +309,7 @@ index 841546cef2a98427ae78ca2a07693391eb0d3035..d6ab395d1081196fb690dc872b243524 Bootstrap.bootStrap(); Bootstrap.validate(); diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java -index 5f0fa04a4ed2b0073240edbf39aeed9007911e63..f348202ae2cc78586cf4b7926180c659b5fca56f 100644 +index 0837c765d9e8833347c9c0c1254da8249daf42c3..73d052596310098abe69b247f45cdb118297f1ee 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -267,6 +267,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop trackerMainThreadTasks = new java.util.concurrent.ConcurrentLinkedQueue<>(); -+ private boolean tracking = false; -+ -+ public void runOnTrackerMainThread(final Runnable runnable) { -+ //final boolean isOnMain = ca.spottedleaf.moonrise.common.util.TickThread.isTickThread(); -+ //System.out.println(isOnMain); -+ if (false && this.tracking) { // TODO: check here -+ this.trackerMainThreadTasks.add(runnable); -+ } else { -+ runnable.run(); -+ } -+ } -+ // Leaf end - petal - Multithreaded tracker -+ - // Paper start - optimise entity tracker - private void newTrackerTick() { - final ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup entityLookup = (ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup)((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getEntityLookup();; -@@ -951,6 +975,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider +@@ -951,6 +960,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider // Paper end - optimise entity tracker protected void tick() { @@ -79,18 +57,16 @@ index 5d9d233e3a568aa6297ed9c703fa450f98158602..325f44fc5c07d931d888698dc7f84547 // Paper start - optimise entity tracker if (true) { this.newTrackerTick(); -@@ -1073,7 +1104,9 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider +@@ -1073,7 +1089,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider final Entity entity; private final int range; SectionPos lastSectionPos; - public final Set seenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl -+ public final Set seenBy = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled -+ ? com.google.common.collect.Sets.newConcurrentHashSet() -+ : new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl // Leaf - petal - Multithreaded tracker ++ public final Set seenBy = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled ? com.google.common.collect.Sets.newConcurrentHashSet() : new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl // Leaf - petal - Multithreaded tracker // Paper start - optimise entity tracker private long lastChunkUpdate = -1L; -@@ -1100,7 +1133,39 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider +@@ -1100,7 +1116,39 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider this.lastTrackedChunk = chunk; final ServerPlayer[] playersRaw = players.getRawDataUnchecked(); @@ -130,7 +106,7 @@ index 5d9d233e3a568aa6297ed9c703fa450f98158602..325f44fc5c07d931d888698dc7f84547 for (int i = 0, len = players.size(); i < len; ++i) { final ServerPlayer player = playersRaw[i]; this.updatePlayer(player); -@@ -1115,6 +1180,8 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider +@@ -1115,6 +1163,8 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider } } } @@ -139,7 +115,7 @@ index 5d9d233e3a568aa6297ed9c703fa450f98158602..325f44fc5c07d931d888698dc7f84547 } @Override -@@ -1176,7 +1243,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider +@@ -1176,7 +1226,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider } public void broadcast(Packet packet) { @@ -148,7 +124,7 @@ index 5d9d233e3a568aa6297ed9c703fa450f98158602..325f44fc5c07d931d888698dc7f84547 serverPlayerConnection.send(packet); } } -@@ -1189,21 +1256,22 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider +@@ -1189,21 +1239,22 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider } public void broadcastRemoved() { @@ -175,22 +151,20 @@ index 5d9d233e3a568aa6297ed9c703fa450f98158602..325f44fc5c07d931d888698dc7f84547 // Vec3 vec3 = player.position().subtract(this.entity.position()); double vec3_dx = player.getX() - this.entity.getX(); diff --git a/net/minecraft/server/level/ServerBossEvent.java b/net/minecraft/server/level/ServerBossEvent.java -index f106373ef3ac4a8685c2939c9e8361688a285913..37c5fd2ba5b3b0ff741222f04737e8928a4b6079 100644 +index f106373ef3ac4a8685c2939c9e8361688a285913..51ae390c68e7a3aa193329cc3bc47ca675930ff2 100644 --- a/net/minecraft/server/level/ServerBossEvent.java +++ b/net/minecraft/server/level/ServerBossEvent.java -@@ -13,7 +13,9 @@ import net.minecraft.util.Mth; +@@ -13,7 +13,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.BossEvent; public class ServerBossEvent extends BossEvent { - private final Set players = Sets.newHashSet(); -+ private final Set players = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled -+ ? Sets.newConcurrentHashSet() -+ : Sets.newHashSet(); // Leaf - petal - Multithreaded tracker - players can be removed in async tracking ++ private final Set players = org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled ? Sets.newConcurrentHashSet() : Sets.newHashSet(); // Leaf - petal - Multithreaded tracker - players can be removed in async tracking private final Set unmodifiablePlayers = Collections.unmodifiableSet(this.players); public boolean visible = true; diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java -index 1b9e34574fb5b8955fa37795baebf588fdaeca2a..a0a40c5f0ae22390615d060b1b45c937dd9e2370 100644 +index 1b9e34574fb5b8955fa37795baebf588fdaeca2a..2cca2c7b826dc64c0642751fda006f65e80befc1 100644 --- a/net/minecraft/server/level/ServerEntity.java +++ b/net/minecraft/server/level/ServerEntity.java @@ -110,8 +110,16 @@ public class ServerEntity { @@ -212,49 +186,12 @@ index 1b9e34574fb5b8955fa37795baebf588fdaeca2a..a0a40c5f0ae22390615d060b1b45c937 } } ); -@@ -335,14 +343,21 @@ public class ServerEntity { - - public void removePairing(ServerPlayer player) { - this.entity.stopSeenByPlayer(player); -- player.connection.send(new ClientboundRemoveEntitiesPacket(this.entity.getId())); -+ // Leaf start - petal - Multithreaded tracker - send in main thread -+ ((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> -+ player.connection.send(new ClientboundRemoveEntitiesPacket(this.entity.getId())) -+ ); -+ // Leaf end - petal - Multithreaded tracker - send in main thread - } - - public void addPairing(ServerPlayer player) { - List> list = new ArrayList<>(); - this.sendPairingData(player, list::add); -- player.connection.send(new ClientboundBundlePacket(list)); -- this.entity.startSeenByPlayer(player); -+ // Leaf start - petal - Multithreaded tracker - send in main thread -+ ((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> -+ player.connection.send(new ClientboundBundlePacket(list)) -+ ); -+ // Leaf end - petal - Multithreaded tracker - send in main thread this.entity.startSeenByPlayer(player); - } - - public void sendPairingData(ServerPlayer player, Consumer> consumer) { -@@ -435,18 +450,27 @@ public class ServerEntity { - List> list = entityData.packDirty(); - if (list != null) { - this.trackedDataValues = entityData.getNonDefaultValues(); -- this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list)); -+ // Leaf start - petal - Multithreaded tracker - send in main thread -+ ((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> -+ this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list)) -+ ); -+ // Leaf end - petal - Multithreaded tracker - send in main thread - } - +@@ -441,12 +449,15 @@ public class ServerEntity { if (this.entity instanceof LivingEntity) { Set attributesToSync = ((LivingEntity)this.entity).getAttributes().getAttributesToSync(); if (!attributesToSync.isEmpty()) { + // Leaf start - petal - Multithreaded tracker - send in main thread + final Set copy = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(attributesToSync); -+ ((ServerLevel) this.entity.level()).chunkSource.chunkMap.runOnTrackerMainThread(() -> { // CraftBukkit start - Send scaled max health if (this.entity instanceof ServerPlayer serverPlayer) { - serverPlayer.getBukkitEntity().injectScaledMaxHealth(attributesToSync, false); @@ -263,13 +200,12 @@ index 1b9e34574fb5b8955fa37795baebf588fdaeca2a..a0a40c5f0ae22390615d060b1b45c937 // CraftBukkit end - this.broadcastAndSend(new ClientboundUpdateAttributesPacket(this.entity.getId(), attributesToSync)); + this.broadcastAndSend(new ClientboundUpdateAttributesPacket(this.entity.getId(), copy)); -+ }); + // Leaf end - petal - Multithreaded tracker - send in main thread } attributesToSync.clear(); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index b3c388f6108360708baf275121af18f46622494f..682024138e792fa4c72189ed06226f0a92ef3d7f 100644 +index 677e5f31089879235677b82ff554e5b89e335a6d..9ac8f658cbdc0640112c6aa672d45761285e81a9 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -2494,7 +2494,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -282,7 +218,7 @@ index b3c388f6108360708baf275121af18f46622494f..682024138e792fa4c72189ed06226f0a } diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 14c75c85c062fb9d2b576bb1cd24f942642fbf8c..0ebcaeeda2242d918fbb917076bc99a86ef677f8 100644 +index e47a9ee15c9fb7fa79c0fa92f1193adf4efb667d..72d520c91e070ce6d309f68c0558d82baffd6eb0 100644 --- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -1810,7 +1810,7 @@ public class ServerGamePacketListenerImpl diff --git a/leaf-server/minecraft-patches/features/0085-Nitori-Async-playerdata-Save.patch b/leaf-server/minecraft-patches/features/0085-Nitori-Async-playerdata-Save.patch index 1338c9ea..9ea40f7d 100644 --- a/leaf-server/minecraft-patches/features/0085-Nitori-Async-playerdata-Save.patch +++ b/leaf-server/minecraft-patches/features/0085-Nitori-Async-playerdata-Save.patch @@ -37,10 +37,10 @@ index de43e54698125ce9f319d4889dd49f7029fe95e0..1fde2e33af9102017ab17cb766e9784e public long makeWorldBackup() throws IOException { diff --git a/net/minecraft/world/level/storage/PlayerDataStorage.java b/net/minecraft/world/level/storage/PlayerDataStorage.java -index c44110b123ba5912af18faf0065e9ded780da9b7..06bf26d7e216a0d75811b831ac7ac1cc6106d6e8 100644 +index c44110b123ba5912af18faf0065e9ded780da9b7..e15221e70a1dd2bec1eb2aea3e70db28eb512e74 100644 --- a/net/minecraft/world/level/storage/PlayerDataStorage.java +++ b/net/minecraft/world/level/storage/PlayerDataStorage.java -@@ -33,6 +33,12 @@ public class PlayerDataStorage { +@@ -33,6 +33,13 @@ public class PlayerDataStorage { } public void save(Player player) { @@ -48,6 +48,7 @@ index c44110b123ba5912af18faf0065e9ded780da9b7..06bf26d7e216a0d75811b831ac7ac1cc + Runnable runnable = () -> saveInternal(player); + org.dreeam.leaf.async.AsyncPlayerDataSaving.saveAsync(runnable); + } ++ + private void saveInternal(Player player) { + // Leaf end - Nitori - Async playerdata save if (org.spigotmc.SpigotConfig.disablePlayerDataSaving) return; // Spigot diff --git a/leaf-server/minecraft-patches/features/0087-Cache-blockstate-cache.patch b/leaf-server/minecraft-patches/features/0087-Cache-blockstate-cache-array.patch similarity index 98% rename from leaf-server/minecraft-patches/features/0087-Cache-blockstate-cache.patch rename to leaf-server/minecraft-patches/features/0087-Cache-blockstate-cache-array.patch index 2652d71d..35571560 100644 --- a/leaf-server/minecraft-patches/features/0087-Cache-blockstate-cache.patch +++ b/leaf-server/minecraft-patches/features/0087-Cache-blockstate-cache-array.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:07:36 +0800 -Subject: [PATCH] Cache blockstate cache +Subject: [PATCH] Cache blockstate cache array diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java diff --git a/leaf-server/minecraft-patches/features/0088-Asynchronous-locator.patch b/leaf-server/minecraft-patches/features/0088-Asynchronous-locator.patch index f2444b7a..ee20df93 100644 --- a/leaf-server/minecraft-patches/features/0088-Asynchronous-locator.patch +++ b/leaf-server/minecraft-patches/features/0088-Asynchronous-locator.patch @@ -7,19 +7,19 @@ Original license: MIT Original project: https://github.com/thebrightspark/AsyncLocator diff --git a/net/minecraft/server/commands/LocateCommand.java b/net/minecraft/server/commands/LocateCommand.java -index 13bcd8653d766cd0b754a22e9aab261fbc62b0a5..8fcc33505b86ff686dfe3049631044b2b50789d5 100644 +index 13bcd8653d766cd0b754a22e9aab261fbc62b0a5..e3e7c4e4da0bc95b015bb84e470477782bdb691c 100644 --- a/net/minecraft/server/commands/LocateCommand.java +++ b/net/minecraft/server/commands/LocateCommand.java -@@ -109,6 +109,37 @@ public class LocateCommand { +@@ -109,6 +109,38 @@ public class LocateCommand { BlockPos blockPos = BlockPos.containing(source.getPosition()); ServerLevel level = source.getLevel(); Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER); -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) { + net.minecraft.commands.CommandSource locatorSource = source.source; -+ if (locatorSource instanceof net.minecraft.server.level.ServerPlayer || -+ locatorSource instanceof net.minecraft.server.MinecraftServer) { ++ if (locatorSource instanceof net.minecraft.server.level.ServerPlayer || locatorSource instanceof net.minecraft.server.MinecraftServer) { + BlockPos originPos = BlockPos.containing(source.getPosition()); ++ + org.dreeam.leaf.async.locate.AsyncLocator.locate(source.getLevel(), holderSet, originPos, 100, false) + .thenOnServerThread(pair -> { + stopwatch.stop(); @@ -41,43 +41,46 @@ index 13bcd8653d766cd0b754a22e9aab261fbc62b0a5..8fcc33505b86ff686dfe3049631044b2 + ); + } + }); ++ + return 0; + } + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator Pair> pair = level.getChunkSource().getGenerator().findNearestMapStructure(level, holderSet, blockPos, 100, false); stopwatch.stop(); if (pair == null) { diff --git a/net/minecraft/world/entity/animal/Dolphin.java b/net/minecraft/world/entity/animal/Dolphin.java -index 7003b532182737a745491e397a967b72e6b308aa..4f2baa764362c1cfa8ba84b52c54cf820db55ea5 100644 +index 7003b532182737a745491e397a967b72e6b308aa..3ed9652510976770f5661dd7b317f27f046700d4 100644 --- a/net/minecraft/world/entity/animal/Dolphin.java +++ b/net/minecraft/world/entity/animal/Dolphin.java -@@ -500,6 +500,8 @@ public class Dolphin extends AgeableWaterCreature { +@@ -500,6 +500,10 @@ public class Dolphin extends AgeableWaterCreature { static class DolphinSwimToTreasureGoal extends Goal { private final Dolphin dolphin; private boolean stuck; ++ // Leaf start - Asynchronous locator + @Nullable + private org.dreeam.leaf.async.locate.AsyncLocator.LocateTask asyncLocator$locateTask; ++ // Leaf end - Asynchronous locator DolphinSwimToTreasureGoal(Dolphin dolphin) { this.dolphin = dolphin; -@@ -519,6 +521,11 @@ public class Dolphin extends AgeableWaterCreature { +@@ -519,6 +523,11 @@ public class Dolphin extends AgeableWaterCreature { @Override public boolean canContinueToUse() { -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) { + return true; + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator BlockPos treasurePos = this.dolphin.getTreasurePos(); return !BlockPos.containing(treasurePos.getX(), this.dolphin.getY(), treasurePos.getZ()).closerToCenterThan(this.dolphin.position(), 4.0) && !this.stuck -@@ -532,6 +539,21 @@ public class Dolphin extends AgeableWaterCreature { +@@ -532,6 +541,22 @@ public class Dolphin extends AgeableWaterCreature { this.stuck = false; this.dolphin.getNavigation().stop(); BlockPos blockPos = this.dolphin.blockPosition(); -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) { + asyncLocator$locateTask = org.dreeam.leaf.async.locate.AsyncLocator.locate(serverLevel, StructureTags.DOLPHIN_LOCATED, blockPos, 50, false) + .thenOnServerThread(pos -> { @@ -89,46 +92,47 @@ index 7003b532182737a745491e397a967b72e6b308aa..4f2baa764362c1cfa8ba84b52c54cf82 + this.stuck = true; + } + }); ++ + return; + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator BlockPos blockPos1 = serverLevel.findNearestMapStructure(StructureTags.DOLPHIN_LOCATED, blockPos, 50, false); if (blockPos1 != null) { this.dolphin.setTreasurePos(blockPos1); -@@ -544,6 +566,12 @@ public class Dolphin extends AgeableWaterCreature { +@@ -544,6 +569,12 @@ public class Dolphin extends AgeableWaterCreature { @Override public void stop() { -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) { + this.asyncLocator$locateTask.cancel(); + this.asyncLocator$locateTask = null; + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator BlockPos treasurePos = this.dolphin.getTreasurePos(); if (BlockPos.containing(treasurePos.getX(), this.dolphin.getY(), treasurePos.getZ()).closerToCenterThan(this.dolphin.position(), 4.0) || this.stuck ) -@@ -554,6 +582,11 @@ public class Dolphin extends AgeableWaterCreature { +@@ -554,6 +585,11 @@ public class Dolphin extends AgeableWaterCreature { @Override public void tick() { -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) { + return; + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator Level level = this.dolphin.level(); if (this.dolphin.closeToNextPos() || this.dolphin.getNavigation().isDone()) { Vec3 vec3 = Vec3.atCenterOf(this.dolphin.getTreasurePos()); diff --git a/net/minecraft/world/entity/projectile/EyeOfEnder.java b/net/minecraft/world/entity/projectile/EyeOfEnder.java -index 01a9bad80a30a7879a69b800258b616b4d986108..5b6d6afd64181d095d61ce233d6f549710648ada 100644 +index 01a9bad80a30a7879a69b800258b616b4d986108..d4f49e40461a165ebd6635e9fec8fe56d7f1acf6 100644 --- a/net/minecraft/world/entity/projectile/EyeOfEnder.java +++ b/net/minecraft/world/entity/projectile/EyeOfEnder.java @@ -26,6 +26,7 @@ public class EyeOfEnder extends Entity implements ItemSupplier { public double tz; public int life; public boolean surviveAfterDeath; -+ public boolean asyncLocator$locateTaskOngoing = false; // Leaf - Async locator ++ public boolean asyncLocator$locateTaskOngoing = false; // Leaf - Asynchronous locator public EyeOfEnder(EntityType entityType, Level level) { super(entityType, level); @@ -136,16 +140,16 @@ index 01a9bad80a30a7879a69b800258b616b4d986108..5b6d6afd64181d095d61ce233d6f5497 @Override public void tick() { super.tick(); -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTaskOngoing) { + return; + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator Vec3 deltaMovement = this.getDeltaMovement(); double d = this.getX() + deltaMovement.x; double d1 = this.getY() + deltaMovement.y; diff --git a/net/minecraft/world/item/EnderEyeItem.java b/net/minecraft/world/item/EnderEyeItem.java -index 02f2c38b5f9a503097dea44d5c79518b03b63f9a..a2e701d671088a40f15e49a5343598a921d9a651 100644 +index 02f2c38b5f9a503097dea44d5c79518b03b63f9a..a7aa09d7c9d5f95706349e426cd54a79e963c6f9 100644 --- a/net/minecraft/world/item/EnderEyeItem.java +++ b/net/minecraft/world/item/EnderEyeItem.java @@ -103,14 +103,47 @@ public class EnderEyeItem extends Item { @@ -153,21 +157,21 @@ index 02f2c38b5f9a503097dea44d5c79518b03b63f9a..a2e701d671088a40f15e49a5343598a9 player.startUsingItem(hand); if (level instanceof ServerLevel serverLevel) { - BlockPos blockPos = serverLevel.findNearestMapStructure(StructureTags.EYE_OF_ENDER_LOCATED, player.blockPosition(), 100, false); -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + BlockPos blockPos; + if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) { + blockPos = BlockPos.ZERO; + } else { + blockPos = serverLevel.findNearestMapStructure(StructureTags.EYE_OF_ENDER_LOCATED, player.blockPosition(), 100, false); + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator if (blockPos == null) { return InteractionResult.CONSUME; } EyeOfEnder eyeOfEnder = new EyeOfEnder(level, player.getX(), player.getY(0.5), player.getZ()); + -+ // Leaf start - Async locator ++ // Leaf start - Asynchronous locator + final boolean isAsyncLocatorEnabled = org.dreeam.leaf.config.modules.async.AsyncLocator.enabled; + + if (isAsyncLocatorEnabled) { @@ -190,11 +194,11 @@ index 02f2c38b5f9a503097dea44d5c79518b03b63f9a..a2e701d671088a40f15e49a5343598a9 + } + }); + } -+ // Leaf end - Async locator ++ // Leaf end - Asynchronous locator + eyeOfEnder.setItem(itemInHand); - eyeOfEnder.signalTo(blockPos); -+ if (!isAsyncLocatorEnabled) eyeOfEnder.signalTo(blockPos); // Leaf - Async locator ++ if (!isAsyncLocatorEnabled) eyeOfEnder.signalTo(blockPos); // Leaf - Asynchronous locator level.gameEvent(GameEvent.PROJECTILE_SHOOT, eyeOfEnder.position(), GameEvent.Context.of(player)); // CraftBukkit start if (!level.addFreshEntity(eyeOfEnder)) { @@ -203,7 +207,7 @@ index 02f2c38b5f9a503097dea44d5c79518b03b63f9a..a2e701d671088a40f15e49a5343598a9 level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENDER_EYE_LAUNCH, SoundSource.NEUTRAL, 1.0F, f); itemInHand.consume(1, player); - player.awardStat(Stats.ITEM_USED.get(this)); -+ if (!isAsyncLocatorEnabled) player.awardStat(Stats.ITEM_USED.get(this)); // Leaf - Async locator ++ if (!isAsyncLocatorEnabled) player.awardStat(Stats.ITEM_USED.get(this)); // Leaf - Asynchronous locator } return InteractionResult.SUCCESS_SERVER; diff --git a/leaf-server/minecraft-patches/features/0091-Optimize-Entity-distanceToSqr.patch b/leaf-server/minecraft-patches/features/0091-Optimize-Entity-distanceToSqr.patch index 8b4fc00b..9112744b 100644 --- a/leaf-server/minecraft-patches/features/0091-Optimize-Entity-distanceToSqr.patch +++ b/leaf-server/minecraft-patches/features/0091-Optimize-Entity-distanceToSqr.patch @@ -8,10 +8,10 @@ avoids multiple casting in Entity#distanceTo, using Math#sqrt directly instead o these methods more able to be inlined by the JIT compiler. diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 1a0b7148c48a767b3a33f6377ba7d26239cda0c2..4ccb0ad241f6692cf1b37a6d888a82eda3bacd05 100644 +index 1a0b7148c48a767b3a33f6377ba7d26239cda0c2..236c5d98b27966f9cea0bfbe8e0dcd07987c71aa 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java -@@ -2194,30 +2194,38 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -2194,31 +2194,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess return new Vec3(this.xOld, this.yOld, this.zOld); } @@ -28,43 +28,53 @@ index 1a0b7148c48a767b3a33f6377ba7d26239cda0c2..4ccb0ad241f6692cf1b37a6d888a82ed - double d2 = this.getZ() - z; - return d * d + d1 * d1 + d2 * d2; - } -+ // Leaf start - Optimize distanceTo - inlining -+ public final float distanceTo(Entity entity) { -+ // Leaf start - Optimize distanceTo - Avoid casting -+ final double dx = this.getX() - entity.getX(); -+ final double dy = this.getY() - entity.getY(); -+ final double dz = this.getZ() - entity.getZ(); -+ // Leaf end - Optimize distanceTo - Avoid casting -+ return (float) Math.sqrt(org.dreeam.leaf.LeafBootstrap.enableFMA ? Math.fma(dx, dx, Math.fma(dy, dy, dz * dz)) : dx * dx + dy * dy + dz * dz); // Leaf - Use Math#sqrt instead of Mojang's Mth#sqrt - only cast once -+ } -+ // Leaf end - Optimize distanceTo - inlining -+ -+ // Leaf start - Optimize distanceToSqr - inlining -+ public final double distanceToSqr(final double x, final double y, final double z) { -+ final double dx = this.getX() - x; -+ final double dy = this.getY() - y; -+ final double dz = this.getZ() - z; -+ return org.dreeam.leaf.LeafBootstrap.enableFMA ? Math.fma(dx, dx, Math.fma(dy, dy, dz * dz)) : dx * dx + dy * dy + dz * dz; // Leaf - Use FMA for distanceToSqr -+ } -+ // Leaf end - Optimize distanceToSqr - - public double distanceToSqr(Entity entity) { - return this.distanceToSqr(entity.position()); - } - +- +- public double distanceToSqr(Entity entity) { +- return this.distanceToSqr(entity.position()); +- } +- - public double distanceToSqr(Vec3 vec) { - double d = this.getX() - vec.x; - double d1 = this.getY() - vec.y; - double d2 = this.getZ() - vec.z; - return d * d + d1 * d1 + d2 * d2; -+ // Leaf start - Optimize distanceToSqr - inlining +- } +- + public void playerTouch(Player player) { + } + +@@ -5230,4 +5205,34 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess + return false; + } + // Purpur end - Ridables ++ ++ // Leaf start - Optimize Entity distanceTo ++ // Inlining and avoid casting ++ // Use Math#sqrt instead of Mojang's Mth#sqrt - only cast once ++ // Added option to enable FMA acceleration ++ public final float distanceTo(Entity entity) { ++ final double dx = this.getX() - entity.getX(); ++ final double dy = this.getY() - entity.getY(); ++ final double dz = this.getZ() - entity.getZ(); ++ return (float) Math.sqrt(org.dreeam.leaf.LeafBootstrap.enableFMA ? Math.fma(dx, dx, Math.fma(dy, dy, dz * dz)) : dx * dx + dy * dy + dz * dz); ++ } ++ ++ public final double distanceToSqr(final double x, final double y, final double z) { ++ final double dx = this.getX() - x; ++ final double dy = this.getY() - y; ++ final double dz = this.getZ() - z; ++ return org.dreeam.leaf.LeafBootstrap.enableFMA ? Math.fma(dx, dx, Math.fma(dy, dy, dz * dz)) : dx * dx + dy * dy + dz * dz; ++ } ++ + public final double distanceToSqr(Vec3 vector) { + final double dx = this.getX() - vector.x; + final double dy = this.getY() - vector.y; + final double dz = this.getZ() - vector.z; -+ return org.dreeam.leaf.LeafBootstrap.enableFMA ? Math.fma(dx, dx, Math.fma(dy, dy, dz * dz)) : dx * dx + dy * dy + dz * dz; // Leaf - Use FMA for distanceToSqr - } -+ // Leaf end - Optimize distanceToSqr - inlining - - public void playerTouch(Player player) { - } ++ return org.dreeam.leaf.LeafBootstrap.enableFMA ? Math.fma(dx, dx, Math.fma(dy, dy, dz * dz)) : dx * dx + dy * dy + dz * dz; ++ } ++ ++ public double distanceToSqr(Entity entity) { ++ return this.distanceToSqr(entity.position()); ++ } ++ // Leaf end - Optimize Entity distanceToSqr + } diff --git a/leaf-server/minecraft-patches/features/0092-EMC-Don-t-use-snapshots-for-TileEntity-getOwner.patch b/leaf-server/minecraft-patches/features/0092-EMC-Don-t-use-snapshots-for-TileEntity-getOwner.patch index b3c9d11f..39f10aa4 100644 --- a/leaf-server/minecraft-patches/features/0092-EMC-Don-t-use-snapshots-for-TileEntity-getOwner.patch +++ b/leaf-server/minecraft-patches/features/0092-EMC-Don-t-use-snapshots-for-TileEntity-getOwner.patch @@ -9,7 +9,7 @@ Original project: https://github.com/starlis/empirecraft Also see Leaf's EMC-Default-don-t-use-blockstate-snapshots.patch diff --git a/net/minecraft/world/level/block/entity/BlockEntity.java b/net/minecraft/world/level/block/entity/BlockEntity.java -index 3fd0f42618e5c2c683335d1d3e0bb74c6d32ef66..9bbd6ee0518d27a7f4e009e8516e1397234e2090 100644 +index 3fd0f42618e5c2c683335d1d3e0bb74c6d32ef66..8f4d13d897ac92c6ea239da22029c8058bd82eaa 100644 --- a/net/minecraft/world/level/block/entity/BlockEntity.java +++ b/net/minecraft/world/level/block/entity/BlockEntity.java @@ -361,7 +361,7 @@ public abstract class BlockEntity { @@ -17,7 +17,7 @@ index 3fd0f42618e5c2c683335d1d3e0bb74c6d32ef66..9bbd6ee0518d27a7f4e009e8516e1397 public org.bukkit.inventory.InventoryHolder getOwner() { // Paper start - return getOwner(true); -+ return getOwner(org.dreeam.leaf.config.modules.opt.TileEntitySnapshotCreation.enabled); // Leaf - EMC - don't use snapshots ++ return getOwner(org.dreeam.leaf.config.modules.opt.TileEntitySnapshotCreation.enabled); // Leaf - EMC - Don't use snapshots for TileEntity::getOwner } public org.bukkit.inventory.InventoryHolder getOwner(boolean useSnapshot) { // Paper end diff --git a/leaf-server/minecraft-patches/features/0093-Cache-tile-entity-position.patch b/leaf-server/minecraft-patches/features/0093-Cache-tile-entity-position.patch index 6567c2ef..94337545 100644 --- a/leaf-server/minecraft-patches/features/0093-Cache-tile-entity-position.patch +++ b/leaf-server/minecraft-patches/features/0093-Cache-tile-entity-position.patch @@ -3,17 +3,17 @@ From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:27:07 -0400 Subject: [PATCH] Cache tile entity position -Check if there is a way to cache isRemoved without problem +Dreeam TODO: Check if there is a way to cache isRemoved without problem diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java -index d97d8e79034eb1484d4e3646faacc6f11289bb28..a58a36a8a473e610f604fa778df860470caf7176 100644 +index 265e890557dd6557b327b6252dd3177fdd112777..465cd4f6214c949040a35bc9e1e969c33469f2a6 100644 --- a/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java @@ -938,10 +938,12 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p private final T blockEntity; private final BlockEntityTicker ticker; private boolean loggedInvalidBlockState; -+ private BlockPos cachedPos; // Leaf - Cache tile entity position ++ private final BlockPos cachedPos; // Leaf - Cache tile entity position BoundTickingBlockEntity(final T blockEntity, final BlockEntityTicker ticker) { this.blockEntity = blockEntity; diff --git a/leaf-server/minecraft-patches/features/0094-TT20-Lag-compensation.patch b/leaf-server/minecraft-patches/features/0094-TT20-Lag-compensation.patch index ef7515bc..331cace4 100644 --- a/leaf-server/minecraft-patches/features/0094-TT20-Lag-compensation.patch +++ b/leaf-server/minecraft-patches/features/0094-TT20-Lag-compensation.patch @@ -1,25 +1,25 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Mon, 1 Nov 2077 00:00:00 +0800 -Subject: [PATCH] TT20 Lag compensation +Subject: [PATCH] TT20: Lag compensation Original license: AGPL-3.0 Original project: https://github.com/snackbag/TT20 diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java -index 99fb4faa6e8f099ee216eb44793a1df0e6b8c137..f5766b3bed325f42d4bf55d4fe83ef50fed1481f 100644 +index 2b28fdd68db5b5cf67023410730871843f49248b..d6266bd00da49a9121916fa03a7b920cebec2ace 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1556,6 +1556,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { -+ public static final float[] SIN = Util.make(new float[65536], floats -> { // Leaf - Lithium - private -> public - for (int i1 = 0; i1 < floats.length; i1++) { - floats[i1] = (float)Math.sin(i1 * Math.PI * 2.0 / 65536.0); - } @@ -46,11 +46,11 @@ public class Mth { private static final double[] COS_TAB = new double[257]; diff --git a/leaf-server/minecraft-patches/features/0099-Lithium-IterateOutwardsCache.patch b/leaf-server/minecraft-patches/features/0099-Lithium-cached-iterate-outwards.patch similarity index 85% rename from leaf-server/minecraft-patches/features/0099-Lithium-IterateOutwardsCache.patch rename to leaf-server/minecraft-patches/features/0099-Lithium-cached-iterate-outwards.patch index ca964eef..907e2b35 100644 --- a/leaf-server/minecraft-patches/features/0099-Lithium-IterateOutwardsCache.patch +++ b/leaf-server/minecraft-patches/features/0099-Lithium-cached-iterate-outwards.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Fri, 8 Nov 2024 00:06:34 +0100 -Subject: [PATCH] Lithium: IterateOutwardsCache +Subject: [PATCH] Lithium: cached iterate outwards By: 2No2Name <2No2Name@web.de> As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric) Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html) diff --git a/net/minecraft/core/BlockPos.java b/net/minecraft/core/BlockPos.java -index 6518d3fff6daf331b24a7bf5b39fa1920b73711d..da491fc59b78f9fc8141e72f810f3fbaf9bc1274 100644 +index 6518d3fff6daf331b24a7bf5b39fa1920b73711d..596a62f4020e51c2bd5a63c145b7f0e500c4b0ed 100644 --- a/net/minecraft/core/BlockPos.java +++ b/net/minecraft/core/BlockPos.java @@ -347,7 +347,18 @@ public class BlockPos extends Vec3i { @@ -18,7 +18,7 @@ index 6518d3fff6daf331b24a7bf5b39fa1920b73711d..da491fc59b78f9fc8141e72f810f3fba + // JettPack start - lithium: cached iterate outwards + private static final org.dreeam.leaf.util.cache.IterateOutwardsCache ITERATE_OUTWARDS_CACHE = new org.dreeam.leaf.util.cache.IterateOutwardsCache(50); + private static final it.unimi.dsi.fastutil.longs.LongList HOGLIN_PIGLIN_CACHE = ITERATE_OUTWARDS_CACHE.getOrCompute(8, 4, 8); -+ // JettPack end ++ // JettPack end - lithium: cached iterate outwards + public static Iterable withinManhattan(BlockPos pos, int xSize, int ySize, int zSize) { + // JettPack start - lithium: cached iterate outwards @@ -26,7 +26,7 @@ index 6518d3fff6daf331b24a7bf5b39fa1920b73711d..da491fc59b78f9fc8141e72f810f3fba + final it.unimi.dsi.fastutil.longs.LongList positions = xSize == 8 && ySize == 4 && zSize == 8 ? HOGLIN_PIGLIN_CACHE : ITERATE_OUTWARDS_CACHE.getOrCompute(xSize, ySize, zSize); + return new org.dreeam.leaf.util.cache.LongList2BlockPosMutableIterable(pos, positions); + } -+ // JettPack end ++ // JettPack end - lithium: cached iterate outwards int i = xSize + ySize + zSize; int x1 = pos.getX(); int y1 = pos.getY(); diff --git a/leaf-server/minecraft-patches/features/0100-Smooth-teleport-config.patch b/leaf-server/minecraft-patches/features/0100-Smooth-teleport-config.patch index 91d0e7bb..44892a15 100644 --- a/leaf-server/minecraft-patches/features/0100-Smooth-teleport-config.patch +++ b/leaf-server/minecraft-patches/features/0100-Smooth-teleport-config.patch @@ -9,7 +9,7 @@ happen but the visual "refresh" of a world change is hidden. Depending on the de this can act as a "smooth teleport" to a world if the new world is very similar looking to the old one. diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java -index ef20741ab2a7feaa8a86759ee0ae6283e4d4651c..98e20e34287443fa8ba482f65aae663f3c6e0f87 100644 +index d0c4c46c38eeb923b5352a0969e2e4ef8937d9f7..b4ca5d43401d03bf1e9580e95fd473b7c28916ac 100644 --- a/net/minecraft/server/level/ServerPlayer.java +++ b/net/minecraft/server/level/ServerPlayer.java @@ -1468,6 +1468,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc @@ -30,7 +30,7 @@ index ef20741ab2a7feaa8a86759ee0ae6283e4d4651c..98e20e34287443fa8ba482f65aae663f level.addDuringTeleport(this); this.triggerDimensionChangeTriggers(serverLevel); diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java -index 9ac89bd2dcf2bba13a7f12f4902db94f71771fae..3882612e14f71cce81eec23b505611432f5cb50a 100644 +index 7fe5b9006de5c1a549aa3fc1a0947f3042b15c56..75e5540337706f1be213adfc778e6ebd32409f96 100644 --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java @@ -954,11 +954,11 @@ public abstract class PlayerList { @@ -38,12 +38,12 @@ index 9ac89bd2dcf2bba13a7f12f4902db94f71771fae..3882612e14f71cce81eec23b50561143 ServerLevel serverLevel = serverPlayer.serverLevel(); LevelData levelData = serverLevel.getLevelData(); - if (!serverPlayer.smoothWorldTeleport || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(serverLevel), b)); // Leaf - Slice -+ if ((!serverPlayer.smoothWorldTeleport && !org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled) || b != 1 || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(serverLevel), b)); // Leaf - Slice // Leaf ++ if ((!serverPlayer.smoothWorldTeleport && !org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled) || b != 1 || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(serverLevel), b)); // Leaf - Slice // Leaf - Smooth teleport // serverPlayer.connection.teleport(serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), serverPlayer.getYRot(), serverPlayer.getXRot()); serverPlayer.connection.send(new ClientboundSetChunkCacheRadiusPacket(serverLevel.spigotConfig.viewDistance)); // Spigot serverPlayer.connection.send(new ClientboundSetSimulationDistancePacket(serverLevel.spigotConfig.simulationDistance)); // Spigot - if (!serverPlayer.smoothWorldTeleport || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.teleport(org.bukkit.craftbukkit.util.CraftLocation.toBukkit(serverPlayer.position(), serverLevel.getWorld(), serverPlayer.getYRot(), serverPlayer.getXRot())); // CraftBukkit // Leaf - Slice -+ if ((!serverPlayer.smoothWorldTeleport && !org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled) || b != 1 || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.teleport(org.bukkit.craftbukkit.util.CraftLocation.toBukkit(serverPlayer.position(), serverLevel.getWorld(), serverPlayer.getYRot(), serverPlayer.getXRot())); // CraftBukkit // Leaf - Slice // Leaf ++ if ((!serverPlayer.smoothWorldTeleport && !org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled) || b != 1 || !isSameLogicalHeight((ServerLevel) fromWorld, level)) serverPlayer.connection.teleport(org.bukkit.craftbukkit.util.CraftLocation.toBukkit(serverPlayer.position(), serverLevel.getWorld(), serverPlayer.getYRot(), serverPlayer.getXRot())); // CraftBukkit // Leaf - Slice // Leaf - Smooth teleport serverPlayer.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle())); serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked())); serverPlayer.connection diff --git a/leaf-server/minecraft-patches/features/0101-Use-faster-and-thread-safe-ban-list-date-format-pars.patch b/leaf-server/minecraft-patches/features/0101-Use-faster-and-thread-safe-ban-list-date-format-pars.patch index 822203b8..c50770c1 100644 --- a/leaf-server/minecraft-patches/features/0101-Use-faster-and-thread-safe-ban-list-date-format-pars.patch +++ b/leaf-server/minecraft-patches/features/0101-Use-faster-and-thread-safe-ban-list-date-format-pars.patch @@ -23,21 +23,23 @@ Wether there is a high frequnently calls or not. And also thread-safe. So there a better solution, why not using it? diff --git a/net/minecraft/server/players/BanListEntry.java b/net/minecraft/server/players/BanListEntry.java -index e111adec2116f922fe67ee434635e50c60dad15c..378ea667007844a08b4f215ca5f0730668e46699 100644 +index e111adec2116f922fe67ee434635e50c60dad15c..72f64d5812411be0f0bc5456caff87d63a4cbbb9 100644 --- a/net/minecraft/server/players/BanListEntry.java +++ b/net/minecraft/server/players/BanListEntry.java -@@ -9,7 +9,9 @@ import javax.annotation.Nullable; +@@ -9,7 +9,11 @@ import javax.annotation.Nullable; import net.minecraft.network.chat.Component; public abstract class BanListEntry extends StoredUserEntry { - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ROOT); ++ // Leaf start - Use faster and thread-safe ban list date format parsing + //public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ROOT); // Leaf - I assume no one will use this, if yes, why? + private static final java.time.ZoneId ZONE_ID = java.time.ZoneId.systemDefault(); -+ public static final java.time.format.DateTimeFormatter DATE_TIME_FORMATTER = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z"); // Leaf - Use faster and thread-safe ban list date format parsing ++ public static final java.time.format.DateTimeFormatter DATE_TIME_FORMATTER = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss Z"); ++ // Leaf end - Use faster and thread-safe ban list date format parsing public static final String EXPIRES_NEVER = "forever"; protected final Date created; protected final String source; -@@ -30,8 +32,10 @@ public abstract class BanListEntry extends StoredUserEntry { +@@ -30,8 +34,10 @@ public abstract class BanListEntry extends StoredUserEntry { Date date; try { @@ -50,7 +52,7 @@ index e111adec2116f922fe67ee434635e50c60dad15c..378ea667007844a08b4f215ca5f07306 date = new Date(); } -@@ -40,8 +44,10 @@ public abstract class BanListEntry extends StoredUserEntry { +@@ -40,8 +46,10 @@ public abstract class BanListEntry extends StoredUserEntry { Date date1; try { @@ -63,7 +65,7 @@ index e111adec2116f922fe67ee434635e50c60dad15c..378ea667007844a08b4f215ca5f07306 date1 = null; } -@@ -75,9 +81,9 @@ public abstract class BanListEntry extends StoredUserEntry { +@@ -75,9 +83,9 @@ public abstract class BanListEntry extends StoredUserEntry { @Override protected void serialize(JsonObject data) { @@ -75,7 +77,7 @@ index e111adec2116f922fe67ee434635e50c60dad15c..378ea667007844a08b4f215ca5f07306 data.addProperty("reason", this.reason); } -@@ -86,9 +92,11 @@ public abstract class BanListEntry extends StoredUserEntry { +@@ -86,9 +94,11 @@ public abstract class BanListEntry extends StoredUserEntry { Date expires = null; try { @@ -83,13 +85,13 @@ index e111adec2116f922fe67ee434635e50c60dad15c..378ea667007844a08b4f215ca5f07306 - } catch (ParseException ex) { + // Leaf start - Use faster and thread-safe ban list date format parsing + expires = jsonobject.has("expires") ? parseToDate(jsonobject.get("expires").getAsString()) : null; -+ } catch (java.time.format.DateTimeParseException ignored) { ++ } catch (java.time.format.DateTimeParseException ex) { // Guess we don't have a date + // Leaf end - Use faster and thread-safe ban list date format parsing } if (expires == null || expires.after(new Date())) { -@@ -98,4 +106,15 @@ public abstract class BanListEntry extends StoredUserEntry { +@@ -98,4 +108,15 @@ public abstract class BanListEntry extends StoredUserEntry { } } // CraftBukkit end @@ -100,7 +102,7 @@ index e111adec2116f922fe67ee434635e50c60dad15c..378ea667007844a08b4f215ca5f07306 + return Date.from(parsedDateTime.toInstant()); + } + -+ public static String formateToString(Date date) { ++ private static String formateToString(Date date) { + return DATE_TIME_FORMATTER.format(date.toInstant().atZone(ZONE_ID)); + } + // Leaf end - Use faster and thread-safe ban list date format parsing diff --git a/leaf-server/minecraft-patches/features/0102-Collect-then-startEachNonRunningBehavior-in-Brain.patch b/leaf-server/minecraft-patches/features/0102-Collect-then-startEachNonRunningBehavior-in-Brain.patch index bd259169..c4960779 100644 --- a/leaf-server/minecraft-patches/features/0102-Collect-then-startEachNonRunningBehavior-in-Brain.patch +++ b/leaf-server/minecraft-patches/features/0102-Collect-then-startEachNonRunningBehavior-in-Brain.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Collect then startEachNonRunningBehavior in Brain diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java -index c561b749fb9b76ba9b1e9689089b743248c65d50..2f261294ddb82231b6cf423c27c0620876d51cdf 100644 +index c561b749fb9b76ba9b1e9689089b743248c65d50..ea6c8e85ccff67b1c24109732f74f1e8199cad07 100644 --- a/net/minecraft/world/entity/ai/Brain.java +++ b/net/minecraft/world/entity/ai/Brain.java @@ -453,20 +453,29 @@ public class Brain { @@ -13,7 +13,7 @@ index c561b749fb9b76ba9b1e9689089b743248c65d50..2f261294ddb82231b6cf423c27c06208 private void startEachNonRunningBehavior(ServerLevel level, E entity) { - long gameTime = level.getGameTime(); -+ // Leaf start - Collect first then start ++ // Leaf start - Collect then startEachNonRunningBehavior in Brain + final long gameTime = level.getGameTime(); + List> behaviorsToStart = new ObjectArrayList<>(); @@ -41,7 +41,7 @@ index c561b749fb9b76ba9b1e9689089b743248c65d50..2f261294ddb82231b6cf423c27c06208 + behaviorControl.tryStart(level, entity, gameTime); + } + } -+ // Leaf end - Collect first then start ++ // Leaf end - Collect then startEachNonRunningBehavior in Brain } private void tickEachRunningBehavior(ServerLevel level, E entity) { diff --git a/leaf-server/minecraft-patches/features/0103-Lithium-equipment-tracking.patch b/leaf-server/minecraft-patches/features/0103-Lithium-equipment-tracking.patch index b774a74f..cc825b97 100644 --- a/leaf-server/minecraft-patches/features/0103-Lithium-equipment-tracking.patch +++ b/leaf-server/minecraft-patches/features/0103-Lithium-equipment-tracking.patch @@ -24,7 +24,7 @@ As part of: Lithium (https://github.com/CaffeineMC/lithium-fabric) Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html) diff --git a/net/minecraft/core/component/PatchedDataComponentMap.java b/net/minecraft/core/component/PatchedDataComponentMap.java -index a8c6549f772208cd543607224fef2c2389b14f24..f0b9bb52763b994c34048eb540ac60e73dcb227a 100644 +index a8c6549f772208cd543607224fef2c2389b14f24..709631db548a16a969a373e26ebbcd6983e35590 100644 --- a/net/minecraft/core/component/PatchedDataComponentMap.java +++ b/net/minecraft/core/component/PatchedDataComponentMap.java @@ -14,10 +14,11 @@ import java.util.Map.Entry; @@ -32,29 +32,31 @@ index a8c6549f772208cd543607224fef2c2389b14f24..f0b9bb52763b994c34048eb540ac60e7 import javax.annotation.Nullable; -public final class PatchedDataComponentMap implements DataComponentMap { -+public final class PatchedDataComponentMap implements DataComponentMap, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangePublisher { // Leaf - Lithium equipment tracking ++public final class PatchedDataComponentMap implements DataComponentMap, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangePublisher { // Leaf - Lithium - equipment tracking private final DataComponentMap prototype; private Reference2ObjectMap, Optional> patch; private boolean copyOnWrite; -+ private net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber; // Leaf - Lithium equipment tracking ++ private net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber; // Leaf - Lithium - equipment tracking public PatchedDataComponentMap(DataComponentMap prototype) { this(prototype, Reference2ObjectMaps.emptyMap(), true); -@@ -135,6 +136,9 @@ public final class PatchedDataComponentMap implements DataComponentMap { +@@ -135,6 +136,11 @@ public final class PatchedDataComponentMap implements DataComponentMap { } private void ensureMapOwnership() { ++ // Leaf start - Lithium - equipment tracking + if (this.subscriber != null) { + this.subscriber.notify(this, 0); + } ++ // Leaf end - Lithium - equipment tracking if (this.copyOnWrite) { this.patch = new Reference2ObjectArrayMap<>(this.patch); this.copyOnWrite = false; -@@ -221,6 +225,22 @@ public final class PatchedDataComponentMap implements DataComponentMap { +@@ -221,6 +227,22 @@ public final class PatchedDataComponentMap implements DataComponentMap { return (DataComponentMap)(this.patch.isEmpty() ? this.prototype : this.copy()); } -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + @Override + public void subscribe(net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber, int subscriberData) { + if (subscriberData != 0) { @@ -68,13 +70,13 @@ index a8c6549f772208cd543607224fef2c2389b14f24..f0b9bb52763b994c34048eb540ac60e7 + this.subscriber = net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber.without(this.subscriber, subscriber); + return 0; + } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking + @Override public boolean equals(Object other) { return this == other diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java -index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f7733e7836d 100644 +index ead6a4823d7681109bc0888d0a1fc0d73dad3c98..9a3b27457ff62dfb2ead9c114c287f55504f19f6 100644 --- a/net/minecraft/world/entity/LivingEntity.java +++ b/net/minecraft/world/entity/LivingEntity.java @@ -159,7 +159,7 @@ import org.bukkit.event.entity.EntityTeleportEvent; @@ -82,7 +84,7 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 // CraftBukkit end -public abstract class LivingEntity extends Entity implements Attackable { -+public abstract class LivingEntity extends Entity implements Attackable, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber.CountChangeSubscriber, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity.TickableEnchantmentTrackingEntity, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity.EquipmentTrackingEntity { // Leaf - Lithium equipment tracking ++public abstract class LivingEntity extends Entity implements Attackable, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber.CountChangeSubscriber, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity.TickableEnchantmentTrackingEntity, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity.EquipmentTrackingEntity { // Leaf - Lithium - equipment tracking private static final Logger LOGGER = LogUtils.getLogger(); private static final String TAG_ACTIVE_EFFECTS = "active_effects"; private static final ResourceLocation SPEED_MODIFIER_POWDER_SNOW_ID = ResourceLocation.withDefaultNamespace("powder_snow"); @@ -90,10 +92,10 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper - Friction API protected boolean shouldBurnInDay = false; public boolean shouldBurnInDay() { return this.shouldBurnInDay; } public void setShouldBurnInDay(boolean shouldBurnInDay) { this.shouldBurnInDay = shouldBurnInDay; } // Purpur - API for any mob to burn daylight -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + private boolean maybeHasTickableEnchantments = this instanceof net.minecraft.world.entity.player.Player; + private boolean equipmentChanged = true; -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking @Override public float getBukkitYaw() { return this.getYHeadRot(); @@ -102,7 +104,7 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 } - if (this.level() instanceof ServerLevel serverLevel) { -+ if (this.maybeHasTickableEnchantments && this.level() instanceof ServerLevel serverLevel) { // Leaf - Lithium equipment tracking ++ if (this.maybeHasTickableEnchantments && this.level() instanceof ServerLevel serverLevel) { // Leaf - Lithium - equipment tracking EnchantmentHelper.tickEffects(serverLevel, this); } @@ -110,7 +112,7 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 if (!this.level().isClientSide() && !this.isSpectator()) { boolean flag = newItem.isEmpty() && oldItem.isEmpty(); if (!flag && !ItemStack.isSameItemSameComponents(oldItem, newItem) && !this.firstTick) { -+ this.onEquipmentReplaced(oldItem, newItem); // Leaf - Lithium equipment tracking ++ this.onEquipmentReplaced(oldItem, newItem); // Leaf - Lithium - equipment tracking Equippable equippable = newItem.get(DataComponents.EQUIPPABLE); if (!this.isSilent() && equippable != null && slot == equippable.slot() && !silent) { // CraftBukkit this.level() @@ -118,7 +120,7 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 public void detectEquipmentUpdatesPublic() { // CraftBukkit Map map = this.collectEquipmentChanges(); if (map != null) { -+ if (!(this instanceof net.minecraft.world.entity.player.Player)) this.equipmentChanged = false; // Leaf - Lithium equipment tracking ++ if (!(this instanceof net.minecraft.world.entity.player.Player)) this.equipmentChanged = false; // Leaf - Lithium - equipment tracking this.handleHandSwap(map); if (!map.isEmpty()) { this.handleEquipmentChanges(map); @@ -126,10 +128,10 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 @Nullable private Map collectEquipmentChanges() { -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + final boolean isArmorStandUpdateNoTick = this instanceof net.minecraft.world.entity.decoration.ArmorStand stand && !stand.canTick && stand.noTickEquipmentDirty; + if (!isArmorStandUpdateNoTick && !this.equipmentChanged) return null; -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking Map map = null; for (EquipmentSlot equipmentSlot : EquipmentSlot.VALUES) { @@ -137,7 +139,7 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 return this.lastHurtByPlayerTime; } -+ // Leaf start - Lithium entity equipment tracking ++ // Leaf start - Lithium - equipment tracking + @Override + public void updateHasTickableEnchantments(ItemStack oldStack, ItemStack newStack) { + if (!this.maybeHasTickableEnchantments) { @@ -210,13 +212,13 @@ index 4819ff258b3abffcbf8a443b157c3a28afd1c52a..e216bb1cf728698fea018b9064c71f77 + newStack.subscribe(this, 0); + } + } -+ // Leaf end - Lithium entity equipment tracking ++ // Leaf end - Lithium - equipment tracking + public record Fallsounds(SoundEvent small, SoundEvent big) { } } diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java -index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a18dec9dd6 100644 +index c32086ddf90fafcc55600f9e0724b9f915671482..b541236c39e3f36bcc619fffe83e32987df20adf 100644 --- a/net/minecraft/world/entity/Mob.java +++ b/net/minecraft/world/entity/Mob.java @@ -94,7 +94,7 @@ import org.bukkit.event.entity.EntityUnleashEvent; @@ -224,7 +226,7 @@ index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a1 // CraftBukkit end -public abstract class Mob extends LivingEntity implements EquipmentUser, Leashable, Targeting { -+public abstract class Mob extends LivingEntity implements EquipmentUser, Leashable, Targeting, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity { // Leaf - Lithium equipment tracking ++public abstract class Mob extends LivingEntity implements EquipmentUser, Leashable, Targeting, net.caffeinemc.mods.lithium.common.entity.EquipmentEntity { // Leaf - Lithium - equipment tracking private static final EntityDataAccessor DATA_MOB_FLAGS_ID = SynchedEntityData.defineId(Mob.class, EntityDataSerializers.BYTE); private static final int MOB_FLAG_NO_AI = 1; private static final int MOB_FLAG_LEFTHANDED = 2; @@ -232,7 +234,7 @@ index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a1 @Override public void readAdditionalSaveData(CompoundTag compound) { -+ ItemStack prevBodyArmor = this.bodyArmorItem; // Leaf - Lithium equipment tracking ++ ItemStack prevBodyArmor = this.bodyArmorItem; // Leaf - Lithium - equipment tracking super.readAdditionalSaveData(compound); // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it if (compound.contains("CanPickUpLoot", 99)) { @@ -241,11 +243,11 @@ index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a1 for (int i = 0; i < this.armorItems.size(); i++) { CompoundTag compound1 = list.getCompound(i); - this.armorItems.set(i, ItemStack.parseOptional(this.registryAccess(), compound1)); -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + ItemStack currStack = ItemStack.parseOptional(this.registryAccess(), compound1); + ItemStack prevStack = this.armorItems.set(i, currStack); + this.trackEquipChange(prevStack, currStack); -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } } else { this.armorItems.replaceAll(itemStack -> ItemStack.EMPTY); @@ -254,11 +256,11 @@ index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a1 for (int i = 0; i < this.handItems.size(); i++) { CompoundTag compound1 = list.getCompound(i); - this.handItems.set(i, ItemStack.parseOptional(this.registryAccess(), compound1)); -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + ItemStack currStack = ItemStack.parseOptional(this.registryAccess(), compound1); + ItemStack prevStack = this.handItems.set(i, currStack); + this.trackEquipChange(prevStack, currStack); -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } } else { this.handItems.replaceAll(itemStack -> ItemStack.EMPTY); @@ -266,11 +268,11 @@ index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a1 this.ticksSinceLastInteraction = compound.getInt("Purpur.ticksSinceLastInteraction"); } // Purpur end - Entity lifespan -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + if (prevBodyArmor != this.bodyArmorItem) { + this.trackEquipChange(prevBodyArmor, this.bodyArmorItem); + } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } @Override @@ -279,14 +281,14 @@ index c32086ddf90fafcc55600f9e0724b9f915671482..5e03f3536010951ac378c1856ac355a1 } // Purpur end - Ridables + -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + private void trackEquipChange(ItemStack prevStack, ItemStack currStack) { + this.onEquipmentReplaced(prevStack, currStack); + } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } diff --git a/net/minecraft/world/entity/decoration/ArmorStand.java b/net/minecraft/world/entity/decoration/ArmorStand.java -index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95326800a0 100644 +index a31bbd8f3fff4fb4b1b33877d5835b93fc248f65..21153f37c169e987d7876d1b914105223ac10ee7 100644 --- a/net/minecraft/world/entity/decoration/ArmorStand.java +++ b/net/minecraft/world/entity/decoration/ArmorStand.java @@ -46,7 +46,7 @@ import net.minecraft.world.level.material.PushReaction; @@ -294,29 +296,20 @@ index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95 import net.minecraft.world.phys.Vec3; -public class ArmorStand extends LivingEntity { -+public class ArmorStand extends LivingEntity implements net.caffeinemc.mods.lithium.common.entity.EquipmentEntity { // Leaf - Lithium equipment tracking ++public class ArmorStand extends LivingEntity implements net.caffeinemc.mods.lithium.common.entity.EquipmentEntity { // Leaf - Lithium - equipment tracking public static final int WOBBLE_TIME = 5; private static final boolean ENABLE_ARMS = true; public static final Rotations DEFAULT_HEAD_POSE = new Rotations(0.0F, 0.0F, 0.0F); -@@ -91,7 +91,7 @@ public class ArmorStand extends LivingEntity { - public boolean canTick = true; - public boolean canTickSetByAPI = false; - private boolean noTickPoseDirty = false; -- private boolean noTickEquipmentDirty = false; -+ public boolean noTickEquipmentDirty = false; // Leaf - Lithium equipment tracking - private -> public - // Paper end - Allow ArmorStands not to tick - public boolean canMovementTick = true; // Purpur - Movement options for armor stands - @@ -233,7 +233,11 @@ public class ArmorStand extends LivingEntity { for (int i = 0; i < this.armorItems.size(); i++) { CompoundTag compound1 = list.getCompound(i); - this.armorItems.set(i, ItemStack.parseOptional(this.registryAccess(), compound1)); -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + ItemStack currElement = ItemStack.parseOptional(this.registryAccess(), compound1); + ItemStack prevElement = this.armorItems.set(i, currElement); + this.trackEquipChange(prevElement, currElement); -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } } @@ -325,11 +318,11 @@ index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95 for (int i = 0; i < this.handItems.size(); i++) { CompoundTag compound1 = list.getCompound(i); - this.handItems.set(i, ItemStack.parseOptional(this.registryAccess(), compound1)); -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + ItemStack currStack = ItemStack.parseOptional(this.registryAccess(), compound1); + ItemStack prevStack = this.handItems.set(i, currStack); + this.trackEquipChange(prevStack, currStack); -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } } @@ -338,11 +331,11 @@ index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95 if (!itemStack.isEmpty()) { this.drops.add(new DefaultDrop(itemStack, stack -> Block.popResource(this.level(), this.blockPosition().above(), stack))); // CraftBukkit - add to drops // Paper - Restore vanilla drops behavior; mirror so we can destroy it later - though this call site was safe & spawn drops correctly - this.handItems.set(i, ItemStack.EMPTY); -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + ItemStack emptyStack = ItemStack.EMPTY; + ItemStack prevStack = this.handItems.set(i, emptyStack); + this.trackEquipChange(prevStack, emptyStack); -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } } @@ -351,11 +344,11 @@ index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95 if (!itemStack.isEmpty()) { this.drops.add(new DefaultDrop(itemStack, stack -> Block.popResource(this.level(), this.blockPosition().above(), stack))); // CraftBukkit - add to drops // Paper - Restore vanilla drops behavior; mirror so we can destroy it later - though this call site was safe & spawn drops correctly - this.armorItems.set(ix, ItemStack.EMPTY); -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + ItemStack emptyStack = ItemStack.EMPTY; + ItemStack prevStack = this.armorItems.set(ix, ItemStack.EMPTY); + this.trackEquipChange(prevStack, emptyStack); -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } } return this.dropAllDeathLoot(level, damageSource); // CraftBukkit - moved from above // Paper @@ -363,13 +356,13 @@ index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95 this.updatePose(); } -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking if (this.noTickEquipmentDirty) { - this.noTickEquipmentDirty = false; this.detectEquipmentUpdatesPublic(); -+ this.noTickEquipmentDirty = false; ++ this.noTickEquipmentDirty = false; // Remove dirty mark after handling equipment update for armor stand } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking return; } @@ -378,14 +371,14 @@ index 8c0ab32487c56e2caf42404184f86c9bcf5f8b41..ccdbc67a50056ea1033f1f963c9f9a95 } // Purpur end - Movement options for armor stands + -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + private void trackEquipChange(ItemStack prevStack, ItemStack currStack) { + this.onEquipmentReplaced(prevStack, currStack); + } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } diff --git a/net/minecraft/world/item/ItemStack.java b/net/minecraft/world/item/ItemStack.java -index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052be3d117ae 100644 +index aa2c00be86f42a6674694a20545399e441b75199..fd7c1e800cbd4919a1a47f6c468c8776535bd028 100644 --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java @@ -95,7 +95,7 @@ import net.minecraft.world.level.saveddata.maps.MapId; @@ -393,7 +386,7 @@ index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052b import org.slf4j.Logger; -public final class ItemStack implements DataComponentHolder { -+public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangePublisher, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber { // Leaf - Lithium equipment tracking ++public final class ItemStack implements DataComponentHolder, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangePublisher, net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber { // Leaf - Lithium - equipment tracking private static final List OP_NBT_WARNING = List.of( Component.translatable("item.op_warning.line1").withStyle(ChatFormatting.RED, ChatFormatting.BOLD), Component.translatable("item.op_warning.line2").withStyle(ChatFormatting.RED), @@ -401,11 +394,11 @@ index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052b PatchedDataComponentMap components; @Nullable private Entity entityRepresentation; -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + @Nullable + private net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber; + private int subscriberData; -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking private static DataResult validateStrict(ItemStack stack) { DataResult dataResult = validateComponents(stack.getComponents()); @@ -413,7 +406,7 @@ index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052b } public void setCount(int count) { -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + if (count != this.count) { + if (this.subscriber instanceof net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber.CountChangeSubscriber countChangeSubscriber) { + countChangeSubscriber.notifyCount(this, this.subscriberData, count); @@ -427,7 +420,7 @@ index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052b + } + } + } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking this.count = count; } @@ -436,7 +429,7 @@ index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052b return repairable != null && repairable.isValidRepairItem(item); } + -+ // Leaf start - Lithium equipment tracking ++ // Leaf start - Lithium - equipment tracking + @Override + public void subscribe(net.caffeinemc.mods.lithium.common.util.change_tracking.ChangeSubscriber subscriber, int subscriberData) { + if (this.isEmpty()) { @@ -517,5 +510,5 @@ index aa2c00be86f42a6674694a20545399e441b75199..e183298a7fb538ee35ea1dc4f46d052b + private void startTrackingChanges() { + this.components.subscribe(this, 0); + } -+ // Leaf end - Lithium equipment tracking ++ // Leaf end - Lithium - equipment tracking } diff --git a/leaf-server/minecraft-patches/features/0104-C2ME-Optimize-world-gen-math.patch b/leaf-server/minecraft-patches/features/0104-C2ME-Optimize-world-gen-math.patch index 3b430344..7480271b 100644 --- a/leaf-server/minecraft-patches/features/0104-C2ME-Optimize-world-gen-math.patch +++ b/leaf-server/minecraft-patches/features/0104-C2ME-Optimize-world-gen-math.patch @@ -13,46 +13,48 @@ Licensed under: MIT Co-authored-by: Taiyou06 diff --git a/net/minecraft/world/level/ChunkPos.java b/net/minecraft/world/level/ChunkPos.java -index 55ce935a2fab7e32904d9ff599867269035d703f..f758602f1929fe0e19b91989d240b24d9d0d1ca6 100644 +index 55ce935a2fab7e32904d9ff599867269035d703f..6e2b2d258e47dcca30a5ad9f4f492598f2bc21fb 100644 --- a/net/minecraft/world/level/ChunkPos.java +++ b/net/minecraft/world/level/ChunkPos.java -@@ -110,7 +110,12 @@ public class ChunkPos { +@@ -110,7 +110,13 @@ public class ChunkPos { @Override public boolean equals(Object other) { - return this == other || other instanceof ChunkPos chunkPos && this.x == chunkPos.x && this.z == chunkPos.z; -+ // Leaf start - Use standard equals ++ // Leaf start - C2ME - Optimize world gen math ++ // Use standard equals + if (other == this) return true; + if (other == null || other.getClass() != this.getClass()) return false; + ChunkPos thatPos = (ChunkPos) other; + return this.x == thatPos.x && this.z == thatPos.z; -+ // Leaf end - Use standard equals ++ // Leaf end - C2ME - Optimize world gen math } public int getMiddleBlockX() { diff --git a/net/minecraft/world/level/levelgen/Beardifier.java b/net/minecraft/world/level/levelgen/Beardifier.java -index 131923282c9ecbcb1d7f45a826da907c02bd2716..3c05e8258902bf46cca3b7274858b7528cce6437 100644 +index 131923282c9ecbcb1d7f45a826da907c02bd2716..47b6519f40ed978c05d93023a0cdc1c9e13f033f 100644 --- a/net/minecraft/world/level/levelgen/Beardifier.java +++ b/net/minecraft/world/level/levelgen/Beardifier.java -@@ -132,8 +132,14 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker { +@@ -132,8 +132,15 @@ public class Beardifier implements DensityFunctions.BeardifierOrMarker { } private static double getBuryContribution(double x, double y, double z) { - double len = Mth.length(x, y, z); - return Mth.clampedMap(len, 0.0, 6.0, 1.0, 0.0); -+ // Leaf start - Optimize method for beardifier ++ // Leaf start - C2ME - Optimize world gen math ++ // Optimize method for beardifier + double len = Math.sqrt(x * x + y * y + z * z); + if (len > 6.0) { + return 0.0; + } else { + return 1.0 - len / 6.0; + } -+ // Leaf end - Optimize method for beardifier ++ // Leaf end - C2ME - Optimize world gen math } private static double getBeardContribution(int x, int y, int z, int height) { diff --git a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java -index 57ae4aaf1431021daf77c5638038d4910a358155..846d44798655ca11c311fd3fda3613de45b93906 100644 +index 57ae4aaf1431021daf77c5638038d4910a358155..d4317668df3b1a2ae1b6091b65dfa9da3582f967 100644 --- a/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java +++ b/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java @@ -68,8 +68,10 @@ public final class NoiseBasedChunkGenerator extends ChunkGenerator { @@ -61,15 +63,15 @@ index 57ae4aaf1431021daf77c5638038d4910a358155..846d44798655ca11c311fd3fda3613de Aquifer.FluidStatus fluidStatus1 = new Aquifer.FluidStatus(seaLevel, settings.defaultFluid()); - Aquifer.FluidStatus fluidStatus2 = new Aquifer.FluidStatus(DimensionType.MIN_Y * 2, Blocks.AIR.defaultBlockState()); - return (x, y, z) -> y < Math.min(-54, seaLevel) ? fluidStatus : fluidStatus1; -+ // Leaf start - Optimize world gen ++ // Leaf start - C2ME - Optimize world gen math + final int min = Math.min(-54, seaLevel); + return (x, y, z) -> y < min ? fluidStatus : fluidStatus1; -+ // Leaf end - Optimize world gen ++ // Leaf end - C2ME - Optimize world gen math } @Override diff --git a/net/minecraft/world/level/levelgen/synth/PerlinNoise.java b/net/minecraft/world/level/levelgen/synth/PerlinNoise.java -index 2c28bb2fed04542a2ee126fe0c1c1f0253a3e2eb..3ede9b09feface73096db746b8a7960b654a7eaf 100644 +index 2c28bb2fed04542a2ee126fe0c1c1f0253a3e2eb..5632cfde8118bd8db79b9abdb8b57edf94c44f96 100644 --- a/net/minecraft/world/level/levelgen/synth/PerlinNoise.java +++ b/net/minecraft/world/level/levelgen/synth/PerlinNoise.java @@ -215,7 +215,7 @@ public class PerlinNoise { @@ -77,7 +79,7 @@ index 2c28bb2fed04542a2ee126fe0c1c1f0253a3e2eb..3ede9b09feface73096db746b8a7960b public static double wrap(double value) { - return value - Mth.lfloor(value / 3.3554432E7 + 0.5) * 3.3554432E7; -+ return value - Math.floor(value / 3.3554432E7 + 0.5) * 3.3554432E7; // Leaf - Avoid casting ++ return value - Math.floor(value / 3.3554432E7 + 0.5) * 3.3554432E7; // Leaf - C2ME - Optimize world gen math - Avoid casting } protected int firstOctave() { diff --git a/leaf-server/minecraft-patches/features/0107-Cache-part-of-canHoldFluid-result.patch b/leaf-server/minecraft-patches/features/0107-Cache-part-of-canHoldFluid-result.patch index e2e34b6d..cc9557f9 100644 --- a/leaf-server/minecraft-patches/features/0107-Cache-part-of-canHoldFluid-result.patch +++ b/leaf-server/minecraft-patches/features/0107-Cache-part-of-canHoldFluid-result.patch @@ -10,7 +10,7 @@ which the contains iteration call is very expensive if called everytime In the test, it can improve ~30% performance in ~1577000 times of canHoldAnyFluid calls (~159ms -> ~111ms) diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java -index 36ac6114cc3449a3b344baac5f3034288cf77a63..fb0843e26e5ee2834fd9917e9d929cb06d915eca 100644 +index 7f46f33fa565fa1a3aedce5524f19be8ba420352..d35211b0cae66b1a40e89539507e55973313f46f 100644 --- a/net/minecraft/world/level/block/state/BlockBehaviour.java +++ b/net/minecraft/world/level/block/state/BlockBehaviour.java @@ -454,6 +454,8 @@ public abstract class BlockBehaviour implements FeatureElement { @@ -51,18 +51,9 @@ index 36ac6114cc3449a3b344baac5f3034288cf77a63..fb0843e26e5ee2834fd9917e9d929cb0 public boolean isSolid() { return this.legacySolid; diff --git a/net/minecraft/world/level/material/FlowingFluid.java b/net/minecraft/world/level/material/FlowingFluid.java -index c535cd03c577d76c3b19da5a8426d0cbee3069f0..2bb220d0442f3c8593c40af2eb559c312c8f47b3 100644 +index 738defb8cbd9c63dc85c479911ebe2f795d0a815..4c2c2efd5380ff1fa5ad7553b51babae20f516ae 100644 --- a/net/minecraft/world/level/material/FlowingFluid.java +++ b/net/minecraft/world/level/material/FlowingFluid.java -@@ -450,7 +450,7 @@ public abstract class FlowingFluid extends Fluid { - return map; - } - -- private static boolean canHoldAnyFluid(BlockState state) { -+ public static boolean canHoldAnyFluid(BlockState state) { // Leaf - Cache part of canHoldFluid result - private -> public - Block block = state.getBlock(); - return block instanceof LiquidBlockContainer - || !state.blocksMotion() @@ -466,7 +466,7 @@ public abstract class FlowingFluid extends Fluid { } diff --git a/leaf-server/src/main/java/org/dreeam/leaf/async/AsyncPlayerDataSaving.java b/leaf-server/src/main/java/org/dreeam/leaf/async/AsyncPlayerDataSaving.java index b5e661cd..5e728625 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/async/AsyncPlayerDataSaving.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/async/AsyncPlayerDataSaving.java @@ -18,6 +18,7 @@ public class AsyncPlayerDataSaving { } ExecutorService ioExecutor = Util.backgroundExecutor().service(); + CompletableFuture.runAsync(runnable, ioExecutor); } }