9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Join Summit - palm of my hands (Odd Mob Remix)

Genre: Tech House
This commit is contained in:
Dreeam
2025-04-07 17:41:47 -04:00
parent 5e1be48cf8
commit 6a07ebf769
38 changed files with 343 additions and 260 deletions

View File

@@ -1,213 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Wed, 23 Oct 2024 23:54:00 +0800
Subject: [PATCH] Asynchronous locator
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..e3e7c4e4da0bc95b015bb84e470477782bdb691c 100644
--- a/net/minecraft/server/commands/LocateCommand.java
+++ b/net/minecraft/server/commands/LocateCommand.java
@@ -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 - 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) {
+ BlockPos originPos = BlockPos.containing(source.getPosition());
+
+ org.dreeam.leaf.async.locate.AsyncLocator.locate(source.getLevel(), holderSet, originPos, 100, false)
+ .thenOnServerThread(pair -> {
+ stopwatch.stop();
+ if (pair != null) {
+ showLocateResult(
+ source,
+ structure,
+ originPos,
+ pair,
+ "commands.locate.structure.success",
+ false,
+ stopwatch.elapsed()
+ );
+ } else {
+ source.sendFailure(
+ Component.literal(
+ ERROR_STRUCTURE_NOT_FOUND.create(structure.asPrintable()).getMessage()
+ )
+ );
+ }
+ });
+
+ return 0;
+ }
+ }
+ // Leaf end - Asynchronous locator
Pair<BlockPos, Holder<Structure>> 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..3ed9652510976770f5661dd7b317f27f046700d4 100644
--- a/net/minecraft/world/entity/animal/Dolphin.java
+++ b/net/minecraft/world/entity/animal/Dolphin.java
@@ -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 +523,11 @@ public class Dolphin extends AgeableWaterCreature {
@Override
public boolean canContinueToUse() {
+ // Leaf start - Asynchronous locator
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) {
+ return true;
+ }
+ // 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 +541,22 @@ public class Dolphin extends AgeableWaterCreature {
this.stuck = false;
this.dolphin.getNavigation().stop();
BlockPos blockPos = this.dolphin.blockPosition();
+ // 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 -> {
+ asyncLocator$locateTask = null;
+ if (pos != null) {
+ this.dolphin.setTreasurePos(pos);
+ serverLevel.broadcastEntityEvent(this.dolphin, (byte) 38);
+ } else {
+ this.stuck = true;
+ }
+ });
+
+ return;
+ }
+ // Leaf end - Asynchronous locator
BlockPos blockPos1 = serverLevel.findNearestMapStructure(StructureTags.DOLPHIN_LOCATED, blockPos, 50, false);
if (blockPos1 != null) {
this.dolphin.setTreasurePos(blockPos1);
@@ -544,6 +569,12 @@ public class Dolphin extends AgeableWaterCreature {
@Override
public void stop() {
+ // 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 - 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 +585,11 @@ public class Dolphin extends AgeableWaterCreature {
@Override
public void tick() {
+ // Leaf start - Asynchronous locator
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTask != null) {
+ return;
+ }
+ // 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..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 - Asynchronous locator
public EyeOfEnder(EntityType<? extends EyeOfEnder> entityType, Level level) {
super(entityType, level);
@@ -112,6 +113,11 @@ public class EyeOfEnder extends Entity implements ItemSupplier {
@Override
public void tick() {
super.tick();
+ // Leaf start - Asynchronous locator
+ if (org.dreeam.leaf.config.modules.async.AsyncLocator.enabled && this.asyncLocator$locateTaskOngoing) {
+ return;
+ }
+ // 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..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 {
} else {
player.startUsingItem(hand);
if (level instanceof ServerLevel serverLevel) {
- BlockPos blockPos = serverLevel.findNearestMapStructure(StructureTags.EYE_OF_ENDER_LOCATED, player.blockPosition(), 100, false);
+ // 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 - Asynchronous locator
if (blockPos == null) {
return InteractionResult.CONSUME;
}
EyeOfEnder eyeOfEnder = new EyeOfEnder(level, player.getX(), player.getY(0.5), player.getZ());
+
+ // Leaf start - Asynchronous locator
+ final boolean isAsyncLocatorEnabled = org.dreeam.leaf.config.modules.async.AsyncLocator.enabled;
+
+ if (isAsyncLocatorEnabled) {
+ eyeOfEnder.asyncLocator$locateTaskOngoing = true;
+ org.dreeam.leaf.async.locate.AsyncLocator.locate(
+ serverLevel,
+ StructureTags.EYE_OF_ENDER_LOCATED,
+ player.blockPosition(),
+ 100,
+ false
+ ).thenOnServerThread(pos -> {
+ eyeOfEnder.asyncLocator$locateTaskOngoing = false;
+ if (pos != null) {
+ eyeOfEnder.signalTo(pos);
+ CriteriaTriggers.USED_ENDER_EYE.trigger((ServerPlayer) player, pos);
+ player.awardStat(Stats.ITEM_USED.get(this));
+ } else {
+ // Set the entity's life to long enough that it dies
+ eyeOfEnder.life = Integer.MAX_VALUE - 100;
+ }
+ });
+ }
+ // Leaf end - Asynchronous locator
+
eyeOfEnder.setItem(itemInHand);
- eyeOfEnder.signalTo(blockPos);
+ 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)) {
@@ -124,7 +157,7 @@ public class EnderEyeItem extends Item {
float f = Mth.lerp(level.random.nextFloat(), 0.33F, 0.5F);
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 - Asynchronous locator
}
return InteractionResult.SUCCESS_SERVER;

View File

@@ -1,127 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Smart sort entities in NearestLivingEntitySensor
Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
FastBitRadix Sort will be used. (see https://ieeexplore.ieee.org/document/7822019 for more)
When entity count reached the threshold, Bucket Sort will be used.
In non-strict test, this can give ~60-110% improvement (524ms on Paper, 204ms on Leaf),
under 625 villagers situation.
diff --git a/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java b/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..83af90c7a2e425b775abd7907895d211ced07955 100644
--- a/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
+++ b/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
@@ -13,18 +13,102 @@ import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
import net.minecraft.world.phys.AABB;
public class NearestLivingEntitySensor<T extends LivingEntity> extends Sensor<T> {
+
+ // Leaf start - Optimized entity sorting with buffer reuse
+ private static final int SMALL_ARRAY_THRESHOLD = 2;
+ private LivingEntity[] entityBuffer = new LivingEntity[0];
+ private long[] bitsBuffer = new long[0];
+
@Override
protected void doTick(ServerLevel level, T entity) {
- double attributeValue = entity.getAttributeValue(Attributes.FOLLOW_RANGE);
- AABB aabb = entity.getBoundingBox().inflate(attributeValue, attributeValue, attributeValue);
- List<LivingEntity> entitiesOfClass = level.getEntitiesOfClass(
- LivingEntity.class, aabb, matchableEntity -> matchableEntity != entity && matchableEntity.isAlive()
+ double range = entity.getAttributeValue(Attributes.FOLLOW_RANGE);
+ double rangeSqr = range * range;
+ AABB aabb = entity.getBoundingBox().inflate(range, range, range);
+
+ List<LivingEntity> entities = level.getEntitiesOfClass(
+ LivingEntity.class, aabb, e -> e != entity && e.isAlive() && entity.distanceToSqr(e) <= rangeSqr
);
- entitiesOfClass.sort(Comparator.comparingDouble(entity::distanceToSqr));
+
+ LivingEntity[] sorted = smartSort(entities, entity);
+ List<LivingEntity> sortedList = java.util.Arrays.asList(sorted);
+
Brain<?> brain = entity.getBrain();
- brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, entitiesOfClass);
- brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(level, entity, entitiesOfClass));
+ brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, sortedList);
+ brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES,
+ new NearestVisibleLivingEntities(level, entity, sortedList));
+ }
+
+ private LivingEntity[] smartSort(List<LivingEntity> entities, T reference) {
+ int size = entities.size();
+ if (size <= 1) return entities.toArray(new LivingEntity[0]);
+
+ if (entityBuffer.length < size) {
+ entityBuffer = new LivingEntity[size];
+ bitsBuffer = new long[size];
+ }
+
+ for (int i = 0; i < size; i++) {
+ LivingEntity e = entities.get(i);
+ entityBuffer[i] = e;
+ bitsBuffer[i] = Double.doubleToRawLongBits(reference.distanceToSqr(e));
+ }
+
+ fastRadixSort(entityBuffer, bitsBuffer, 0, size - 1, 62);
+
+ return java.util.Arrays.copyOf(entityBuffer, size);
+ }
+
+ private void fastRadixSort(LivingEntity[] ents, long[] bits, int low, int high, int bit) {
+ if (bit < 0 || low >= high) return;
+
+ if (high - low <= SMALL_ARRAY_THRESHOLD) {
+ insertionSort(ents, bits, low, high);
+ return;
+ }
+
+ int i = low, j = high;
+ final long mask = 1L << bit;
+
+ while (i <= j) {
+ while (i <= j && (bits[i] & mask) == 0) i++;
+ while (i <= j && (bits[j] & mask) != 0) j--;
+
+ if (i < j) {
+ swap(ents, bits, i++, j--);
+ }
+ }
+
+ if (low < j) fastRadixSort(ents, bits, low, j, bit - 1);
+ if (i < high) fastRadixSort(ents, bits, i, high, bit - 1);
+ }
+
+ private void insertionSort(LivingEntity[] ents, long[] bits, int low, int high) {
+ for (int i = low + 1; i <= high; i++) {
+ int j = i;
+ LivingEntity e = ents[j];
+ long b = bits[j];
+
+ while (j > low && bits[j - 1] > b) {
+ ents[j] = ents[j - 1];
+ bits[j] = bits[j - 1];
+ j--;
+ }
+
+ ents[j] = e;
+ bits[j] = b;
+ }
+ }
+
+ private void swap(LivingEntity[] ents, long[] bits, int a, int b) {
+ LivingEntity te = ents[a];
+ ents[a] = ents[b];
+ ents[b] = te;
+
+ long tb = bits[a];
+ bits[a] = bits[b];
+ bits[b] = tb;
}
+ // Leaf end - Optimized entity sorting with buffer reuse
@Override
public Set<MemoryModuleType<?>> requires() {

View File

@@ -1,42 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Sat, 26 Oct 2024 22:38:30 +0800
Subject: [PATCH] Further reduce memory footprint of CompoundTag
Original license: GPLv3
Original project: https://github.com/embeddedt/ModernFix
diff --git a/net/minecraft/nbt/CompoundTag.java b/net/minecraft/nbt/CompoundTag.java
index 3bce1e8ef90e95abd8b1111f1160f952d2493e69..468566e8175d71e1562a80fae8e5f0cd32318c35 100644
--- a/net/minecraft/nbt/CompoundTag.java
+++ b/net/minecraft/nbt/CompoundTag.java
@@ -49,7 +49,7 @@ public class CompoundTag implements Tag {
private static CompoundTag loadCompound(DataInput input, NbtAccounter nbtAccounter) throws IOException {
nbtAccounter.accountBytes(48L);
- it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - Reduce memory footprint of CompoundTag
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new org.dreeam.leaf.util.map.StringCanonizingOpenHashMap<>(8, 0.8f); // Paper - Reduce memory footprint of CompoundTag // Leaf - Further reduce memory footprint of CompoundTag
byte b;
while ((b = input.readByte()) != 0) {
@@ -166,7 +166,7 @@ public class CompoundTag implements Tag {
}
public CompoundTag() {
- this(new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f)); // Paper - Reduce memory footprint of CompoundTag
+ this(new org.dreeam.leaf.util.map.StringCanonizingOpenHashMap<>(8, 0.8f)); // Paper - Reduce memory footprint of CompoundTag // Leaf - Further reduce memory footprint of CompoundTag
}
@Override
@@ -497,6 +497,11 @@ public class CompoundTag implements Tag {
@Override
public CompoundTag copy() {
+ // Leaf start - Further reduce memory footprint of CompoundTag
+ if (this.tags instanceof org.dreeam.leaf.util.map.StringCanonizingOpenHashMap<Tag> stringCanonizingTags) {
+ return new CompoundTag(org.dreeam.leaf.util.map.StringCanonizingOpenHashMap.deepCopy(stringCanonizingTags, Tag::copy));
+ }
+ // Leaf end - Further reduce memory footprint of CompoundTag
// Paper start - Reduce memory footprint of CompoundTag
it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> ret = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(this.tags.size(), 0.8f);
java.util.Iterator<java.util.Map.Entry<String, Tag>> iterator = (this.tags instanceof it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) ? ((it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)this.tags).object2ObjectEntrySet().fastIterator() : this.tags.entrySet().iterator();

View File

@@ -1,80 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Fri, 29 Oct 2077 00:00:00 +0800
Subject: [PATCH] Optimize Entity distanceToSqr
This patch optimizes Entity#distanceToSqr call by using Math#fma which is around 1.2x to 4x faster than original method,
avoids multiple casting in Entity#distanceTo, using Math#sqrt directly instead of Mojang's Mth#sqrt. Additionally, this patch makes
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 4d88aa70c01e03baf8aea897b00f335c7be91f46..4544dd876d3cbcdb9b774b4a1f0c4737f3124bc5 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -2194,31 +2194,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return new Vec3(this.xOld, this.yOld, this.zOld);
}
- public float distanceTo(Entity entity) {
- float f = (float)(this.getX() - entity.getX());
- float f1 = (float)(this.getY() - entity.getY());
- float f2 = (float)(this.getZ() - entity.getZ());
- return Mth.sqrt(f * f + f1 * f1 + f2 * f2);
- }
-
- public double distanceToSqr(double x, double y, double z) {
- double d = this.getX() - x;
- double d1 = this.getY() - y;
- double d2 = this.getZ() - z;
- return d * d + d1 * d1 + d2 * d2;
- }
-
- 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;
- }
-
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;
+ }
+
+ public double distanceToSqr(Entity entity) {
+ return this.distanceToSqr(entity.position());
+ }
+ // Leaf end - Optimize Entity distanceToSqr
}

View File

@@ -1,23 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 7 Nov 2017 00:01:04 -0500
Subject: [PATCH] EMC: Don't use snapshots for TileEntity::getOwner
Original license: MIT
Original project: https://github.com/starlis/empirecraft
Also see Leaf's EMC-Don-t-use-snapshots-for-acquiring-blockstate
diff --git a/net/minecraft/world/level/block/entity/BlockEntity.java b/net/minecraft/world/level/block/entity/BlockEntity.java
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 {
// CraftBukkit start - add method
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 for TileEntity::getOwner
}
public org.bukkit.inventory.InventoryHolder getOwner(boolean useSnapshot) {
// Paper end

View File

@@ -1,59 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Fri, 25 Oct 2024 22:27:07 -0400
Subject: [PATCH] Cache tile entity position
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 290163335cf3967e2745442fd7d4d4fa16fb7bc0..238e015d4ff5fabb99e569118f253366d545d269 100644
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -936,10 +936,12 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
private final T blockEntity;
private final BlockEntityTicker<T> ticker;
private boolean loggedInvalidBlockState;
+ private final BlockPos cachedPos; // Leaf - Cache tile entity position
BoundTickingBlockEntity(final T blockEntity, final BlockEntityTicker<T> ticker) {
this.blockEntity = blockEntity;
this.ticker = ticker;
+ this.cachedPos = this.blockEntity.getBlockPos(); // Leaf - Cache tile entity position
}
@Override
@@ -980,7 +982,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@Override
public BlockPos getPos() {
- return this.blockEntity.getBlockPos();
+ return this.cachedPos; // Leaf - Cache tile entity position
}
@Override
@@ -1007,13 +1009,16 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
static class RebindableTickingBlockEntityWrapper implements TickingBlockEntity {
private TickingBlockEntity ticker;
+ private BlockPos cachedPos; // Leaf - Cache tile entity position
RebindableTickingBlockEntityWrapper(TickingBlockEntity ticker) {
this.ticker = ticker;
+ this.cachedPos = this.ticker.getPos(); // Leaf - Cache tile entity position
}
void rebind(TickingBlockEntity ticker) {
this.ticker = ticker;
+ this.cachedPos = this.ticker.getPos(); // Leaf - Cache tile entity position
}
@Override
@@ -1028,7 +1033,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
@Override
public BlockPos getPos() {
- return this.ticker.getPos();
+ return this.cachedPos; // Leaf - Cache tile entity position
}
@Override

View File

@@ -1,58 +0,0 @@
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
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 1cb60107d95296fc9e2c106d70838c057564abeb..c50a301a0c2365c2052aefc6a23fcf6fa82e1b9d 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1556,6 +1556,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.server.spark.tickStart(); // Paper - spark
new com.destroystokyo.paper.event.server.ServerTickStartEvent(this.tickCount+1).callEvent(); // Paper - Server Tick Events
+ if (org.dreeam.leaf.config.modules.misc.LagCompensation.enabled) org.dreeam.leaf.misc.LagCompensation.TPSCalculator.onTick(); // Leaf - TT20 - Lag compensation - tick hook
this.tickCount++;
this.tickRateManager.tick();
this.tickChildren(hasTimeLeft);
diff --git a/net/minecraft/world/level/material/LavaFluid.java b/net/minecraft/world/level/material/LavaFluid.java
index 85629a43f5469a89dd6078d879f475e8212438ec..d66321acb26682a02efa02cf1443b40d2a17f67b 100644
--- a/net/minecraft/world/level/material/LavaFluid.java
+++ b/net/minecraft/world/level/material/LavaFluid.java
@@ -177,7 +177,13 @@ public abstract class LavaFluid extends FlowingFluid {
@Override
public int getTickDelay(LevelReader level) {
- return level.dimensionType().ultraWarm() ? level.getWorldBorder().world.purpurConfig.lavaSpeedNether : level.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur - Make lava flow speed configurable
+ // Leaf start - TT20 - Lag compensation
+ if (org.dreeam.leaf.config.modules.misc.LagCompensation.enabled && org.dreeam.leaf.config.modules.misc.LagCompensation.enableForLava) {
+ return level.dimensionType().ultraWarm() ? org.dreeam.leaf.misc.LagCompensation.tt20(level.getWorldBorder().world.purpurConfig.lavaSpeedNether, true) : org.dreeam.leaf.misc.LagCompensation.tt20(level.getWorldBorder().world.purpurConfig.lavaSpeedNotNether, true); // Purpur - Make lava flow speed configurable // Leaf
+ } else {
+ return level.dimensionType().ultraWarm() ? level.getWorldBorder().world.purpurConfig.lavaSpeedNether : level.getWorldBorder().world.purpurConfig.lavaSpeedNotNether; // Purpur - Make lava flow speed configurable
+ }
+ // Leaf end - TT20 - Lag compensation
}
@Override
diff --git a/net/minecraft/world/level/material/WaterFluid.java b/net/minecraft/world/level/material/WaterFluid.java
index 2e4fed7c27910b6c886f710f33b0841c2a175837..508036525272ffdda054bd631bebd05e82d28409 100644
--- a/net/minecraft/world/level/material/WaterFluid.java
+++ b/net/minecraft/world/level/material/WaterFluid.java
@@ -115,7 +115,13 @@ public abstract class WaterFluid extends FlowingFluid {
@Override
public int getTickDelay(LevelReader level) {
- return 5;
+ // Leaf start - TT20 - Lag compensation
+ if (org.dreeam.leaf.config.modules.misc.LagCompensation.enabled && org.dreeam.leaf.config.modules.misc.LagCompensation.enableForWater) {
+ return org.dreeam.leaf.misc.LagCompensation.tt20(5, true);
+ } else {
+ return 5;
+ }
+ // Leaf end - TT20 - Lag compensation
}
@Override

View File

@@ -1,24 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Thu, 7 Nov 2024 19:45:31 +0100
Subject: [PATCH] C2ME: Reduce Allocations
This patch is based on the following mixin:
"com/ishland/c2me/opts/allocs/mixin/object_pooling_caching/MixinOreFeature.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT (https://opensource.org/licenses/MIT)
diff --git a/net/minecraft/world/level/levelgen/feature/OreFeature.java b/net/minecraft/world/level/levelgen/feature/OreFeature.java
index c7b46efd4f08067e2c9c5c8b0e8b71a94a79823d..d14609e932f2ce4e97d1e354b424cc3ec86bd25b 100644
--- a/net/minecraft/world/level/levelgen/feature/OreFeature.java
+++ b/net/minecraft/world/level/levelgen/feature/OreFeature.java
@@ -69,7 +69,7 @@ public class OreFeature extends Feature<OreConfiguration> {
int height
) {
int i = 0;
- BitSet bitSet = new BitSet(width * height * width);
+ BitSet bitSet = org.dreeam.leaf.util.cache.CachedOrNewBitsGetter.getCachedOrNewBitSet(width * height * width); // Leaf - C2ME - Reduce Allocations
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
int i1 = config.size;
double[] doubles = new double[i1 * 4];

View File

@@ -1,33 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: kidofcubes <kidofcubes@gmail.com>
Date: Fri, 8 Nov 2024 00:22:44 +0800
Subject: [PATCH] Lithium: Skip unnecessary calculations if player is not
flying or swing
This patch is based on the following mixins:
* "net/caffeinemc/mods/lithium/mixin/entity/fast_elytra_check/LivingEntityMixin.java"
* "net/caffeinemc/mods/lithium/mixin/entity/fast_hand_swing/LivingEntityMixin.java"
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/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 316242d60db43494300a29b7d0945d0d76ac9987..0138bd4d95a592bfa5ccbb33fa6c1201f289fd2a 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -2739,6 +2739,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
}
protected void updateSwingTime() {
+ if (!this.swinging && this.swingTime == 0) return; // Leaf - Lithium - entity.fast_hand_swing
int currentSwingDuration = this.getCurrentSwingDuration();
if (this.swinging) {
this.swingTime++;
@@ -3690,6 +3691,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
protected void updateFallFlying() {
this.checkSlowFallDistance();
if (!this.level().isClientSide) {
+ if (!this.isFallFlying() && this.fallFlyTicks == 0) return; // Leaf - Lithium - entity.fast_elytra_check
if (!this.canGlide()) {
if (this.getSharedFlag(7) != false && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit
this.setSharedFlag(7, false);

View File

@@ -1,90 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Thu, 7 Nov 2024 21:50:47 +0100
Subject: [PATCH] Lithium: fast util
This patch is based on the following mixins:
* "net/caffeinemc/mods/lithium/mixin/math/fast_util/DirectionMixin.java"
* "net/caffeinemc/mods/lithium/mixin/math/fast_util/AABBMixin.java"
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/Direction.java b/net/minecraft/core/Direction.java
index 216f97207dac88cc1dc3df59c6ee8a62c7614b4a..3a76b1ec8570e4c9f328e9d362b41057b092be45 100644
--- a/net/minecraft/core/Direction.java
+++ b/net/minecraft/core/Direction.java
@@ -217,7 +217,7 @@ public enum Direction implements StringRepresentable, ca.spottedleaf.moonrise.pa
}
public Direction getOpposite() {
- return this.opposite; // Paper - optimise collisions
+ return VALUES[this.oppositeIndex]; // Leaf - Lithium - fast util
}
public Direction getClockWise(Direction.Axis axis) {
@@ -350,7 +350,7 @@ public enum Direction implements StringRepresentable, ca.spottedleaf.moonrise.pa
}
public static Direction getRandom(RandomSource random) {
- return Util.getRandom(VALUES, random);
+ return VALUES[random.nextInt(VALUES.length)]; // Leaf - Lithium - fast util
}
public static Direction getApproximateNearest(double x, double y, double z) {
diff --git a/net/minecraft/world/phys/AABB.java b/net/minecraft/world/phys/AABB.java
index c9c6e4e460ad8435f12761704bb9b0284d6aa708..f64c04b32dd2d0fe143fc8bf9f498e52beb66a58 100644
--- a/net/minecraft/world/phys/AABB.java
+++ b/net/minecraft/world/phys/AABB.java
@@ -18,6 +18,15 @@ public class AABB {
public final double maxY;
public final double maxZ;
+ // Leaf start - Lithium - fast util
+ static {
+ assert Direction.Axis.X.ordinal() == 0;
+ assert Direction.Axis.Y.ordinal() == 1;
+ assert Direction.Axis.Z.ordinal() == 2;
+ assert Direction.Axis.values().length == 3;
+ }
+ // Leaf end - Lithium - fast util
+
public AABB(double x1, double y1, double z1, double x2, double y2, double z2) {
this.minX = Math.min(x1, x2);
this.minY = Math.min(y1, y2);
@@ -79,11 +88,33 @@ public class AABB {
}
public double min(Direction.Axis axis) {
- return axis.choose(this.minX, this.minY, this.minZ);
+ // Leaf start - Lithium - fast util
+ switch (axis.ordinal()) {
+ case 0: //X
+ return this.minX;
+ case 1: //Y
+ return this.minY;
+ case 2: //Z
+ return this.minZ;
+ }
+
+ throw new IllegalArgumentException();
+ // Leaf end - Lithium - fast util
}
public double max(Direction.Axis axis) {
- return axis.choose(this.maxX, this.maxY, this.maxZ);
+ // Leaf start - Lithium - fast util
+ switch (axis.ordinal()) {
+ case 0: //X
+ return this.maxX;
+ case 1: //Y
+ return this.maxY;
+ case 2: //Z
+ return this.maxZ;
+ }
+
+ throw new IllegalArgumentException();
+ // Leaf end - Lithium - fast util
}
@Override

View File

@@ -1,32 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 8 Nov 2024 00:06:34 +0100
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..596a62f4020e51c2bd5a63c145b7f0e500c4b0ed 100644
--- a/net/minecraft/core/BlockPos.java
+++ b/net/minecraft/core/BlockPos.java
@@ -347,7 +347,18 @@ public class BlockPos extends Vec3i {
};
}
+ // 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 - lithium: cached iterate outwards
+
public static Iterable<BlockPos> withinManhattan(BlockPos pos, int xSize, int ySize, int zSize) {
+ // JettPack start - lithium: cached iterate outwards
+ if (pos != org.dreeam.leaf.util.cache.IterateOutwardsCache.POS_ZERO) {
+ 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 - lithium: cached iterate outwards
int i = xSize + ySize + zSize;
int x1 = pos.getX();
int y1 = pos.getY();

View File

@@ -1,49 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] Smooth teleport config
This abuses some of how Minecraft works and attempts to teleport a player to another world without
triggering typical respawn packets. All of natural state of chunk resends, entity adds/removes, etc still
happen but the visual "refresh" of a world change is hidden. Depending on the destination location/world,
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 2a3c38cd8e31f73eca2508ad94e46ace980de50c..336215befa7eb4b20fc86f224a019080cea70113 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -1475,6 +1475,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
LevelData worlddata = level.getLevelData();
this.connection.send(new ClientboundRespawnPacket(this.createCommonSpawnInfo(level), (byte) 3));
+ if (!org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled || !PlayerList.isSameLogicalHeight(serverLevel, level)) this.connection.send(new ClientboundRespawnPacket(this.createCommonSpawnInfo(level), (byte) 3)); // Leaf - Smooth teleport
this.connection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
PlayerList playerList = this.server.getPlayerList();
@@ -1484,7 +1485,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
// CraftBukkit end
this.portalPos = io.papermc.paper.util.MCUtil.toBlockPosition(exit); // Purpur - Fix stuck in portals
this.setServerLevel(level);
- this.connection.internalTeleport(PositionMoveRotation.of(teleportTransition), teleportTransition.relatives()); // CraftBukkit - use internal teleport without event
+ if (!org.dreeam.leaf.config.modules.gameplay.SmoothTeleport.enabled || !PlayerList.isSameLogicalHeight(serverLevel, level)) this.connection.internalTeleport(PositionMoveRotation.of(teleportTransition), teleportTransition.relatives()); // CraftBukkit - use internal teleport without event // Leaf - Smooth teleport
this.connection.resetPosition();
level.addDuringTeleport(this);
this.triggerDimensionChangeTriggers(serverLevel);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index bda8e9e23f63a6eb27f71fc795ad6495e62f00f2..f59662da0bbfe0e768c4ac5c7491d13263ac5cac 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -955,11 +955,11 @@ public abstract class PlayerList {
byte b = (byte)(keepInventory ? 1 : 0);
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 - 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 - Smooth teleport
serverPlayer.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle()));
serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked()));
serverPlayer.connection

View File

@@ -1,126 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Mon, 11 Nov 2024 02:46:39 -0500
Subject: [PATCH] Use faster and thread-safe ban list date format parsing
Dreeam TODO: check is there need to use more accurate benchmark using jmh?
Use DateTimeFormatter since the original java SimpleDateFormat is not thread-safe
If calls DateTimeFormatter asynchronously, one data format may pollute another
This can fix the server crash on loading according to the user report.
The server crashed during initing the IP ban list, probably caused by calls in off-main.
Some performance test **only for reference**
Single thread, 10,000,000 times loop, java 21 (graalvm / zulu)
SimpleDateFormat: ~29,446ms
DateTimeFormatter: ~13,128ms
apache commons-lang's FastDateFormat: ~23,514ms
In the end, DateTimeFormatter is also fastest in three implementations in any ways,
Wether there is a high frequnently calls or not. And also thread-safe. So there is
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..72f64d5812411be0f0bc5456caff87d63a4cbbb9 100644
--- a/net/minecraft/server/players/BanListEntry.java
+++ b/net/minecraft/server/players/BanListEntry.java
@@ -9,7 +9,11 @@ import javax.annotation.Nullable;
import net.minecraft.network.chat.Component;
public abstract class BanListEntry<T> extends StoredUserEntry<T> {
- 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 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 +34,10 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
Date date;
try {
- date = entryData.has("created") ? DATE_FORMAT.parse(entryData.get("created").getAsString()) : new Date();
- } catch (ParseException var7) {
+ // Leaf start - Use faster and thread-safe ban list date format parsing
+ date = entryData.has("created") ? parseToDate(entryData.get("created").getAsString()) : new Date();
+ } catch (java.time.format.DateTimeParseException var7) {
+ // Leaf end - Use faster and thread-safe ban list date format parsing
date = new Date();
}
@@ -40,8 +46,10 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
Date date1;
try {
- date1 = entryData.has("expires") ? DATE_FORMAT.parse(entryData.get("expires").getAsString()) : null;
- } catch (ParseException var6) {
+ // Leaf start - Use faster and thread-safe ban list date format parsing
+ date1 = entryData.has("expires") ? parseToDate(entryData.get("expires").getAsString()) : null;
+ } catch (java.time.format.DateTimeParseException var6) {
+ // Leaf end - Use faster and thread-safe ban list date format parsing
date1 = null;
}
@@ -75,9 +83,9 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
@Override
protected void serialize(JsonObject data) {
- data.addProperty("created", DATE_FORMAT.format(this.created));
+ data.addProperty("created", formateToString(this.created)); // Leaf - Use faster and thread-safe ban list date format parsing
data.addProperty("source", this.source);
- data.addProperty("expires", this.expires == null ? "forever" : DATE_FORMAT.format(this.expires));
+ data.addProperty("expires", this.expires == null ? "forever" : formateToString(this.expires)); // Leaf - Use faster and thread-safe ban list date format parsing
data.addProperty("reason", this.reason);
}
@@ -86,9 +94,11 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
Date expires = null;
try {
- expires = jsonobject.has("expires") ? BanListEntry.DATE_FORMAT.parse(jsonobject.get("expires").getAsString()) : null;
- } 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 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 +108,15 @@ public abstract class BanListEntry<T> extends StoredUserEntry<T> {
}
}
// CraftBukkit end
+
+ // Leaf start - Use faster and thread-safe ban list date format parsing
+ public static Date parseToDate(String string) {
+ java.time.ZonedDateTime parsedDateTime = java.time.ZonedDateTime.parse(string, DATE_TIME_FORMATTER);
+ return Date.from(parsedDateTime.toInstant());
+ }
+
+ 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/net/minecraft/server/players/OldUsersConverter.java b/net/minecraft/server/players/OldUsersConverter.java
index 7dbcd9d96f052bb10127ad2b061154c23cc9ffd4..0a3b159a8629fad1a240b9be3e6025bfa1183a00 100644
--- a/net/minecraft/server/players/OldUsersConverter.java
+++ b/net/minecraft/server/players/OldUsersConverter.java
@@ -469,8 +469,10 @@ public class OldUsersConverter {
static Date parseDate(String input, Date defaultValue) {
Date date;
try {
- date = BanListEntry.DATE_FORMAT.parse(input);
- } catch (ParseException var4) {
+ // Leaf start - Use faster and thread-safe ban list date format parsing
+ date = BanListEntry.parseToDate(input);
+ } catch (java.time.format.DateTimeParseException var4) {
+ // Leaf end - Use faster and thread-safe ban list date format parsing
date = defaultValue;
}

View File

@@ -1,47 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
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..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<E extends LivingEntity> {
}
private void startEachNonRunningBehavior(ServerLevel level, E entity) {
- long gameTime = level.getGameTime();
+ // Leaf start - Collect then startEachNonRunningBehavior in Brain
+ final long gameTime = level.getGameTime();
+ List<BehaviorControl<? super E>> behaviorsToStart = new ObjectArrayList<>();
- for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
- for (Entry<Activity, Set<BehaviorControl<? super E>>> entry : map.entrySet()) {
- Activity activity = entry.getKey();
- if (this.activeActivities.contains(activity)) {
- for (BehaviorControl<? super E> behaviorControl : entry.getValue()) {
+ for (Activity activeActivity : this.activeActivities) {
+ for (Map<Activity, Set<BehaviorControl<? super E>>> priorityMap : this.availableBehaviorsByPriority.values()) {
+ Set<BehaviorControl<? super E>> behaviors = priorityMap.get(activeActivity);
+
+ if (behaviors != null && !behaviors.isEmpty()) {
+ for (BehaviorControl<? super E> behaviorControl : behaviors) {
if (behaviorControl.getStatus() == Behavior.Status.STOPPED) {
- behaviorControl.tryStart(level, entity, gameTime);
+ behaviorsToStart.add(behaviorControl);
}
}
}
}
}
+ if (!behaviorsToStart.isEmpty()) {
+ for (BehaviorControl<? super E> behaviorControl : behaviorsToStart) {
+ behaviorControl.tryStart(level, entity, gameTime);
+ }
+ }
+ // Leaf end - Collect then startEachNonRunningBehavior in Brain
}
private void tickEachRunningBehavior(ServerLevel level, E entity) {

View File

@@ -1,72 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Tue, 9 Nov 2077 00:00:00 +0800
Subject: [PATCH] C2ME: Optimize world gen math
This patch is based on following mixins:
* "com/ishland/c2me/opts/math/mixin/MixinChunkPos.java"
* "com/ishland/c2me/opts/worldgen/vanilla/mixin/structure_weight_sampler/MixinStructureWeightSampler.java"
By: ishland <ishlandmc@yeah.net>
As part of: C2ME-fabric (https://github.com/RelativityMC/C2ME-fabric)
Licensed under: MIT
Co-authored-by: Taiyou06 <kaandindar21@gmail.com>
diff --git a/net/minecraft/world/level/ChunkPos.java b/net/minecraft/world/level/ChunkPos.java
index 55ce935a2fab7e32904d9ff599867269035d703f..6e2b2d258e47dcca30a5ad9f4f492598f2bc21fb 100644
--- a/net/minecraft/world/level/ChunkPos.java
+++ b/net/minecraft/world/level/ChunkPos.java
@@ -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 - 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 - 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..47b6519f40ed978c05d93023a0cdc1c9e13f033f 100644
--- a/net/minecraft/world/level/levelgen/Beardifier.java
+++ b/net/minecraft/world/level/levelgen/Beardifier.java
@@ -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 - 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 - 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..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 {
Aquifer.FluidStatus fluidStatus = new Aquifer.FluidStatus(-54, Blocks.LAVA.defaultBlockState());
int seaLevel = settings.seaLevel();
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 - C2ME - Optimize world gen math
+ final int min = Math.min(-54, seaLevel);
+ return (x, y, z) -> y < min ? fluidStatus : fluidStatus1;
+ // Leaf end - C2ME - Optimize world gen math
}
@Override

View File

@@ -1,143 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sat, 2 Nov 2024 04:15:20 -0400
Subject: [PATCH] Cache chunk key
Cache convert process between ChunkPos < - > chunkKey
This patch didn't cahce SectionPos or BlockPos to chunkKey, since it needs to consider the mutable blockpos siutation.
TODO: Cache block pos and section pos, whether need?
diff --git a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
index 1b8193587814225c2ef2c5d9e667436eb50ff6c5..288a3eb57f3431dd624ad8a4b08684563abbc5ad 100644
--- a/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
+++ b/ca/spottedleaf/moonrise/common/misc/NearbyPlayers.java
@@ -127,7 +127,7 @@ public final class NearbyPlayers {
}
public TrackedChunk getChunk(final ChunkPos pos) {
- return this.byChunk.get(CoordinateUtils.getChunkKey(pos));
+ return this.byChunk.get(pos.longKey); // Leaf - Cache chunk key
}
public TrackedChunk getChunk(final BlockPos pos) {
@@ -143,7 +143,7 @@ public final class NearbyPlayers {
}
public ReferenceList<ServerPlayer> getPlayers(final ChunkPos pos, final NearbyMapType type) {
- return this.directByChunk[type.ordinal()].get(CoordinateUtils.getChunkKey(pos));
+ return this.directByChunk[type.ordinal()].get(pos.longKey); // Leaf - Cache chunk key
}
public ReferenceList<ServerPlayer> getPlayersByChunk(final int chunkX, final int chunkZ, final NearbyMapType type) {
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
index b5817aa8f537593f6d9fc6b612c82ccccb250ac7..be820c6093dd2ae7642b9bee11edf65e3a8d7242 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
@@ -506,7 +506,7 @@ public final class ChunkHolderManager {
public <T> boolean addTicketAtLevel(final TicketType<T> type, final ChunkPos chunkPos, final int level,
final T identifier) {
- return this.addTicketAtLevel(type, CoordinateUtils.getChunkKey(chunkPos), level, identifier);
+ return this.addTicketAtLevel(type, chunkPos.longKey, level, identifier); // Leaf - Cache chunk key
}
public <T> boolean addTicketAtLevel(final TicketType<T> type, final int chunkX, final int chunkZ, final int level,
@@ -604,7 +604,7 @@ public final class ChunkHolderManager {
}
public <T> boolean removeTicketAtLevel(final TicketType<T> type, final ChunkPos chunkPos, final int level, final T identifier) {
- return this.removeTicketAtLevel(type, CoordinateUtils.getChunkKey(chunkPos), level, identifier);
+ return this.removeTicketAtLevel(type, chunkPos.longKey, level, identifier); // Leaf - Cache chunk key
}
public <T> boolean removeTicketAtLevel(final TicketType<T> type, final int chunkX, final int chunkZ, final int level, final T identifier) {
@@ -1224,7 +1224,7 @@ public final class ChunkHolderManager {
}
public static <T> TicketOperation<T, T> addOp(final ChunkPos chunk, final TicketType<T> type, final int ticketLevel, final T identifier) {
- return addOp(CoordinateUtils.getChunkKey(chunk), type, ticketLevel, identifier);
+ return addOp(chunk.longKey, type, ticketLevel, identifier); // Leaf - Cache chunk key
}
public static <T> TicketOperation<T, T> addOp(final int chunkX, final int chunkZ, final TicketType<T> type, final int ticketLevel, final T identifier) {
@@ -1236,7 +1236,7 @@ public final class ChunkHolderManager {
}
public static <T> TicketOperation<T, T> removeOp(final ChunkPos chunk, final TicketType<T> type, final int ticketLevel, final T identifier) {
- return removeOp(CoordinateUtils.getChunkKey(chunk), type, ticketLevel, identifier);
+ return removeOp(chunk.longKey, type, ticketLevel, identifier); // Leaf - Cache chunk key
}
public static <T> TicketOperation<T, T> removeOp(final int chunkX, final int chunkZ, final TicketType<T> type, final int ticketLevel, final T identifier) {
diff --git a/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java b/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java
index 571db5f9bf94745a8afe2cd313e593fb15db5e37..1487b7d8be435b3fbad2aabd05796965b4775a87 100644
--- a/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java
+++ b/ca/spottedleaf/moonrise/patches/starlight/light/StarLightInterface.java
@@ -818,7 +818,7 @@ public final class StarLightInterface {
}
public ServerChunkTasks queueChunkLightTask(final ChunkPos pos, final BooleanSupplier lightTask, final Priority priority) {
- final ServerChunkTasks ret = this.chunkTasks.compute(CoordinateUtils.getChunkKey(pos), (final long keyInMap, ServerChunkTasks valueInMap) -> {
+ final ServerChunkTasks ret = this.chunkTasks.compute(pos.longKey, (final long keyInMap, ServerChunkTasks valueInMap) -> { // Leaf - Cache chunk key
if (valueInMap == null) {
valueInMap = new ServerChunkTasks(
keyInMap, ServerLightQueue.this.lightInterface, ServerLightQueue.this, priority
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 5423d8228c1da56135ae32b958f432d5b94707ed..95bed1e67758543a7aec12eee1229ee2c4057c88 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -508,7 +508,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@Override
public final void moonrise$markChunkForPlayerTicking(final LevelChunk chunk) {
final ChunkPos pos = chunk.getPos();
- if (!this.playerTickingRequests.containsKey(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(pos))) {
+ if (!this.playerTickingRequests.containsKey(pos.longKey)) { // Leaf - Cache chunk key
return;
}
@@ -2569,7 +2569,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
public boolean isNaturalSpawningAllowed(ChunkPos chunkPos) {
// Paper start - rewrite chunk system
- final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(chunkPos));
+ final ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkHolder = this.moonrise$getChunkTaskScheduler().chunkHolderManager.getChunkHolder(chunkPos.longKey); // Leaf - Cache chunk key
return chunkHolder != null && chunkHolder.isEntityTickingReady();
// Paper end - rewrite chunk system
}
diff --git a/net/minecraft/world/level/ChunkPos.java b/net/minecraft/world/level/ChunkPos.java
index 6e2b2d258e47dcca30a5ad9f4f492598f2bc21fb..f9af074e833a6dab96414750314a27b35ec07bfc 100644
--- a/net/minecraft/world/level/ChunkPos.java
+++ b/net/minecraft/world/level/ChunkPos.java
@@ -54,19 +54,19 @@ public class ChunkPos {
public ChunkPos(int x, int y) {
this.x = x;
this.z = y;
- this.longKey = asLong(this.x, this.z); // Paper
+ this.longKey = asLong(this.x, this.z); // Paper // Leaf - Cache chunk key - diff on change
}
public ChunkPos(BlockPos pos) {
this.x = SectionPos.blockToSectionCoord(pos.getX());
this.z = SectionPos.blockToSectionCoord(pos.getZ());
- this.longKey = asLong(this.x, this.z); // Paper
+ this.longKey = asLong(this.x, this.z); // Paper // Leaf - Cache chunk key - diff on change
}
public ChunkPos(long packedPos) {
this.x = (int)packedPos;
this.z = (int)(packedPos >> 32);
- this.longKey = asLong(this.x, this.z); // Paper
+ this.longKey = asLong(this.x, this.z); // Paper // Leaf - Cache chunk key - diff on change
}
public static ChunkPos minFromRegion(int chunkX, int chunkZ) {
@@ -82,7 +82,7 @@ public class ChunkPos {
}
public static long asLong(int x, int z) {
- return x & 4294967295L | (z & 4294967295L) << 32;
+ return x & 4294967295L | (z & 4294967295L) << 32; // Leaf - Cache chunk key - diff on change
}
public static long asLong(BlockPos pos) {

View File

@@ -1,59 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Sat, 23 Nov 2024 09:04:46 -0500
Subject: [PATCH] Cache random tick block status
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
index 412e7b1cf8c24f0ddf6d174967bedad576f10aba..b8ac6a9ba7b56ccd034757f7d135d272b8e69e90 100644
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -21,6 +21,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
short nonEmptyBlockCount; // Paper - package private
private short tickingBlockCount;
private short tickingFluidCount;
+ private boolean isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status
public final PalettedContainer<BlockState> states;
private PalettedContainer<Holder<Biome>> biomes; // CraftBukkit - read/write
@@ -54,6 +55,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
this.tickingFluidCount = section.tickingFluidCount;
this.states = section.states.copy();
this.biomes = section.biomes.copy();
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
}
public LevelChunkSection(PalettedContainer<BlockState> states, PalettedContainer<Holder<Biome>> biomes) { // CraftBukkit - read/write
@@ -165,6 +167,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
}
this.updateBlockCallback(x, y, z, state, blockState); // Paper - block counting
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
return blockState;
}
@@ -178,7 +181,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
}
public boolean isRandomlyTickingBlocks() {
- return this.tickingBlockCount > 0;
+ return isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status
}
public boolean isRandomlyTickingFluids() {
@@ -193,6 +196,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
this.tickingFluidCount = (short)0;
this.specialCollidingBlocks = (short)0;
this.tickingBlocks.clear();
+ this.isRandomlyTickingBlocksStatus = false; // Leaf - Cache random tick block status
if (this.maybeHas((final BlockState state) -> !state.isAir())) {
final PalettedContainer.Data<BlockState> data = this.states.data;
@@ -226,6 +230,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
this.nonEmptyBlockCount += (short)paletteCount;
if (state.isRandomlyTicking()) {
this.tickingBlockCount += (short)paletteCount;
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
final short[] raw = coordinates.elements();
final int rawLen = raw.length;

View File

@@ -1,65 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Tue, 26 Nov 2024 17:15:38 -0500
Subject: [PATCH] Cache part of canHoldFluid result
Cache the result of part of canHoldFluid logic, since there are many state#is in canAnyHoldFluid method,
it uses map contains to do iteration to check whether a block has a specific block tag key,
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 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 {
private VoxelShape[] occlusionShapesByFace;
private boolean propagatesSkylightDown;
private int lightBlock;
+ private boolean canHoldAnyFluidInternal; // Leaf - Cache part of canHoldFluid result
+ private boolean canHoldAnyFluidInternalInit; // Leaf - Cache part of canHoldFluid result
// Paper start - rewrite chunk system
private boolean isConditionallyFullOpaque;
@@ -603,6 +605,8 @@ public abstract class BlockBehaviour implements FeatureElement {
this.propagatesSkylightDown = this.owner.propagatesSkylightDown(this.asState());
this.lightBlock = this.owner.getLightBlock(this.asState());
+ this.canHoldAnyFluidInternal = false; // Leaf - Cache part of canHoldFluid result
+ this.canHoldAnyFluidInternalInit = false; // Leaf - Cache part of canHoldFluid result
// Paper start - rewrite chunk system
this.isConditionallyFullOpaque = this.canOcclude & this.useShapeForLightOcclusion;
// Paper end - rewrite chunk system
@@ -654,6 +658,18 @@ public abstract class BlockBehaviour implements FeatureElement {
return block != Blocks.COBWEB && block != Blocks.BAMBOO_SAPLING && this.isSolid();
}
+ // Leaf start - Cache part of canHoldFluid result
+ public boolean canHoldAnyFluidInternal() {
+ // Lazy load cache
+ if (!canHoldAnyFluidInternalInit) {
+ canHoldAnyFluidInternal = net.minecraft.world.level.material.FlowingFluid.canHoldAnyFluid(this.asState());
+ canHoldAnyFluidInternalInit = true;
+ }
+
+ return canHoldAnyFluidInternal;
+ }
+ // Leaf end - Cache part of canHoldFluid result
+
@Deprecated
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 738defb8cbd9c63dc85c479911ebe2f795d0a815..4c2c2efd5380ff1fa5ad7553b51babae20f516ae 100644
--- a/net/minecraft/world/level/material/FlowingFluid.java
+++ b/net/minecraft/world/level/material/FlowingFluid.java
@@ -466,7 +466,7 @@ public abstract class FlowingFluid extends Fluid {
}
private static boolean canHoldFluid(BlockGetter level, BlockPos pos, BlockState state, Fluid fluid) {
- return canHoldAnyFluid(state) && canHoldSpecificFluid(level, pos, state, fluid);
+ return /*canHoldAnyFluid(state)*/ state.canHoldAnyFluidInternal() && canHoldSpecificFluid(level, pos, state, fluid); // Leaf - Cache part of canHoldFluid result
}
private static boolean canHoldSpecificFluid(BlockGetter level, BlockPos pos, BlockState state, Fluid fluid) {

View File

@@ -1,23 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Tue, 24 Dec 2024 13:28:56 -0500
Subject: [PATCH] Configurable tripwire dupe
Bring back MC-59471, MC-129055 on 1.21.2+, which fixed in 1.21.2 snapshots 24w33a and 24w36a
Note: this is different from Paper's skip-tripwire-hook-placement-validation, that setting
handles tripwire hook dupe
diff --git a/net/minecraft/world/level/block/TripWireHookBlock.java b/net/minecraft/world/level/block/TripWireHookBlock.java
index 9aace993c6c18f1a50610e4766225485984b8167..d62855ce6df9a52cdd8005a43a70353365a92230 100644
--- a/net/minecraft/world/level/block/TripWireHookBlock.java
+++ b/net/minecraft/world/level/block/TripWireHookBlock.java
@@ -215,7 +215,7 @@ public class TripWireHookBlock extends Block {
BlockState blockState2 = blockStates[i2];
if (blockState2 != null) {
BlockState blockState3 = level.getBlockState(blockPos1);
- if (blockState3.is(Blocks.TRIPWIRE) || blockState3.is(Blocks.TRIPWIRE_HOOK)) {
+ if (org.dreeam.leaf.config.modules.gameplay.ConfigurableTripWireDupe.enabled || blockState3.is(Blocks.TRIPWIRE) || blockState3.is(Blocks.TRIPWIRE_HOOK)) { // Leaf - Configurable tripwire dupe
if (!io.papermc.paper.configuration.GlobalConfiguration.get().blockUpdates.disableTripwireUpdates || !blockState3.is(Blocks.TRIPWIRE)) level.setBlock(blockPos1, blockState2.trySetValue(ATTACHED, Boolean.valueOf(flag2)), 3); // Paper - prevent tripwire from updating
}
}

View File

@@ -1,51 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrPowerGamerBR <git@mrpowergamerbr.com>
Date: Sun, 26 Nov 2023 13:02:16 -0300
Subject: [PATCH] PaperPR: Fix MC-117075: Block Entities Unload Lag Spike
Original license: GPLv3
Original project: https://github.com/SparklyPower/SparklyPaper
Paper pull request: https://github.com/PaperMC/Paper/pull/9970
We replaced the `blockEntityTickers` list with a custom list based on fastutil's `ObjectArrayList` with a small yet huge change for us: A method that allows us to remove a list of indexes from the list.
This is WAY FASTER than using `removeAll` with a list of entries to be removed, because we don't need to calculate the identity of each block entity to be removed, and we can jump directly to where the search should begin, giving a performance boost for small removals (because we don't need to loop thru the entire list to find what element should be removed) and a performance boost for big removals (no need to calculate the identity of each block entity).
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
index 53cabe7dabc83618c8941c95e95c5b7e23ee694e..7d3163802640449b6bdaa93595518d7d0f62488b 100644
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -113,7 +113,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
public static final int TICKS_PER_DAY = 24000;
public static final int MAX_ENTITY_SPAWN_Y = 20000000;
public static final int MIN_ENTITY_SPAWN_Y = -20000000;
- public final List<TickingBlockEntity> blockEntityTickers = Lists.newArrayList(); // Paper - public
+ public final org.dreeam.leaf.util.list.BlockEntityTickersList blockEntityTickers = new org.dreeam.leaf.util.list.BlockEntityTickersList(); // Paper - public // SparklyPaper - optimize block entity removals
protected final NeighborUpdater neighborUpdater;
private final List<TickingBlockEntity> pendingBlockEntityTickers = Lists.newArrayList();
private boolean tickingBlockEntities;
@@ -1523,14 +1523,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
boolean runsNormally = this.tickRateManager().runsNormally();
int tickedEntities = 0; // Paper - rewrite chunk system
- var toRemove = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<TickingBlockEntity>(); // Paper - Fix MC-117075; use removeAll
- toRemove.add(null); // Paper - Fix MC-117075
for (tileTickPosition = 0; tileTickPosition < this.blockEntityTickers.size(); tileTickPosition++) { // Paper - Disable tick limiters
this.tileTickPosition = (this.tileTickPosition < this.blockEntityTickers.size()) ? this.tileTickPosition : 0;
TickingBlockEntity tickingBlockEntity = this.blockEntityTickers.get(this.tileTickPosition);
// Spigot end
if (tickingBlockEntity.isRemoved()) {
- toRemove.add(tickingBlockEntity); // Paper - Fix MC-117075; use removeAll
+ this.blockEntityTickers.markAsRemoved(this.tileTickPosition); // toRemove.add(tickingBlockEntity); // SparklyPaper - optimize block entity removals // Paper - Fix MC-117075; use removeAll
} else if (runsNormally && this.shouldTickBlocksAt(tickingBlockEntity.getPos())) {
tickingBlockEntity.tick();
// Paper start - rewrite chunk system
@@ -1540,7 +1538,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// Paper end - rewrite chunk system
}
}
- this.blockEntityTickers.removeAll(toRemove); // Paper - Fix MC-117075
+ this.blockEntityTickers.removeMarkedEntries(); // SparklyPaper - optimize block entity removals
this.tickingBlockEntities = false;
this.spigotConfig.currentPrimedTnt = 0; // Spigot

View File

@@ -1,71 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: cao-awa <cao.awa.www@gmail.com>
Date: Fri, 23 Aug 2024 00:23:32 +0800
Subject: [PATCH] Sepals: Rearrange the attackable conditions
Original license: GPLv3
Original project: https://github.com/cao-awa/Sepals
Rearrange the attackable conditions
let less costs predicate running first
reduce the probability of high-costs calculating
-- The complaints --
Mojang's attackable predicate is:
!entity.getBrain().hasMemoryModule(MemoryModuleType.HAS_HUNTING_COOLDOWN)
&& Sensor.testAttackableTargetPredicate(entity, target)
&& FrogEntity.isValidFrogFood(target)
&& !this.isTargetUnreachable(entity, target)
&& target.isInRange(entity, 10.0)
in this case, 'Sensor#testAttackableTargetPredicate' has calls 'TargetPredicate#test'
that cause a very lots raycast calculate when entities too much in the area
but... minecraft's raycast is absolutely bad, very slow
the 'TargetPredicate#test' in this case (800 frogs) has make 9.8ms costs in once game tick
among them, 'BlockView.raycast' contributed 7.3ms
then i make it be:
FrogEntity.isValidFrogFood(target) &&
entity.getBrain().hasMemoryModule(MemoryModuleType.HAS_HUNTING_COOLDOWN) &&
target.isInRange(entity, 10.0) &&
Sensor.testAttackableTargetPredicate(entity, target) &&
isTargetUnreachable(entity, target);
the 'isValidFrogFood' is simple conditions, check the entity's tag has in 'frog_food'
and a extra check when entity is slime then skip it when it size not 1
the 'isInRange' and 'hasMemoryModule' also simple, it only a few math calculates
Test Result:
800 frogs cramming in a 7x7 space:
| Environment | time | Percent(Avg.) |
|-------------------------------------------------:|:------:|:-------------:|
| Vanilla (FrogAttackablesSensor#matches) | 10 ms | 100 % |
| With Lithium (FrogAttackablesSensor#matches) | 5.7 ms | 57 % |
| With Sepals (SepalsFrogBrain#attackable) | 0.1 ms | 1 % |
| With Sepals+Lithium (SepalsFrogBrain#attackable) | 0.1 ms | 1 % |
diff --git a/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java b/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java
index d163a363273b52b3b3f0b5a74ac4d4ab37d24bb7..e88479ba1ebeff67a93baad4f6f8c83119ff5ff7 100644
--- a/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java
+++ b/net/minecraft/world/entity/ai/sensing/FrogAttackablesSensor.java
@@ -13,11 +13,11 @@ public class FrogAttackablesSensor extends NearestVisibleLivingEntitySensor {
@Override
protected boolean isMatchingEntity(ServerLevel level, LivingEntity entity, LivingEntity target) {
- return !entity.getBrain().hasMemoryValue(MemoryModuleType.HAS_HUNTING_COOLDOWN)
+ return Frog.canEat(target)
+ && !entity.getBrain().hasMemoryValue(MemoryModuleType.HAS_HUNTING_COOLDOWN)
+ && target.closerThan(entity, 10.0)
&& Sensor.isEntityAttackable(level, entity, target)
- && Frog.canEat(target)
- && !this.isUnreachableAttackTarget(entity, target)
- && target.closerThan(entity, 10.0);
+ && !this.isUnreachableAttackTarget(entity, target); // Sepals - Rearrange the attackable conditions
}
private boolean isUnreachableAttackTarget(LivingEntity attacker, LivingEntity target) {

View File

@@ -1,41 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrPowerGamerBR <git@mrpowergamerbr.com>
Date: Mon, 13 Jan 2025 14:32:08 -0300
Subject: [PATCH] SparklyPaper: Skip dirty stats copy when requesting player
stats
diff --git a/net/minecraft/stats/ServerStatsCounter.java b/net/minecraft/stats/ServerStatsCounter.java
index b26dbe807e5cb0a42f6c06b933397902310e5616..ce89060bd01b253af7577fd0e6c03fc95f046b91 100644
--- a/net/minecraft/stats/ServerStatsCounter.java
+++ b/net/minecraft/stats/ServerStatsCounter.java
@@ -81,11 +81,15 @@ public class ServerStatsCounter extends StatsCounter {
this.dirty.add(stat);
}
+ // SparklyPaper start - Skip dirty stats copy when requesting player stats
+ /*
private Set<Stat<?>> getDirty() {
Set<Stat<?>> set = Sets.newHashSet(this.dirty);
this.dirty.clear();
return set;
}
+ */
+ // SparklyPaper end
public void parseLocal(DataFixer fixerUpper, String json) {
try {
@@ -194,10 +198,12 @@ public class ServerStatsCounter extends StatsCounter {
public void sendStats(ServerPlayer player) {
Object2IntMap<Stat<?>> map = new Object2IntOpenHashMap<>();
- for (Stat<?> stat : this.getDirty()) {
+ for (Stat<?> stat : this.dirty) { // SparklyPaper - Skip dirty stats copy when requesting player stats
map.put(stat, this.getValue(stat));
}
+ this.dirty.clear(); // SparklyPaper - Skip dirty stats copy when requesting player stats
+
player.connection.send(new ClientboundAwardStatsPacket(map));
}
}

View File

@@ -1,67 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 8 Feb 2025 05:32:30 +0100
Subject: [PATCH] Optimize checking nearby players for spawning
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
index 8986c059e7aadb58ae8d9ab7b848de10f9faa6b2..546b20f8998c71ca1a701de7efcedd8d821105e4 100644
--- a/net/minecraft/server/level/ChunkMap.java
+++ b/net/minecraft/server/level/ChunkMap.java
@@ -719,7 +719,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
}
private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkPos chunkPos, boolean reducedRange) {
- double blockRange; // Paper - use from event
+ //double blockRange; // Paper - use from event // Leaf - Optimize checking nearby players for spawning - move down
// Spigot end
// Paper start - chunk tick iteration optimisation
final ca.spottedleaf.moonrise.common.list.ReferenceList<ServerPlayer> players = ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel)this.level).moonrise$getNearbyPlayers().getPlayers(
@@ -731,23 +731,39 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
final ServerPlayer[] raw = players.getRawDataUnchecked();
final int len = players.size();
+ // Leaf start - Optimize checking nearby players for spawning
+ // Precompute chunk center once
+ // inline, copy from SectionPos#sectionToBlockCoord
+ final double centerX = (chunkPos.x << 4) + 8;
+ final double centerZ = (chunkPos.z << 4) + 8;
- Objects.checkFromIndexSize(0, len, raw.length);
for (int i = 0; i < len; ++i) {
final ServerPlayer serverPlayer = raw[i];
- // Paper start - PlayerNaturallySpawnCreaturesEvent
- com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
- blockRange = 16384.0D;
+
+ if (serverPlayer.isSpectator()) continue; // Skip spectators early
+
+ final double blockRangeSquared;
+
if (reducedRange) {
- event = serverPlayer.playerNaturallySpawnedEvent;
+ // Handle reduced range from PlayerNaturallySpawnCreaturesEvent
+ // Paper start - PlayerNaturallySpawnCreaturesEvent
+ final com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event = serverPlayer.playerNaturallySpawnedEvent;
if (event == null || event.isCancelled()) continue;
- blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
+ final int spawnRadius = event.getSpawnRadius();
+ blockRangeSquared = (double) (spawnRadius * spawnRadius) * 256.0; // (radius << 4)^2
+ // Paper end - PlayerNaturallySpawnCreaturesEvent
+ } else {
+ blockRangeSquared = 16384.0D; // Default 128^2
}
- // Paper end - PlayerNaturallySpawnCreaturesEvent
- if (this.playerIsCloseEnoughForSpawning(serverPlayer, chunkPos, blockRange)) {
+
+ // Calculate squared distance using precomputed center
+ final double dx = serverPlayer.getX() - centerX;
+ final double dz = serverPlayer.getZ() - centerZ;
+ if (dx * dx + dz * dz < blockRangeSquared) {
return true;
}
}
+ // Leaf end - Optimize checking nearby players for spawning
return false;
// Paper end - chunk tick iteration optimisation

View File

@@ -1,63 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 8 Feb 2025 05:32:30 +0100
Subject: [PATCH] Cache supporting block check
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 4544dd876d3cbcdb9b774b4a1f0c4737f3124bc5..6ca446fd9ab38329ba505526a56f8e4f64a9a639 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -1083,12 +1083,36 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return this.mainSupportingBlockPos.isPresent() && this.mainSupportingBlockPos.get().equals(pos);
}
+ // Leaf start - Cache supporting block check
+ private boolean canSkipSupportingBlockSearch = false;
+ private BlockState cachedSupportingBlockState = null;
+ // Leaf end - Cache supporting block check
+
protected void checkSupportingBlock(boolean onGround, @Nullable Vec3 movement) {
+ // Leaf start - Cache supporting block check
+ // Skip full check if no movement and cache is valid
+ if (movement == null || (movement.x == 0 && movement.z == 0 && movement.y == 0)) {
+ if (canSkipSupportingBlockSearch) {
+ return;
+ }
+ } else {
+ // Invalidate cache on movement
+ canSkipSupportingBlockSearch = false;
+ cachedSupportingBlockState = null;
+ }
+ // Leaf end - Cache supporting block check
if (onGround) {
AABB boundingBox = this.getBoundingBox();
AABB aabb = new AABB(boundingBox.minX, boundingBox.minY - 1.0E-6, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
Optional<BlockPos> optional = this.level.findSupportingBlock(this, aabb);
if (optional.isPresent() || this.onGroundNoBlocks) {
+ // Leaf start - Cache supporting block check
+ if (optional.isPresent()) { // Cache the block state if found
+ BlockPos pos = optional.get();
+ cachedSupportingBlockState = this.level.getBlockState(pos);
+ canSkipSupportingBlockSearch = true;
+ }
+ // Leaf end - Cache supporting block check
this.mainSupportingBlockPos = optional;
} else if (movement != null) {
AABB aabb1 = aabb.move(-movement.x, 0.0, -movement.z);
@@ -1105,6 +1129,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
}
+
+ // Leaf start - Cache supporting block check
+ // Helper method to get cached supporting block state
+ @Nullable
+ public BlockState getCachedSupportingBlock() {
+ return canSkipSupportingBlockSearch ? cachedSupportingBlockState : null;
+ }
+ // Leaf end - Cache supporting block check
+
public boolean onGround() {
return this.onGround;
}

View File

@@ -1,19 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MachineBreaker <saltspigotpp@gmail.com>
Date: Wed, 16 Oct 2024 03:39:24 -0400
Subject: [PATCH] Avoid useless deque clear on LevelTicks#cleanupAfterTick
diff --git a/net/minecraft/world/ticks/LevelTicks.java b/net/minecraft/world/ticks/LevelTicks.java
index fbf0d3b808c66e8971c747619f6acf7417af5ef7..d4542a86a2a9bfcfa7b6b7a213f233542ffed797 100644
--- a/net/minecraft/world/ticks/LevelTicks.java
+++ b/net/minecraft/world/ticks/LevelTicks.java
@@ -182,7 +182,7 @@ public class LevelTicks<T> implements LevelTickAccess<T> {
}
private void cleanupAfterTick() {
- this.toRunThisTick.clear();
+ //this.toRunThisTick.clear(); // Leaf - Avoid useless deque clear on LevelTicks#cleanupAfterTick - This method runs after toRunThisTick is polled so this is always empty
this.containersToTick.clear();
this.alreadyRunThisTick.clear();
this.toRunThisTickSet.clear();

View File

@@ -1,21 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 8 Feb 2025 20:45:14 +0100
Subject: [PATCH] Replace brain activity maps with optimized collection
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index ea6c8e85ccff67b1c24109732f74f1e8199cad07..e27284f9897923f67985e3d60c3438bd00cc4a51 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -390,8 +390,8 @@ public class Brain<E extends LivingEntity> {
for (Pair<Integer, ? extends BehaviorControl<? super E>> pair : tasks) {
this.availableBehaviorsByPriority
- .computeIfAbsent(pair.getFirst(), integer -> Maps.newHashMap())
- .computeIfAbsent(activity, activity1 -> Sets.newLinkedHashSet())
+ .computeIfAbsent(pair.getFirst(), integer -> new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>()) // Leaf - Replace brain activity maps with optimized collection
+ .computeIfAbsent(activity, activity1 -> new it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet<>()) // Leaf - Replace brain activity maps with optimized collection
.add((BehaviorControl<? super E>)pair.getSecond());
}
}

View File

@@ -1,65 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 8 Feb 2025 22:11:16 +0100
Subject: [PATCH] Remove stream in villagers
TradeWithVillager#figureOutWhatIAmWillingToTrade
In the test, this can give ~40% improvement (~20ms -> ~12ms),
under 2048 villagers situation.
And ~100% improvement (~36ms -> ~0ms), under 512 villagers situation.
Villager#countFoodPointsInInventory
In the test, this can give ~82.14% improvement (~1456ms -> ~260ms),
under 2048 villagers situation.
And ~93.92% improvement (~1382ms -> ~84ms), under 512 villagers situation.
diff --git a/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java b/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java
index 4d8523a43d60cd6b4fd5546ffb3a61417b2c475b..8921faa7b893aae9e91a6f8e36dcd751308f9bab 100644
--- a/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java
+++ b/net/minecraft/world/entity/ai/behavior/TradeWithVillager.java
@@ -77,9 +77,19 @@ public class TradeWithVillager extends Behavior<Villager> {
}
private static Set<Item> figureOutWhatIAmWillingToTrade(Villager villager, Villager other) {
- ImmutableSet<Item> set = other.getVillagerData().getProfession().requestedItems();
- ImmutableSet<Item> set1 = villager.getVillagerData().getProfession().requestedItems();
- return set.stream().filter(item -> !set1.contains(item)).collect(Collectors.toSet());
+ // Leaf start - Remove stream in villagers
+ ImmutableSet<Item> otherItems = other.getVillagerData().getProfession().requestedItems();
+ ImmutableSet<Item> villagerItems = villager.getVillagerData().getProfession().requestedItems();
+ Set<Item> result = new java.util.HashSet<>();
+
+ for (Item item : otherItems) {
+ if (!villagerItems.contains(item)) {
+ result.add(item);
+ }
+ }
+
+ return result;
+ // Leaf end - Remove stream in villagers
}
private static void throwHalfStack(Villager villager, Set<Item> stack, LivingEntity entity) {
diff --git a/net/minecraft/world/entity/npc/Villager.java b/net/minecraft/world/entity/npc/Villager.java
index bee017f2c47a9f0876e2e05ce1c720332fb74566..0b4c4707139c9c72929799818ec1a1b25575d70e 100644
--- a/net/minecraft/world/entity/npc/Villager.java
+++ b/net/minecraft/world/entity/npc/Villager.java
@@ -985,7 +985,17 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
private int countFoodPointsInInventory() {
SimpleContainer inventory = this.getInventory();
- return FOOD_POINTS.entrySet().stream().mapToInt(entry -> inventory.countItem(entry.getKey()) * entry.getValue()).sum();
+ // Leaf start - Remove stream in villagers
+ int sum = 0;
+
+ for (Map.Entry<Item, Integer> entry : FOOD_POINTS.entrySet()) {
+ Item item = entry.getKey();
+ int points = entry.getValue();
+ sum += inventory.countItem(item) * points;
+ }
+
+ return sum;
+ // Leaf end - Remove stream in villagers
}
public boolean hasFarmSeeds() {

View File

@@ -1,54 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sat, 8 Feb 2025 22:36:31 +0100
Subject: [PATCH] Optimize baby villager sensor
In the test, this can give ~16.58% improvement (~2316ms -> ~1932ms),
under 2048 villagers situation.
And ~42.93% improvement (~764ms -> ~436ms), under 512 villagers situation.
diff --git a/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java b/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java
index 1c010e5b75506945e5281021a2ddad424044d28f..2b973a3ba7d65330fa4690e71e5321c28457ec61 100644
--- a/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java
+++ b/net/minecraft/world/entity/ai/memory/NearestVisibleLivingEntities.java
@@ -42,7 +42,7 @@ public class NearestVisibleLivingEntities {
}
public Iterable<LivingEntity> findAll(Predicate<LivingEntity> predicate) {
- return Iterables.filter(this.nearbyEntities, target -> predicate.test(target) && this.lineOfSightTest.test(target));
+ return Iterables.filter(this.nearbyEntities, target -> predicate.test(target) && this.lineOfSightTest.test(target)); // Leaf - Optimize baby villager sensor - diff on change
}
public Stream<LivingEntity> find(Predicate<LivingEntity> predicate) {
diff --git a/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java b/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java
index 24d1928445b5571e040a2b12d5c82e77a880d9bd..4b2964aeb4e21fe41f42c2902db63ce28322063a 100644
--- a/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java
+++ b/net/minecraft/world/entity/ai/sensing/VillagerBabiesSensor.java
@@ -22,11 +22,25 @@ public class VillagerBabiesSensor extends Sensor<LivingEntity> {
}
private List<LivingEntity> getNearestVillagerBabies(LivingEntity livingEntity) {
- return ImmutableList.copyOf(this.getVisibleEntities(livingEntity).findAll(this::isVillagerBaby));
+ // Leaf start - Optimize baby villager sensor
+ NearestVisibleLivingEntities visibleEntities = this.getVisibleEntities(livingEntity);
+ ImmutableList.Builder<LivingEntity> babies = ImmutableList.builder();
+
+ // Inline and use single loop - copy from NearestVisibleLivingEntities#findAll and isVillagerBaby
+ for (LivingEntity target : visibleEntities.nearbyEntities) {
+ if (target.getType() == EntityType.VILLAGER
+ && target.isBaby()
+ && visibleEntities.lineOfSightTest.test(target)) {
+ babies.add(target);
+ }
+ }
+
+ return babies.build();
+ // Leaf end - Optimize baby villager sensor
}
private boolean isVillagerBaby(LivingEntity livingEntity) {
- return livingEntity.getType() == EntityType.VILLAGER && livingEntity.isBaby();
+ return livingEntity.getType() == EntityType.VILLAGER && livingEntity.isBaby(); // Leaf - Optimize baby villager sensor - diff on change
}
private NearestVisibleLivingEntities getVisibleEntities(LivingEntity livingEntity) {

View File

@@ -1,94 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Wed, 27 Nov 2024 23:13:12 -0500
Subject: [PATCH] Only player pushable
Useful for extreme cases like massive entities collide together in a small area
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index 00233a7066d751821566b43993e8c45e7dad95d0..03c9edad5c2f5e902b7a766c6d0be61bf3c263ae 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -3631,7 +3631,7 @@ public abstract class LivingEntity extends Entity implements Attackable, net.caf
this.checkAutoSpinAttack(boundingBox, this.getBoundingBox());
}
- this.pushEntities();
+ if (!org.dreeam.leaf.config.modules.gameplay.OnlyPlayerPushable.enabled) this.pushEntities(); // Leaf - Only player pushable
// Paper start - Add EntityMoveEvent
// Purpur start - Ridables
if (this.xo != this.getX() || this.yo != this.getY() || this.zo != this.getZ() || this.yRotO != this.getYRot() || this.xRotO != this.getXRot()) {
@@ -3769,7 +3769,14 @@ public abstract class LivingEntity extends Entity implements Attackable, net.caf
return;
}
// Paper end - don't run getEntities if we're not going to use its result
- List<Entity> entities = this.level().getEntities(this, this.getBoundingBox(), EntitySelector.pushable(this, this.level().paperConfig().collisions.fixClimbingBypassingCrammingRule)); // Paper - Climbing should not bypass cramming gamerule
+ // Leaf start - Only player pushable
+ final AABB box = this.getBoundingBox();
+ final Predicate<Entity> conditions = EntitySelector.pushable(this, this.level().paperConfig().collisions.fixClimbingBypassingCrammingRule);
+
+ List<Entity> entities = org.dreeam.leaf.config.modules.gameplay.OnlyPlayerPushable.enabled
+ ? getNearbyPushablePlayers(this, box, conditions)
+ : this.level().getEntities(this, box, conditions); // Paper - Climbing should not bypass cramming gamerule
+ // Leaf end - Only player pushable
if (!entities.isEmpty()) {
// Paper - don't run getEntities if we're not going to use its result; moved up
if (_int > 0 && entities.size() > _int - 1 && this.random.nextInt(4) == 0) {
@@ -3802,6 +3809,44 @@ public abstract class LivingEntity extends Entity implements Attackable, net.caf
}
}
+ // Leaf start - Only player pushable
+ public List<Entity> getNearbyPushablePlayers(Entity entity, AABB box, Predicate<Entity> conditions) {
+ final Vec3 vec = entity.position;
+ final net.minecraft.core.BlockPos.MutableBlockPos mutablePos = new net.minecraft.core.BlockPos.MutableBlockPos();
+
+ mutablePos.set(vec.x, vec.y, vec.z);
+
+ final ca.spottedleaf.moonrise.common.list.ReferenceList<ServerPlayer> players = ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel) this.level()).moonrise$getNearbyPlayers().getPlayers(
+ mutablePos, ca.spottedleaf.moonrise.common.misc.NearbyPlayers.NearbyMapType.SPAWN_RANGE
+ );
+
+ if (players == null) {
+ return new ArrayList<>();
+ }
+
+ List<Entity> ret = null;
+
+ final ServerPlayer[] raw = players.getRawDataUnchecked();
+ final int len = players.size();
+
+ java.util.Objects.checkFromIndexSize(0, len, raw.length);
+
+ for (int i = 0; i < len; ++i) {
+ final ServerPlayer player = raw[i];
+ if (player != entity && box.intersects(player.getBoundingBox()) && conditions.test(player)) {
+ if (ret == null) {
+ ret = new ArrayList<>(len - i);
+ ret.add(player);
+ } else {
+ ret.add(player);
+ }
+ }
+ }
+
+ return ret == null ? new ArrayList<>() : ret;
+ }
+ // Leaf end - Only player pushable
+
protected void checkAutoSpinAttack(AABB boundingBoxBeforeSpin, AABB boundingBoxAfterSpin) {
AABB aabb = boundingBoxBeforeSpin.minmax(boundingBoxAfterSpin);
List<Entity> entities = this.level().getEntities(this, aabb);
diff --git a/net/minecraft/world/entity/decoration/ArmorStand.java b/net/minecraft/world/entity/decoration/ArmorStand.java
index 21153f37c169e987d7876d1b914105223ac10ee7..a8bd9f027b5ce360b9e720a7734451bcf9f701d4 100644
--- a/net/minecraft/world/entity/decoration/ArmorStand.java
+++ b/net/minecraft/world/entity/decoration/ArmorStand.java
@@ -326,7 +326,7 @@ public class ArmorStand extends LivingEntity implements net.caffeinemc.mods.lith
@Override
protected void pushEntities() {
- if (!this.level().paperConfig().entities.armorStands.doCollisionEntityLookups) return; // Paper - Option to prevent armor stands from doing entity lookups
+ if (org.dreeam.leaf.config.modules.gameplay.OnlyPlayerPushable.enabled || !this.level().paperConfig().entities.armorStands.doCollisionEntityLookups) return; // Paper - Option to prevent armor stands from doing entity lookups // Leaf - Only player pushable
for (Entity entity : this.level().getEntitiesOfClass(AbstractMinecart.class, this.getBoundingBox(), RIDABLE_MINECARTS)) { // Paper - optimise collisions
if (this.distanceToSqr(entity) <= 0.2) {
entity.push(this);

View File

@@ -1,61 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Thu, 13 Feb 2025 01:25:40 +0100
Subject: [PATCH] Remove iterators from Inventory#contains
diff --git a/net/minecraft/world/entity/player/Inventory.java b/net/minecraft/world/entity/player/Inventory.java
index 839cbb67d3d38960d9114a4db5bab911b66a573c..e2237ffebadc8f010688c6e7336f4278193a1a20 100644
--- a/net/minecraft/world/entity/player/Inventory.java
+++ b/net/minecraft/world/entity/player/Inventory.java
@@ -568,9 +568,13 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(ItemStack stack) {
- for (List<ItemStack> list : this.compartments) {
- for (ItemStack itemStack : list) {
- if (!itemStack.isEmpty() && ItemStack.isSameItemSameComponents(itemStack, stack)) {
+ // Leaf start - Remove iterators from Inventory#contains
+ for (int i = 0; i < this.compartments.size(); i++) {
+ List<ItemStack> list = this.compartments.get(i);
+ for (int j = 0; j < list.size(); j++) {
+ ItemStack itemstack1 = list.get(j);
+ if (!itemstack1.isEmpty() && ItemStack.isSameItemSameComponents(itemstack1, stack)) {
+ // Leaf end - Remove iterators from Inventory#contains
return true;
}
}
@@ -580,9 +584,13 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(TagKey<Item> tag) {
- for (List<ItemStack> list : this.compartments) {
- for (ItemStack itemStack : list) {
- if (!itemStack.isEmpty() && itemStack.is(tag)) {
+ // Leaf start - Remove iterators from Inventory#contains
+ for (int i = 0; i < this.compartments.size(); i++) {
+ List<ItemStack> list = this.compartments.get(i);
+ for (int j = 0; j < list.size(); j++) {
+ ItemStack itemstack = list.get(j);
+ if (!itemstack.isEmpty() && itemstack.is(tag)) {
+ // Leaf end - Remove iterators from Inventory#contains
return true;
}
}
@@ -592,9 +600,13 @@ public class Inventory implements Container, Nameable {
}
public boolean contains(Predicate<ItemStack> predicate) {
- for (List<ItemStack> list : this.compartments) {
- for (ItemStack itemStack : list) {
- if (predicate.test(itemStack)) {
+ // Leaf start - Remove iterators from Inventory#contains
+ for (int i = 0; i < this.compartments.size(); i++) {
+ List<ItemStack> list = this.compartments.get(i);
+ for (int j = 0; j < list.size(); j++) {
+ ItemStack itemstack = list.get(j);
+ if (predicate.test(itemstack)) {
+ // Leaf end - Remove iterators from Inventory#contains
return true;
}
}

View File

@@ -1,72 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 14 Feb 2025 14:58:59 +0100
Subject: [PATCH] Alternative Brain Behaviour
In the test, this can give ~54.87% improvement (~25712ms -> ~11604ms),
under 1024 villagers situation.
diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java
index e27284f9897923f67985e3d60c3438bd00cc4a51..0ff7564e0e848bd38e82f9089bfd7249fa649dc5 100644
--- a/net/minecraft/world/entity/ai/Brain.java
+++ b/net/minecraft/world/entity/ai/Brain.java
@@ -268,23 +268,52 @@ public class Brain<E extends LivingEntity> {
return this.activeActivities;
}
+ // Leaf start - Alternative Brain Behaviour
+ private ObjectArrayList<BehaviorControl<? super E>> runningBehaviorsCache;
+ private long lastRunningBehaviorCheck = -1;
+ // Leaf end - Alternative Brain Behaviour
+
@Deprecated
@VisibleForDebug
public List<BehaviorControl<? super E>> getRunningBehaviors() {
- List<BehaviorControl<? super E>> list = new ObjectArrayList<>();
+ // Leaf start - Alternative Brain Behaviour
+ long currentTick = getCurrentTick();
+
+ // Use cached result if within update interval
+ if (runningBehaviorsCache != null && (currentTick - lastRunningBehaviorCheck) < org.dreeam.leaf.config.modules.opt.BrainRunningBehaviorCacheUpdate.interval) {
+ return runningBehaviorsCache;
+ }
+
+ // Initialize or reuse cache list
+ if (runningBehaviorsCache == null) {
+ runningBehaviorsCache = new ObjectArrayList<>(32);
+ } else {
+ runningBehaviorsCache.clear();
+ }
+
+ for (Map<Activity, Set<BehaviorControl<? super E>>> activityMap : availableBehaviorsByPriority.values()) {
+ for (Set<BehaviorControl<? super E>> behaviors : activityMap.values()) {
+ if (behaviors.isEmpty()) continue;
- for (Map<Activity, Set<BehaviorControl<? super E>>> map : this.availableBehaviorsByPriority.values()) {
- for (Set<BehaviorControl<? super E>> set : map.values()) {
- for (BehaviorControl<? super E> behaviorControl : set) {
- if (behaviorControl.getStatus() == Behavior.Status.RUNNING) {
- list.add(behaviorControl);
+ for (BehaviorControl<? super E> behavior : behaviors) {
+ if (behavior.getStatus() == Behavior.Status.RUNNING) {
+ runningBehaviorsCache.add(behavior);
}
}
}
}
- return list;
+ lastRunningBehaviorCheck = currentTick;
+
+ return runningBehaviorsCache;
+ }
+
+ // Helper method to get current tick
+ private long getCurrentTick() {
+ // This should be implemented to return the current game tick
+ return System.nanoTime() / 50_000_000; // Approximate tick time of 50ms
}
+ // Leaf end - Alternative Brain Behaviour
public void useDefaultActivity() {
this.setActiveActivity(this.defaultActivity);

View File

@@ -1,87 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Fri, 14 Feb 2025 20:08:14 +0100
Subject: [PATCH] Cache eligible players for despawn checks
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
index 20ded514a74652685b2f785c7fe5fda19e36b2a5..5da07e22ef9dac7baca9d8450b7eae3f6fa141b1 100644
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -735,6 +735,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
return this.structureManager;
}
+ public Player[] eligibleDespawnCheckingPlayerCache = new Player[0]; // Leaf - Cache eligible players for despawn checks
+
public void tick(BooleanSupplier hasTimeLeft) {
this.handlingTick = true;
TickRateManager tickRateManager = this.tickRateManager();
@@ -802,6 +804,19 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
}
io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR
+
+ // Leaf start - Cache eligible players for despawn checks
+ List<ServerPlayer> serverPlayers = new ArrayList<>(players().size());
+ for (int i = 0; i < players().size(); i++) {
+ ServerPlayer player = players().get(i);
+ if (net.minecraft.world.entity.EntitySelector.PLAYER_AFFECTS_SPAWNING.test(player)) {
+ serverPlayers.add(player);
+ }
+ }
+
+ eligibleDespawnCheckingPlayerCache = serverPlayers.toArray(new Player[0]);
+ // Leaf end - Cache eligible players for despawn checks
+
this.entityTickList
.forEach(
entity -> {
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 336215befa7eb4b20fc86f224a019080cea70113..e2b15968e89a532ec21c786f41b7f9322fd65a04 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -1576,6 +1576,13 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
this.containerMenu.broadcastChanges();
}
+ // Leaf start - Cache eligible players for despawn checks
+ @Override
+ public boolean isAlive() {
+ return !this.isRemoved() && this.entityData.get(DATA_HEALTH_ID) > 0.0f && !this.dead;
+ }
+ // Leaf end - Cache eligible players for despawn checks
+
// CraftBukkit start - moved bed result checks from below into separate method
private Either<Player.BedSleepingProblem, Unit> getBedResult(BlockPos at, Direction direction) {
if (this.isSleeping() || !this.isAlive()) {
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
index 54eeb0b112112bc5d3f4165c0ea43cf67931a739..05d5cde42b7011091ef4ee874c0d9d5586ae3f10 100644
--- a/net/minecraft/world/entity/Mob.java
+++ b/net/minecraft/world/entity/Mob.java
@@ -854,7 +854,24 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
- Entity nearestPlayer = this.level().findNearbyPlayer(this, -1.0, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API
+ // Leaf start - Cache eligible players for despawn checks
+ Entity nearestPlayer = null;
+
+ if (this.level() instanceof ServerLevel serverLevel) {
+ double minDist = Double.MAX_VALUE;
+ for (int i = 0; i < serverLevel.eligibleDespawnCheckingPlayerCache.length; i++) {
+ Player cachedPlayer = serverLevel.eligibleDespawnCheckingPlayerCache[i];
+ double d1 = cachedPlayer.distanceToSqr(this);
+ if (d1 <= minDist) {
+ minDist = d1;
+ nearestPlayer = cachedPlayer;
+ }
+ }
+ } else {
+ nearestPlayer = this.level().findNearbyPlayer(this, -1.0, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API
+ }
+ // Leaf end - Cache eligible players for despawn checks
+
if (nearestPlayer != null) {
// Paper start - Configurable despawn distances
final io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRangePair despawnRangePair = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());

View File

@@ -1,73 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 16 Feb 2025 09:21:50 +0100
Subject: [PATCH] Slightly optimise getNearestPlayer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Original:
Condition checks per iteration: ~3-4 (predicate check, distance check, and d comparison)
Calculations per iteration: Distance calculation + potentially a multiplication
Total operations: ~(5-6) × n
Patch:
Condition checks per iteration: 1 (just the distance comparison)
Calculations per iteration: Distance calculation
One-time operation: Convert distance to squared distance
Total operations: ~3 × n (in the no-predicate case) or ~4 × n (with predicate)
diff --git a/net/minecraft/world/level/EntityGetter.java b/net/minecraft/world/level/EntityGetter.java
index 670860df81a3abfc1b8b53be505fce0ee32ee2c4..083a2b5da246113913bcd5d0b2b9be42cf0554d9 100644
--- a/net/minecraft/world/level/EntityGetter.java
+++ b/net/minecraft/world/level/EntityGetter.java
@@ -201,23 +201,42 @@ public interface EntityGetter extends ca.spottedleaf.moonrise.patches.chunk_syst
}
// Paper end - Affects Spawning API
+ // Leaf start - Slightly optimise getNearestPlayer
@Nullable
default Player getNearestPlayer(double x, double y, double z, double distance, @Nullable Predicate<Entity> predicate) {
- double d = -1.0;
+ if (distance < 0.0) {
+ distance = Double.MAX_VALUE;
+ } else {
+ distance = distance * distance;
+ }
+
Player player = null;
- for (Player player1 : this.players()) {
- if (predicate == null || predicate.test(player1)) {
+ if (predicate == null) {
+ for (int i = 0; i < this.players().size(); i++) {
+ Player player1 = this.players().get(i);
double d1 = player1.distanceToSqr(x, y, z);
- if ((distance < 0.0 || d1 < distance * distance) && (d == -1.0 || d1 < d)) {
- d = d1;
+ if (d1 < distance) {
+ distance = d1;
player = player1;
}
}
+ } else {
+ for (int i = 0; i < this.players().size(); i++) {
+ Player player1 = this.players().get(i);
+ if (predicate.test(player1)) {
+ double d1 = player1.distanceToSqr(x, y, z);
+ if (d1 < distance) {
+ distance = d1;
+ player = player1;
+ }
+ }
+ }
}
return player;
}
+ // Leaf end - Slightly optimise getNearestPlayer
// Paper start
default List<org.bukkit.entity.HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, boolean notSpectator) {

View File

@@ -1,19 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: "Author: PureGero" <puregero@gmail.com>
Date: Thu, 1 Aug 2024 00:43:05 +0900
Subject: [PATCH] ShreddedPaper: Don't block main thread in
Connection#syncAfterConfigurationChange
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
index 00a82873d226f113278632a53c0faca420dd67d4..5b46036868b6c9d082e35591e58735e16adaae62 100644
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -325,6 +325,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
private static void syncAfterConfigurationChange(ChannelFuture future) {
try {
+ if (ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()) net.minecraft.server.MinecraftServer.getServer().managedBlock(future::isDone); // ShreddedPaper - Don't block main thread in Connection#syncAfterConfigurationChange
future.syncUninterruptibly();
} catch (Exception var2) {
if (var2 instanceof ClosedChannelException) {

View File

@@ -1,24 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 16 Feb 2025 01:13:04 +0100
Subject: [PATCH] Use ensureCapacity to pre-populate the size of ticking chunks
list output
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index 6735f9e23c8972b7cf1438a2f3b49d780c1ff78c..c80464d333bd37a9b8bc7cea2291c8c72e6f9bd6 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -585,7 +585,11 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
final ServerChunkCache.ChunkAndHolder[] raw = tickingChunks.getRawDataUnchecked();
final int size = tickingChunks.size();
- final ChunkMap chunkMap = this.chunkMap;
+ // Leaf start - Use ensureCapacity to pre-populate the size of ticking chunks list output
+ if (output instanceof ArrayList<LevelChunk> arrayList) {
+ arrayList.ensureCapacity(size);
+ }
+ // Leaf end - Use ensureCapacity to pre-populate the size of ticking chunks list output
for (int i = 0; i < size; ++i) {
final ServerChunkCache.ChunkAndHolder chunkAndHolder = raw[i];

View File

@@ -1,28 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
Date: Sun, 16 Feb 2025 01:13:04 +0100
Subject: [PATCH] Directly use the pre-filtered ticking chunks list as the
output
This patch uses already pre filtered chunks, which completely skips the isChunkNearPlayer check
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
index c80464d333bd37a9b8bc7cea2291c8c72e6f9bd6..b1f1b596a597d559aa672a3cb46a03917ad746af 100644
--- a/net/minecraft/server/level/ServerChunkCache.java
+++ b/net/minecraft/server/level/ServerChunkCache.java
@@ -592,14 +592,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
// Leaf end - Use ensureCapacity to pre-populate the size of ticking chunks list output
for (int i = 0; i < size; ++i) {
- final ServerChunkCache.ChunkAndHolder chunkAndHolder = raw[i];
- final LevelChunk levelChunk = chunkAndHolder.chunk();
-
- if (!this.isChunkNearPlayer(chunkMap, levelChunk.getPos(), levelChunk)) {
- continue;
- }
-
- output.add(levelChunk);
+ output.add(raw[i].chunk()); // Leaf - Directly use the pre-filtered ticking chunks list as the output
}
// Paper end - chunk tick iteration optimisation
}