9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-30 20:39:21 +00:00

[ci skip] cleanup

stage 3
This commit is contained in:
Dreeam
2025-05-15 23:39:22 -04:00
parent a56de1a3b0
commit 6533fde2d8
4 changed files with 52 additions and 52 deletions

View File

@@ -5,28 +5,30 @@ Subject: [PATCH] Async target finding
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf758211deec0cf 100644
index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..561723eeb1dd80f7fdd9aff33f6e1c4c16def0ff 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
@@ -40,8 +40,8 @@ public final class ChunkEntitySlices {
@@ -40,8 +40,10 @@ public final class ChunkEntitySlices {
private final EntityCollectionBySection allEntities;
private final EntityCollectionBySection hardCollidingEntities;
- private final Reference2ObjectOpenHashMap<Class<? extends Entity>, EntityCollectionBySection> entitiesByClass;
- private final Reference2ObjectOpenHashMap<EntityType<?>, EntityCollectionBySection> entitiesByType;
+ private final Reference2ObjectMap<Class<? extends Entity>, EntityCollectionBySection> entitiesByClass; // Leaf
+ private final Reference2ObjectMap<EntityType<?>, EntityCollectionBySection> entitiesByType; // Leaf
+ // Leaf start - Async target finding
+ private final Reference2ObjectMap<Class<? extends Entity>, EntityCollectionBySection> entitiesByClass;
+ private final Reference2ObjectMap<EntityType<?>, EntityCollectionBySection> entitiesByType;
+ // Leaf end - Async target finding
private final EntityList entities = new EntityList();
public FullChunkStatus status;
@@ -67,9 +67,16 @@ public final class ChunkEntitySlices {
@@ -67,9 +69,15 @@ public final class ChunkEntitySlices {
this.allEntities = new EntityCollectionBySection(this);
this.hardCollidingEntities = new EntityCollectionBySection(this);
- this.entitiesByClass = new Reference2ObjectOpenHashMap<>();
- this.entitiesByType = new Reference2ObjectOpenHashMap<>();
+ // Leaf start
-
+ // Leaf start - Async target finding
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
+ this.entitiesByClass = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>());
+ this.entitiesByType = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>());
@@ -34,18 +36,18 @@ index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf75821
+ this.entitiesByClass = new Reference2ObjectOpenHashMap<>();
+ this.entitiesByType = new Reference2ObjectOpenHashMap<>();
+ }
+ // Leaf end
+ // Leaf end - Async target finding
this.status = status;
this.chunkData = chunkData;
}
@@ -248,14 +255,26 @@ public final class ChunkEntitySlices {
@@ -248,14 +256,26 @@ public final class ChunkEntitySlices {
this.hardCollidingEntities.addEntity(entity, sectionIndex);
}
- for (final Iterator<Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection>> iterator =
- this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) {
- final Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection> entry = iterator.next();
+ // Leaf start
+ // Leaf start - Async target finding
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
+ synchronized (this.entitiesByClass) {
+ for (final var entry : this.entitiesByClass.reference2ObjectEntrySet()) {
@@ -66,18 +68,18 @@ index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf75821
+ }
}
}
+ // Leaf end
+ // Leaf end - Async target finding
EntityCollectionBySection byType = this.entitiesByType.get(entity.getType());
if (byType != null) {
@@ -282,14 +301,27 @@ public final class ChunkEntitySlices {
@@ -282,14 +302,27 @@ public final class ChunkEntitySlices {
this.hardCollidingEntities.removeEntity(entity, sectionIndex);
}
- for (final Iterator<Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection>> iterator =
- this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) {
- final Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection> entry = iterator.next();
+ // Leaf start
+ // Leaf start - Async target finding
+ if (org.dreeam.leaf.config.modules.async.AsyncTargetFinding.enabled) {
+ synchronized (this.entitiesByClass) {
+ for (final var entry : this.entitiesByClass.reference2ObjectEntrySet()) {
@@ -98,7 +100,7 @@ index b6af8da084c83ee38bb3ecea6a98feb0c1c74d2a..635d6aabbbe9be5c81a71d5e5bf75821
+ }
}
}
+ // Leaf end
+ // Leaf end - Async target finding
+
final EntityCollectionBySection byType = this.entitiesByType.get(entity.getType());
@@ -667,7 +669,7 @@ index 3093f03d4f298bf39fec8bad2b6c22518774aea8..0a41797fd7beddce0b93d42bac6e0270
} else {
this.parent = animal;
diff --git a/net/minecraft/world/entity/ai/goal/GoalSelector.java b/net/minecraft/world/entity/ai/goal/GoalSelector.java
index e82e32407cec6109b9c3b0106295217f4a3f4aa2..a177505c84697b93d828db9f111bdeb14f57de43 100644
index e82e32407cec6109b9c3b0106295217f4a3f4aa2..3c24382a3cced8dcea103ccc87cb506310de8461 100644
--- a/net/minecraft/world/entity/ai/goal/GoalSelector.java
+++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java
@@ -26,13 +26,23 @@ public class GoalSelector {
@@ -684,37 +686,39 @@ index e82e32407cec6109b9c3b0106295217f4a3f4aa2..a177505c84697b93d828db9f111bdeb1
+
public void addGoal(int priority, Goal goal) {
this.availableGoals.add(new WrappedGoal(priority, goal));
+ availableGoalsDirty = true; // Leaf
+ availableGoalsDirty = true; // Leaf - Async target finding
}
@VisibleForTesting
public void removeAllGoals(Predicate<Goal> filter) {
this.availableGoals.removeIf(wrappedGoal -> filter.test(wrappedGoal.getGoal()));
+ availableGoalsDirty = true; // Leaf
+ availableGoalsDirty = true; // Leaf - Async target finding
}
// Paper start - EAR 2
@@ -63,16 +73,19 @@ public class GoalSelector {
@@ -63,18 +73,19 @@ public class GoalSelector {
}
this.availableGoals.removeIf(wrappedGoal1 -> wrappedGoal1.getGoal() == goal);
+ availableGoalsDirty = true; // Leaf
+ availableGoalsDirty = true; // Leaf - Async target finding
}
// Paper start - Perf: optimize goal types
private static boolean goalContainsAnyFlags(WrappedGoal goal, ca.spottedleaf.moonrise.common.set.OptimizedSmallEnumSet<Goal.Flag> flags) {
+ // Leaf - inline diff
return goal.getFlags().hasCommonElements(flags);
- return goal.getFlags().hasCommonElements(flags);
+ return goal.getFlags().hasCommonElements(flags); // Leaf - Async target finding - inline diff
}
private static boolean goalCanBeReplacedForAllFlags(WrappedGoal goal, Map<Goal.Flag, WrappedGoal> flag) {
long flagIterator = goal.getFlags().getBackingSet();
int wrappedGoalSize = goal.getFlags().size();
+ // Leaf - inline diff
for (int i = 0; i < wrappedGoalSize; ++i) {
final Goal.Flag flag1 = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)];
- final Goal.Flag flag1 = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)];
+ final Goal.Flag flag1 = GOAL_FLAG_VALUES[Long.numberOfTrailingZeros(flagIterator)]; // Leaf - Async target finding - inline diff
flagIterator ^= ca.spottedleaf.concurrentutil.util.IntegerUtil.getTrailingBit(flagIterator);
@@ -85,7 +98,131 @@ public class GoalSelector {
// Paper end - Perf: optimize goal types
if (!flag.getOrDefault(flag1, NO_GOAL).canBeReplacedBy(goal)) {
@@ -85,7 +96,131 @@ public class GoalSelector {
return true;
}
@@ -846,7 +850,7 @@ index e82e32407cec6109b9c3b0106295217f4a3f4aa2..a177505c84697b93d828db9f111bdeb1
for (WrappedGoal wrappedGoal : this.availableGoals) {
if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.goalTypes) || !wrappedGoal.canContinueToUse())) { // Paper - Perf: optimize goal types by removing streams
wrappedGoal.stop();
@@ -116,6 +253,18 @@ public class GoalSelector {
@@ -116,6 +251,18 @@ public class GoalSelector {
}
public void tickRunningGoals(boolean tickAllRunning) {

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Sakura: copy-EntityList-implementation-to-BasicEntityList
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d9fc6fdd8 100644
index 561723eeb1dd80f7fdd9aff33f6e1c4c16def0ff..1acf552d915f72929e1a68d9c769dd8a9026514f 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
@@ -414,6 +414,13 @@ public final class ChunkEntitySlices {
@@ -415,6 +415,13 @@ public final class ChunkEntitySlices {
private E[] storage;
private int size;
@@ -22,7 +22,7 @@ index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d
public BasicEntityList() {
this(0);
@@ -434,6 +441,7 @@ public final class ChunkEntitySlices {
@@ -435,6 +442,7 @@ public final class ChunkEntitySlices {
private void resize() {
if (this.storage == me.titaniumtown.ArrayConstants.emptyEntityArray) { // Gale - JettPack - reduce array allocations
this.storage = (E[])new Entity[DEFAULT_CAPACITY];
@@ -30,7 +30,7 @@ index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d
} else {
this.storage = Arrays.copyOf(this.storage, this.storage.length * 2);
}
@@ -447,6 +455,7 @@ public final class ChunkEntitySlices {
@@ -448,6 +456,7 @@ public final class ChunkEntitySlices {
} else {
this.storage[idx] = entity;
}
@@ -38,7 +38,7 @@ index 635d6aabbbe9be5c81a71d5e5bf758211deec0cf..a45f4eb235a7823fce84948ad556c36d
}
public int indexOf(final E entity) {
@@ -462,24 +471,32 @@ public final class ChunkEntitySlices {
@@ -463,24 +472,32 @@ public final class ChunkEntitySlices {
}
public boolean remove(final E entity) {

View File

@@ -5,80 +5,80 @@ Subject: [PATCH] Protocol Core
diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
index 7e19dfe90a63ff26f03b95891dacb7360bba5a3c..d20ffa172227f85b9fd6ac5e2766f6ebd2d07638 100644
index 7e19dfe90a63ff26f03b95891dacb7360bba5a3c..5d0961f06c23121883c4f0b889ccdf32f06e8a35 100644
--- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
+++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
@@ -47,6 +47,12 @@ public interface CustomPacketPayload {
return;
}
// Leaves end - protocol core
+ // Leaf start - protocol
+ // Leaf start - Protocol core
+ if (value instanceof org.dreeam.leaf.protocol.LeafCustomPayload payload) {
+ org.dreeam.leaf.protocol.Protocols.write(buffer, payload);
+ return;
+ }
+ // Leaf end - protocol
+ // Leaf end - Protocol core
this.writeCap(buffer, value.type(), value);
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 98af1ad020a003db66d7319f33d43deec315aec5..e04a6db55d936277f2a852374f11d483d79a90ed 100644
index 98af1ad020a003db66d7319f33d43deec315aec5..9669036e6b7f1830888e48c99acb01d443f4e9f0 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1839,6 +1839,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(); // Leaves - protocol
+ org.dreeam.leaf.protocol.Protocols.tickServer(this); // Leaf - protocol
+ org.dreeam.leaf.protocol.Protocols.tickServer(this); // Leaf - Protocol core
for (int i = 0; i < this.tickables.size(); i++) {
this.tickables.get(i).run();
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
index 38314fcb660f6cbb36d60434d24df5b579425eb3..f17980536b98f20443556ed294c970bc2d570bbb 100644
index be3057119bcbce4a4f72284fa7ba8f60ba43f397..65caf86832b3f33ad87208eb37b44ef2d8a2ec4e 100644
--- a/net/minecraft/server/level/ServerEntity.java
+++ b/net/minecraft/server/level/ServerEntity.java
@@ -283,6 +283,7 @@ public class ServerEntity {
this.entity.hurtMarked = false;
this.broadcastAndSend(new ClientboundSetEntityMotionPacket(this.entity));
}
+ if (entity instanceof ServerPlayer serverPlayer) { org.dreeam.leaf.protocol.Protocols.tickTracker(serverPlayer); } // Leaf - protocol
+ if (entity instanceof ServerPlayer serverPlayer) org.dreeam.leaf.protocol.Protocols.tickTracker(serverPlayer); // Leaf - Protocol core
}
// Purpur start
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 09f517059aa47ca67329bc913243d4fdee09abe5..43c4b8e54842310e48bcdaa991c68ff9571d7249 100644
index 09f517059aa47ca67329bc913243d4fdee09abe5..50cf63666071f5d01a85dfc6c6c45c19b05d8ec2 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -859,6 +859,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
}
}
// Purpur end - Ridables
+ org.dreeam.leaf.protocol.Protocols.tickPlayer(this); // Leaf - protocol
+ org.dreeam.leaf.protocol.Protocols.tickPlayer(this); // Leaf - Protocol core
}
private void updatePlayerAttributes() {
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index 96b70c1384834a8e22925c8e2af85ab7606dde20..9570ab0fcf62fef04c039ab0de72e8293fa29950 100644
index 96b70c1384834a8e22925c8e2af85ab7606dde20..9eb14bb38416330878959c4b095d057ce0e4fe92 100644
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -167,6 +167,8 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
+ org.dreeam.leaf.protocol.Protocols.handle(this.player, discardedPayload); // Leaf - protocol
+ org.dreeam.leaf.protocol.Protocols.handle(this.player, discardedPayload); // Leaf - Protocol core
+
final net.minecraft.resources.ResourceLocation identifier = packet.payload().type().id();
final byte[] data = discardedPayload.data();
try {
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 842cb6efc8aa7c68b7b9cba144d8540679850f23..db079ee9a957972a0e7199d885165eead128b81e 100644
index 842cb6efc8aa7c68b7b9cba144d8540679850f23..857e5823038192931b89a8b638a9a6b1fd0f9b5c 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -682,6 +682,7 @@ public abstract class PlayerList {
}
public net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) {
org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(player); // Leaves - protocol
+ org.dreeam.leaf.protocol.Protocols.disconnected(player); // Leaf - protocol
+ org.dreeam.leaf.protocol.Protocols.disconnected(player); // Leaf - Protocol core
// Paper end - Fix kick event leave message not being sent
org.purpurmc.purpur.task.BossBarTask.removeFromAll(player.getBukkitEntity()); // Purpur - Implement TPSBar
net.minecraft.server.network.ServerGamePacketListenerImpl.afkCooldown.remove(player.getBukkitEntity().getUniqueId()); // Leaf - Improve Purpur AFK system

View File

@@ -5,28 +5,24 @@ Subject: [PATCH] reduce PlayerChunk Updates
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index abe79d07196de0a10a382d4c37161c7eb4a604ae..405b8da8b886b5caac7ed774472e106374c42185 100644
index abe79d07196de0a10a382d4c37161c7eb4a604ae..51079419496900b86ff5e9ed41150831681e6d0b 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1367,6 +1367,10 @@ public class ServerGamePacketListenerImpl
@@ -1367,6 +1367,8 @@ public class ServerGamePacketListenerImpl
this.resetPosition();
}
+ // Leaf start - ReduceChunkSourceUpdates
+ final net.minecraft.world.level.ChunkPos playerStartChunkPosition = this.player.chunkPosition();
+ // Leaf end - ReduceChunkSourceUpdates
+ final net.minecraft.world.level.ChunkPos playerStartChunkPosition = this.player.chunkPosition(); // Leaf - Reduce PlayerChunk Updates
+
if (!this.updateAwaitingTeleport() && this.player.hasClientLoaded()) {
double d = clampHorizontal(packet.getX(this.player.getX())); final double toX = d; // Paper - OBFHELPER
double d1 = clampVertical(packet.getY(this.player.getY())); final double toY = d1; // Paper - OBFHELPER
@@ -1638,7 +1642,9 @@ public class ServerGamePacketListenerImpl
@@ -1638,7 +1640,7 @@ public class ServerGamePacketListenerImpl
&& !isFallFlying
&& !isAutoSpinAttack
&& this.noBlocksAround(this.player);
- this.player.serverLevel().getChunkSource().move(this.player);
+ if (!org.dreeam.leaf.config.modules.opt.ReduceChunkSourceUpdates.enabled || this.player.serverLevel() != serverLevel || this.player.chunkPosition() == playerStartChunkPosition) {
+ this.player.serverLevel().getChunkSource().move(this.player);
+ }
+ if (!org.dreeam.leaf.config.modules.opt.ReduceChunkSourceUpdates.enabled || this.player.serverLevel() != serverLevel || this.player.chunkPosition() == playerStartChunkPosition) this.player.serverLevel().getChunkSource().move(this.player); // Leaf - Reduce PlayerChunk Updates
Vec3 vec3 = new Vec3(this.player.getX() - x, this.player.getY() - y, this.player.getZ() - z);
this.player.setOnGroundWithMovement(packet.isOnGround(), packet.horizontalCollision(), vec3);
this.player.doCheckFallDamage(vec3.x, vec3.y, vec3.z, packet.isOnGround());