9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 08:19:26 +00:00
Files
SakuraMC/patches/server/0025-Add-maxSearch-to-getEntities.patch
Samsuik 264bf21712 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b4f04ff Add Plugin#getDataPath (#11080)
PaperMC/Paper@05e5865 Add ItemType#getItemRarity (#11049)
PaperMC/Paper@aa929d6 Call PlayerLaunchProjectileEvent for wind charge (#10911)
PaperMC/Paper@8b23018 Avoid collision shapes outside world border in findFreePosition
PaperMC/Paper@3b45454 Port random ticking optimisation from Moonrise
PaperMC/Paper@77fcb29 Apply incremental player/level saving patch
PaperMC/Paper@9fd7710 Apply automatic regionfile header recalculation patch
PaperMC/Paper@b57b24d Do not try to stop main thread during watchdog shutdown
PaperMC/Paper@2cd8c46 Add OMINOUS_ITEM_SPAWNER SpawnReason (#10897)
PaperMC/Paper@ef96a69 Fire EntityChangeBlockEvent for weaving potion effect (#11087)
PaperMC/Paper@a6ceda1 distinguish between null and empty map in API (#10829)
PaperMC/Paper@506f165 Don't store removed components in multiple places (#11091)
PaperMC/Paper@ceeb8c1 Disable timings by default (#11095)
PaperMC/Paper@05ed6a6 Fix priority scheduling logic
PaperMC/Paper@967f98a Optimise chunk tick checking during chunk tick
PaperMC/Paper@00b949f Remove Moonrise utils to MCUtils, remove duplicated/unused utils
PaperMC/Paper@4efd24b Remove unused chunk system hooks in MCUtils
PaperMC/Paper@b653276 Finish chunk tick iteration optimisation port from Moonrise
PaperMC/Paper@2df5bba Log throwable when failing to save chunk/poi/entity data
PaperMC/Paper@44c3dd0 fix exact choice shapeless recipes (#10973)
PaperMC/Paper@dd11ef8 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102)
PaperMC/Paper@3c8a7fe Re-add missing chunk event calls (#11104)
PaperMC/Paper@a8db527 Even more cleanup of mcutil patch
PaperMC/Paper@d08e8d1 Add total time to done message (#11109)
PaperMC/Paper@2a39276 Add CrafterCraftEvent (#11082)
PaperMC/Paper@75af62b Split rewriting flag into `paper.disableOldApiSupport` and `paper.disablePluginRemapping` (#11108)
PaperMC/Paper@7ea4039 Fixup startup time log message
PaperMC/Paper@e71c1df Call PlayerChunkUnloadEvent
PaperMC/Paper@968bdeb Make CraftComplexRecipe extend CraftingRecipe (#11114)
PaperMC/Paper@f1f01a1 Adjust done message again (#11118)
2024-07-20 00:57:24 +01:00

133 lines
8.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Thu, 27 Jun 2024 17:02:32 +0100
Subject: [PATCH] Add maxSearch to getEntities
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
index 8126c4fdbbc586cf3722c6ee2986338de044602e..0a8f593784322454335236d6f0dbb6ec9a9b8332 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
@@ -336,10 +336,16 @@ public final class ChunkEntitySlices {
this.allEntities.getEntities(except, box, into, predicate);
}
+ // Sakura start - add maxSearch to getEntities
+ public boolean getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
+ final int maxCount) {
+ return this.getEntities(except, box, into, predicate, maxCount, Integer.MAX_VALUE);
+ }
public boolean getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
- final int maxCount) {
- return this.allEntities.getEntitiesWithEnderDragonPartsLimited(except, box, into, predicate, maxCount);
+ final int maxCount, final int maxSearch) {
+ return this.allEntities.getEntitiesWithEnderDragonPartsLimited(except, box, into, predicate, maxCount, maxSearch);
+ // Sakura end - add maxSearch to getEntities
}
public boolean getEntitiesWithoutDragonParts(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
@@ -693,8 +699,16 @@ public final class ChunkEntitySlices {
}
}
+ // Sakura start - add maxSearch to getEntities
public boolean getEntitiesWithEnderDragonPartsLimited(final Entity except, final AABB box, final List<Entity> into,
final Predicate<? super Entity> predicate, final int maxCount) {
+ return this.getEntitiesWithEnderDragonPartsLimited(except, box, into, predicate, maxCount, Integer.MAX_VALUE);
+ }
+
+ public boolean getEntitiesWithEnderDragonPartsLimited(final Entity except, final AABB box, final List<Entity> into,
+ final Predicate<? super Entity> predicate, final int maxCount,
+ final int maxSearch) {
+ // Sakura end - add maxSearch to getEntities
if (this.count == 0) {
return false;
}
@@ -716,8 +730,14 @@ public final class ChunkEntitySlices {
final Entity[] storage = list.storage;
- for (int i = 0, len = Math.min(storage.length, list.size()); i < len; ++i) {
- final Entity entity = storage[i];
+ // Sakura start - add maxSearch to getEntities
+ final int len = Math.min(storage.length, list.size());
+ final int offset = this.slices.world.random.nextInt(len);
+ for (int i = 0; i < len; ++i) {
+ final int pos = (i + offset) % len;
+ final Entity entity = storage[pos];
+ if (i > maxSearch) break;
+ // Sakura end - add maxSearch to getEntities
if (entity == null || entity == except || !entity.getBoundingBox().intersects(box)) {
continue;
diff --git a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
index efc0c1acc8239dd7b00211a1d3bfd3fc3b2c810c..0ffbc8b459c3475ff0a9c307cb7bd144045f5f1c 100644
--- a/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java
@@ -801,8 +801,15 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
}
}
+ // Sakura start - add maxSearch to getEntities
public void getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
final int maxCount) {
+ this.getEntities(except, box, into, predicate, maxCount, Integer.MAX_VALUE);
+ }
+
+ public void getEntities(final Entity except, final AABB box, final List<Entity> into, final Predicate<? super Entity> predicate,
+ final int maxCount, final int maxSearch) {
+ // Sakura end - add maxSearch to getEntities
final int minChunkX = (Mth.floor(box.minX) - 2) >> 4;
final int minChunkZ = (Mth.floor(box.minZ) - 2) >> 4;
final int maxChunkX = (Mth.floor(box.maxX) + 2) >> 4;
@@ -834,7 +841,7 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
continue;
}
- if (chunk.getEntities(except, box, into, predicate, maxCount)) {
+ if (chunk.getEntities(except, box, into, predicate, maxCount, maxSearch)) { // Sakura - add maxSearch to getEntities
return;
}
}
@@ -1080,4 +1087,4 @@ public abstract class EntityLookup implements LevelEntityGetter<Entity> {
@Override
public void onRemove(final Entity.RemovalReason reason) {}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 70ce20d946287a7449da4efc958be5a9fa683afe..503e5afa3d9130738a9374e591277aae9dc08282 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1669,10 +1669,18 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
this.getEntities(filter, box, predicate, result, Integer.MAX_VALUE);
}
- // Paper start - rewrite chunk system
+ // Sakura start - add maxSearch to getEntities
public <T extends Entity> void getEntities(final EntityTypeTest<Entity, T> entityTypeTest,
final AABB boundingBox, final Predicate<? super T> predicate,
final List<? super T> into, final int maxCount) {
+ this.getEntities(entityTypeTest, boundingBox, predicate, into, maxCount, Integer.MAX_VALUE);
+ }
+
+ // Paper start - rewrite chunk system
+ public <T extends Entity> void getEntities(final EntityTypeTest<Entity, T> entityTypeTest,
+ final AABB boundingBox, final Predicate<? super T> predicate,
+ final List<? super T> into, final int maxCount, final int maxSearch) {
+ // Sakura end - add maxSearch to getEntities
this.getProfiler().incrementCounter("getEntities");
if (entityTypeTest instanceof net.minecraft.world.entity.EntityType<T> byType) {
@@ -1687,7 +1695,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
if (entityTypeTest == null) {
if (maxCount != Integer.MAX_VALUE) {
- ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel)this).moonrise$getEntityLookup().getEntities((Entity)null, boundingBox, (List)into, (Predicate)predicate, maxCount);
+ ((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel)this).moonrise$getEntityLookup().getEntities((Entity)null, boundingBox, (List)into, (Predicate)predicate, maxCount, maxSearch); // Sakura - add maxSearch to getEntities
return;
} else {
((ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel)this).moonrise$getEntityLookup().getEntities((Entity)null, boundingBox, (List)into, (Predicate)predicate);