From 4fa21c21fc1eefe5979c133ed5030b2f3cd5eb3f Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Tue, 3 Jun 2025 12:50:46 -0700 Subject: [PATCH] Update Moonrise to 1.21.6-pre2 See https://github.com/Tuinity/Moonrise/commit/b312be292122eef21cd8e617b5015f3e6f020eec --- .../0015-Moonrise-optimisation-patches.patch | 123 +++++++------ ...nate-Current-redstone-implementation.patch | 4 +- ...021-Entity-load-save-limit-per-chunk.patch | 31 ++-- ...additions-for-dynamic-hard-collision.patch | 163 ------------------ .../moonrise/paper/PaperHooks.java.patch | 11 +- 5 files changed, 94 insertions(+), 238 deletions(-) delete mode 100644 paper-server/patches/features/0030-Moonrise-additions-for-dynamic-hard-collision.patch diff --git a/paper-server/patches/features/0015-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0015-Moonrise-optimisation-patches.patch index f308e4c430..d2fb8d1686 100644 --- a/paper-server/patches/features/0015-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0015-Moonrise-optimisation-patches.patch @@ -297,7 +297,7 @@ index 0000000000000000000000000000000000000000..1b8193587814225c2ef2c5d9e667436e + } +} diff --git a/ca/spottedleaf/moonrise/paper/PaperHooks.java b/ca/spottedleaf/moonrise/paper/PaperHooks.java -index a013f00e981e4411de9cbc65eb7694a15774be10..90366380685ecca4135c57f6b497f58af8045f00 100644 +index 0ced5a8990b9fa2bdda90eac0a1c7ab27effe0e9..8506fc08bc2a2933e8f4f3a3e636913fa96c3d84 100644 --- a/ca/spottedleaf/moonrise/paper/PaperHooks.java +++ b/ca/spottedleaf/moonrise/paper/PaperHooks.java @@ -13,6 +13,7 @@ import net.minecraft.server.level.ChunkHolder; @@ -308,32 +308,24 @@ index a013f00e981e4411de9cbc65eb7694a15774be10..90366380685ecca4135c57f6b497f58a import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.boss.EnderDragonPart; import net.minecraft.world.level.BlockGetter; -@@ -147,8 +148,8 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo - } +@@ -150,7 +151,7 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo @Override -- public long[] getCounterTypesUncached(final net.minecraft.server.level.TicketType type) { + public long[] getCounterTypesUncached(final net.minecraft.server.level.TicketType type) { - return new long[0]; -+ public long[] getCounterTypesUncached(final TicketType type) { -+ return type == TicketType.FORCED ? new long[] { ca.spottedleaf.moonrise.patches.chunk_system.ticket.ChunkSystemTicketType.COUNTER_TYPE_FORCED } : it.unimi.dsi.fastutil.longs.LongArrays.EMPTY_ARRAY; ++ return type == TicketType.FORCED ? new long[] { ca.spottedleaf.moonrise.patches.chunk_system.ticket.ChunkSystemTicketType.COUNTER_TYPE_FORCED } : it.unimi.dsi.fastutil.longs.LongArrays.EMPTY_ARRAY; // Paper - rewrite chunk system } @Override -@@ -239,6 +240,7 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo - net.minecraft.world.level.chunk.status.ChunkStatusTasks.postLoadProtoChunk( - world, - net.minecraft.world.level.storage.TagValueInput.create(net.minecraft.util.ProblemReporter.DISCARDING, world.registryAccess(), chunk.getEntities()) -+ , chunk.getPos() // Paper - rewrite chunk system - add ChunkPos param - ); +@@ -239,7 +240,7 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo + @Override + public void postLoadProtoChunk(final ServerLevel world, final ProtoChunk chunk) { + try (final net.minecraft.util.ProblemReporter.ScopedCollector scopedCollector = new net.minecraft.util.ProblemReporter.ScopedCollector(chunk.problemPath(), LOGGER)) { +- net.minecraft.world.level.chunk.status.ChunkStatusTasks.postLoadProtoChunk(world, net.minecraft.world.level.storage.TagValueInput.create(scopedCollector, world.registryAccess(), chunk.getEntities())); ++ net.minecraft.world.level.chunk.status.ChunkStatusTasks.postLoadProtoChunk(world, net.minecraft.world.level.storage.TagValueInput.create(scopedCollector, world.registryAccess(), chunk.getEntities()), chunk.getPos()); // Paper - rewrite chunk system - add ChunkPos param + } } -@@ -246,4 +248,4 @@ public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHo - public int modifyEntityTrackingRange(final Entity entity, final int currentRange) { - return org.spigotmc.TrackingRange.getEntityTrackingRange(entity, currentRange); - } --} -\ No newline at end of file -+} diff --git a/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java b/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java index ce81e9f4f1e80be3b4f0cbdd95609990f9006534..975a2e4ea1f84e81fa3526395b43cb8157a06243 100644 --- a/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java @@ -1057,15 +1049,16 @@ index 0000000000000000000000000000000000000000..02d596647ab78afb056eefe14ffa0ef2 +} diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java b/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java new file mode 100644 -index 0000000000000000000000000000000000000000..c7da23900228aab3a5673eb5adfada5091140319 +index 0000000000000000000000000000000000000000..1d2498e33b9cd5a22cb348a213be3d75281b6d24 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java -@@ -0,0 +1,44 @@ +@@ -0,0 +1,45 @@ +package ca.spottedleaf.moonrise.patches.chunk_system.entity; + +import ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData; +import net.minecraft.server.level.FullChunkStatus; +import net.minecraft.world.entity.Entity; ++import net.minecraft.world.entity.animal.HappyGhast; +import net.minecraft.world.entity.monster.Shulker; +import net.minecraft.world.entity.vehicle.AbstractMinecart; +import net.minecraft.world.entity.vehicle.Boat; @@ -1076,7 +1069,7 @@ index 0000000000000000000000000000000000000000..c7da23900228aab3a5673eb5adfada50 + + // for mods to override + public default boolean moonrise$isHardCollidingUncached() { -+ return this instanceof Boat || this instanceof AbstractMinecart || this instanceof Shulker || ((Entity)this).canBeCollidedWith(); ++ return this instanceof Boat || this instanceof AbstractMinecart || this instanceof Shulker || this instanceof HappyGhast || ((Entity)this).canBeCollidedWith(null); + } + + public FullChunkStatus moonrise$getChunkStatus(); @@ -3305,10 +3298,10 @@ index 0000000000000000000000000000000000000000..59cbbf65c9df5c680b803f6dd6436a35 +} diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java new file mode 100644 -index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cdc7efdf56 +index 0000000000000000000000000000000000000000..c380487a97f626163e1f13d87231d64ce2ea4b24 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -0,0 +1,569 @@ +@@ -0,0 +1,591 @@ +package ca.spottedleaf.moonrise.patches.chunk_system.level.entity; + +import ca.spottedleaf.moonrise.common.PlatformHooks; @@ -3316,6 +3309,7 @@ index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cd +import ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData; +import ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity; +import com.google.common.collect.ImmutableList; ++import com.mojang.logging.LogUtils; +import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; +import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; +import net.minecraft.nbt.CompoundTag; @@ -3325,6 +3319,7 @@ index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cd +import net.minecraft.server.level.FullChunkStatus; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.Mth; ++import net.minecraft.util.ProblemReporter; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntitySpawnReason; +import net.minecraft.world.entity.EntityType; @@ -3332,9 +3327,14 @@ index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cd +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; ++import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.storage.EntityStorage; +import net.minecraft.world.level.entity.Visibility; ++import net.minecraft.world.level.storage.TagValueInput; ++import net.minecraft.world.level.storage.TagValueOutput; ++import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.phys.AABB; ++import org.slf4j.Logger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; @@ -3343,6 +3343,8 @@ index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cd + +public final class ChunkEntitySlices { + ++ private static final Logger LOGGER = LogUtils.getLogger(); ++ + public final int minSection; + public final int maxSection; + public final int chunkX; @@ -3385,9 +3387,12 @@ index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cd + this.chunkData = chunkData; + } + -+ public static List readEntities(final ServerLevel world, final CompoundTag compoundTag) { -+ // TODO check this and below on update for format changes -+ return EntityType.loadEntitiesRecursive(compoundTag.getListOrEmpty("Entities"), world, EntitySpawnReason.LOAD).collect(ImmutableList.toImmutableList()); ++ public static List readEntities(final ServerLevel world, final ChunkPos pos, final CompoundTag compoundTag) { ++ try (final ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(ChunkAccess.problemPath(pos), LOGGER)) { ++ ValueInput valueinput = TagValueInput.create(scopedCollector, world.registryAccess(), compoundTag); ++ // TODO check this and below on update for format changes ++ return EntityType.loadEntitiesRecursive(valueinput.childrenListOrEmpty("Entities"), world, EntitySpawnReason.LOAD).collect(ImmutableList.toImmutableList()); ++ } + } + + // Paper start - rewrite chunk system @@ -3415,12 +3420,22 @@ index 0000000000000000000000000000000000000000..1c82dcd38f789707e15e8cbec72ef9cd + } + + final ListTag entitiesTag = new ListTag(); -+ for (final Entity entity : PlatformHooks.get().modifySavedEntities(world, chunkPos.x, chunkPos.z, entities)) { -+ CompoundTag compoundTag = new CompoundTag(); -+ if (entity.save(compoundTag)) { -+ entitiesTag.add(compoundTag); ++ try (final ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(ChunkAccess.problemPath(chunkPos), LOGGER)) { ++ for (final Entity entity : PlatformHooks.get().modifySavedEntities(world, chunkPos.x, chunkPos.z, entities)) { ++ final TagValueOutput savedEntity = TagValueOutput.createWithContext( ++ scopedCollector.forChild(entity.problemPath()), entity.registryAccess() ++ ); ++ ++ try { ++ if (entity.save(savedEntity)) { ++ entitiesTag.add(savedEntity.buildResult()); ++ } ++ } catch (final Exception ex) { ++ LOGGER.error("Entity type " + entity.getType() + " failed to serialize", ex); ++ } + } + } ++ + final CompoundTag ret = NbtUtils.addCurrentDataVersion(new CompoundTag()); + ret.put("Entities", entitiesTag); + ret.store("Position", ChunkPos.CODEC, chunkPos); @@ -9414,10 +9429,10 @@ index 0000000000000000000000000000000000000000..8f8268924ac92fca5df8a11e08031fa8 +} diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java new file mode 100644 -index 0000000000000000000000000000000000000000..e4a5fa25ed368fc4662c30934da2963ef446d782 +index 0000000000000000000000000000000000000000..2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java -@@ -0,0 +1,1997 @@ +@@ -0,0 +1,1999 @@ +package ca.spottedleaf.moonrise.patches.chunk_system.scheduling; + +import ca.spottedleaf.concurrentutil.completable.CallbackCompletable; @@ -9537,9 +9552,11 @@ index 0000000000000000000000000000000000000000..e4a5fa25ed368fc4662c30934da2963e + + if (!transientChunk) { + if (entityChunk != null) { -+ final List entities = ChunkEntitySlices.readEntities(this.world, entityChunk); ++ final ChunkPos pos = new ChunkPos(this.chunkX, this.chunkZ); + -+ ((ChunkSystemServerLevel)this.world).moonrise$getEntityLookup().addEntityChunkEntities(entities, new ChunkPos(this.chunkX, this.chunkZ)); ++ final List entities = ChunkEntitySlices.readEntities(this.world, pos, entityChunk); ++ ++ ((ChunkSystemServerLevel)this.world).moonrise$getEntityLookup().addEntityChunkEntities(entities, pos); + } + } + @@ -16359,7 +16376,7 @@ index 0000000000000000000000000000000000000000..1414f25ef770b0fe73ea618a450ade2f +} diff --git a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java new file mode 100644 -index 0000000000000000000000000000000000000000..9f8fb5d96d7a9776a5b809c4bd474b404b452145 +index 0000000000000000000000000000000000000000..01cd38bba2deb6cf65c82b4e4ec352a2998fd339 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java @@ -0,0 +1,2185 @@ @@ -18456,7 +18473,7 @@ index 0000000000000000000000000000000000000000..9f8fb5d96d7a9776a5b809c4bd474b40 + continue; + } + -+ if ((entity == null && otherEntity.canBeCollidedWith(null)) || (entity != null && entity.canCollideWith(otherEntity))) { ++ if ((entity == null && otherEntity.canBeCollidedWith(entity)) || (entity != null && entity.canCollideWith(otherEntity))) { + if (checkOnly) { + return true; + } else { @@ -26824,7 +26841,7 @@ index 283f240511898e416b83ec4dcccd4901889b80bb..3d5a8163a7dd78a195b77c4aaebdee2d if (!passengers.equals(this.lastPassengers)) { List list = this.mountedOrDismounted(passengers).map(Entity::getUUID).toList(); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 49008b4cbaead8a66a93d2b0d4b50b335a6c3eed..4ff31ae3af6840fbce2f76f5db075d0a2e9535d8 100644 +index 49008b4cbaead8a66a93d2b0d4b50b335a6c3eed..f9c96bbdc54e68b9216b7f8662bfae03012d2866 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -168,7 +168,7 @@ import net.minecraft.world.ticks.LevelTicks; @@ -27508,18 +27525,16 @@ index 49008b4cbaead8a66a93d2b0d4b50b335a6c3eed..4ff31ae3af6840fbce2f76f5db075d0a } public void startTickingChunk(LevelChunk chunk) { -@@ -2165,8 +2465,9 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe - List list = ChunkPos.rangeClosed(chunkPos, i).toList(); +@@ -2166,7 +2466,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.chunkSource.addTicketWithRadius(TicketType.UNKNOWN, chunkPos, i); list.forEach(chunkPos1 -> this.getChunk(chunkPos1.x, chunkPos1.z)); -+ if (true) return; // Paper - rewrite chunk system this.server.managedBlock(() -> { - this.entityManager.processPendingLoads(); -+ // Paper - rewrite chunk system ++ //this.entityManager.processPendingLoads(); // Paper - rewrite chunk system for (ChunkPos chunkPos1 : list) { if (!this.areEntitiesLoaded(chunkPos1.toLong())) { -@@ -2181,28 +2482,38 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2181,28 +2481,38 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @Override public void close() throws IOException { super.close(); @@ -27564,7 +27579,7 @@ index 49008b4cbaead8a66a93d2b0d4b50b335a6c3eed..4ff31ae3af6840fbce2f76f5db075d0a } public boolean anyPlayerCloseEnoughForSpawning(BlockPos pos) { -@@ -2214,7 +2525,10 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2214,7 +2524,10 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } public boolean canSpawnEntitiesInChunk(ChunkPos chunkPos) { @@ -27576,7 +27591,7 @@ index 49008b4cbaead8a66a93d2b0d4b50b335a6c3eed..4ff31ae3af6840fbce2f76f5db075d0a } @Override -@@ -2269,7 +2583,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2269,7 +2582,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @Override public CrashReportCategory fillReportDetails(CrashReport report) { CrashReportCategory crashReportCategory = super.fillReportDetails(report); @@ -29623,7 +29638,7 @@ index 9f34fc4278860dd7bcfa1fd79b15e588b0cc3973..a7ebd624652cb6f0edc735bf6b9760e7 public ClipContext(Vec3 from, Vec3 to, ClipContext.Block block, ClipContext.Fluid fluid, Entity entity) { diff --git a/net/minecraft/world/level/EntityGetter.java b/net/minecraft/world/level/EntityGetter.java -index 300f3ed58109219d97846082941b860585f66fed..67f47982e238430b7adaa93f5e730b5e87eac741 100644 +index 300f3ed58109219d97846082941b860585f66fed..9175a7e4e6076626cb46144c5858c2f2474f1858 100644 --- a/net/minecraft/world/level/EntityGetter.java +++ b/net/minecraft/world/level/EntityGetter.java @@ -15,7 +15,7 @@ import net.minecraft.world.phys.shapes.BooleanOp; @@ -29735,7 +29750,7 @@ index 300f3ed58109219d97846082941b860585f66fed..67f47982e238430b7adaa93f5e730b5e + continue; + } + -+ if ((entity == null && otherEntity.canBeCollidedWith(null)) || (entity != null && entity.canCollideWith(otherEntity))) { ++ if ((entity == null && otherEntity.canBeCollidedWith(entity)) || (entity != null && entity.canCollideWith(otherEntity))) { + ret.add(Shapes.create(otherEntity.getBoundingBox())); } } @@ -31110,7 +31125,7 @@ index 8afaded394fcbf5d7ad4c51ea49642ce93cd5198..e5ccfb8cbfafed7bb0a1d888b5bc98a9 } diff --git a/net/minecraft/world/level/TicketStorage.java b/net/minecraft/world/level/TicketStorage.java -index ac9d453df4bfa3cc50f1909e0d425e5ba98e6d75..9c48dcc2a5fe11ae177ede4b53c5b31e1eb95765 100644 +index ac9d453df4bfa3cc50f1909e0d425e5ba98e6d75..669d347d90de6b083d56e995c7e3b022b54dd838 100644 --- a/net/minecraft/world/level/TicketStorage.java +++ b/net/minecraft/world/level/TicketStorage.java @@ -29,7 +29,7 @@ import net.minecraft.world.level.saveddata.SavedData; @@ -31344,10 +31359,9 @@ index ac9d453df4bfa3cc50f1909e0d425e5ba98e6d75..9c48dcc2a5fe11ae177ede4b53c5b31e public void deactivateTicketsOnClosing() { - this.removeTicketIf((_long, ticket) -> ticket.getType() != TicketType.UNKNOWN && ticket.getType() != TicketType.CHUNK_LOAD && ticket.getType() != TicketType.FUTURE_AWAIT, this.deactivatedTickets); -+ // Paper - rewrite chunk system - } - - public void removeTicketIf(BiPredicate biPredicate, @Nullable Long2ObjectOpenHashMap> map) { +- } +- +- public void removeTicketIf(BiPredicate biPredicate, @Nullable Long2ObjectOpenHashMap> map) { - ObjectIterator>> objectIterator = this.tickets.long2ObjectEntrySet().fastIterator(); - boolean flag = false; - @@ -31396,10 +31410,13 @@ index ac9d453df4bfa3cc50f1909e0d425e5ba98e6d75..9c48dcc2a5fe11ae177ede4b53c5b31e - } - } - } -- ++ // Paper - rewrite chunk system ++ } + - if (flag) { - this.updateForcedChunks(); - } ++ public void removeTicketIf(Predicate predicate, @Nullable Long2ObjectOpenHashMap> tickets) { + throw new UnsupportedOperationException(); // Paper - rewrite chunk system } diff --git a/paper-server/patches/features/0018-Add-Alternate-Current-redstone-implementation.patch b/paper-server/patches/features/0018-Add-Alternate-Current-redstone-implementation.patch index 55dac96773..5404a4f4ca 100644 --- a/paper-server/patches/features/0018-Add-Alternate-Current-redstone-implementation.patch +++ b/paper-server/patches/features/0018-Add-Alternate-Current-redstone-implementation.patch @@ -2326,7 +2326,7 @@ index 0000000000000000000000000000000000000000..298076a0db4e6ee6e4775ac43bf749d9 + } +} diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 4ff31ae3af6840fbce2f76f5db075d0a2e9535d8..cb8f47ec146d45ed223094e5ee9237cdc5a183be 100644 +index f9c96bbdc54e68b9216b7f8662bfae03012d2866..34b7769663e235b93c6388ab0c92c00f0297e42f 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -213,6 +213,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -2337,7 +2337,7 @@ index 4ff31ae3af6840fbce2f76f5db075d0a2e9535d8..cb8f47ec146d45ed223094e5ee9237cd @Override public @Nullable LevelChunk getChunkIfLoaded(int x, int z) { -@@ -2592,6 +2593,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2591,6 +2592,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe return this.chunkSource.getGenerator().getSeaLevel(); } diff --git a/paper-server/patches/features/0021-Entity-load-save-limit-per-chunk.patch b/paper-server/patches/features/0021-Entity-load-save-limit-per-chunk.patch index 02d3198fdf..90dcdaabd4 100644 --- a/paper-server/patches/features/0021-Entity-load-save-limit-per-chunk.patch +++ b/paper-server/patches/features/0021-Entity-load-save-limit-per-chunk.patch @@ -9,28 +9,29 @@ defaults are only included for certain entites, this allows setting limits for any entity type. diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index 1c82dcd38f789707e15e8cbec72ef9cdc7efdf56..ba20e87d2105ce53cdaf4049de2388d05fcd1b56 100644 +index c380487a97f626163e1f13d87231d64ce2ea4b24..b2bcfb3557a0326fd7ec1059f95d6da4568dfd80 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -104,7 +104,18 @@ public final class ChunkEntitySlices { +@@ -116,8 +116,19 @@ public final class ChunkEntitySlices { } final ListTag entitiesTag = new ListTag(); + final java.util.Map, Integer> savedEntityCounts = new java.util.HashMap<>(); // Paper - Entity load/save limit per chunk - for (final Entity entity : PlatformHooks.get().modifySavedEntities(world, chunkPos.x, chunkPos.z, entities)) { -+ // Paper start - Entity load/save limit per chunk -+ final EntityType entityType = entity.getType(); -+ final int saveLimit = world.paperConfig().chunks.entityPerChunkSaveLimit.getOrDefault(entityType, -1); -+ if (saveLimit > -1) { -+ if (savedEntityCounts.getOrDefault(entityType, 0) >= saveLimit) { -+ continue; + try (final ProblemReporter.ScopedCollector scopedCollector = new ProblemReporter.ScopedCollector(ChunkAccess.problemPath(chunkPos), LOGGER)) { + for (final Entity entity : PlatformHooks.get().modifySavedEntities(world, chunkPos.x, chunkPos.z, entities)) { ++ // Paper start - Entity load/save limit per chunk ++ final EntityType entityType = entity.getType(); ++ final int saveLimit = world.paperConfig().chunks.entityPerChunkSaveLimit.getOrDefault(entityType, -1); ++ if (saveLimit > -1) { ++ if (savedEntityCounts.getOrDefault(entityType, 0) >= saveLimit) { ++ continue; ++ } ++ savedEntityCounts.merge(entityType, 1, Integer::sum); + } -+ savedEntityCounts.merge(entityType, 1, Integer::sum); -+ } -+ // Paper end - Entity load/save limit per chunk - CompoundTag compoundTag = new CompoundTag(); - if (entity.save(compoundTag)) { - entitiesTag.add(compoundTag); ++ // Paper end - Entity load/save limit per chunk + final TagValueOutput savedEntity = TagValueOutput.createWithContext( + scopedCollector.forChild(entity.problemPath()), entity.registryAccess() + ); diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java index 98586dfc562cf6909df0f4bfa1c19e35b3172abe..f92adee1c187561d3790a5a5c8c81f5e1543ed97 100644 --- a/net/minecraft/world/entity/EntityType.java diff --git a/paper-server/patches/features/0030-Moonrise-additions-for-dynamic-hard-collision.patch b/paper-server/patches/features/0030-Moonrise-additions-for-dynamic-hard-collision.patch deleted file mode 100644 index fc0b53c47a..0000000000 --- a/paper-server/patches/features/0030-Moonrise-additions-for-dynamic-hard-collision.patch +++ /dev/null @@ -1,163 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Bjarne Koll -Date: Tue, 3 Jun 2025 14:52:34 +0200 -Subject: [PATCH] Moonrise additions for dynamic hard collision - - -diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java b/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java -index c7da23900228aab3a5673eb5adfada5091140319..10921a7702fa9a2f69d084b55a60359e93106a3b 100644 ---- a/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java -+++ b/ca/spottedleaf/moonrise/patches/chunk_system/entity/ChunkSystemEntity.java -@@ -3,17 +3,35 @@ package ca.spottedleaf.moonrise.patches.chunk_system.entity; - import ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData; - import net.minecraft.server.level.FullChunkStatus; - import net.minecraft.world.entity.Entity; -+import net.minecraft.world.entity.animal.HappyGhast; - import net.minecraft.world.entity.monster.Shulker; - import net.minecraft.world.entity.vehicle.AbstractMinecart; - import net.minecraft.world.entity.vehicle.Boat; - - public interface ChunkSystemEntity { - -- public boolean moonrise$isHardColliding(); -+ enum HardColliding { -+ NEVER, -+ ALWAYS, -+ SOMETIMES, -+ ; -+ } -+ -+ default public boolean moonrise$isHardColliding() { -+ return switch (this.moonrise$hardCollisionConstant()) { -+ case ALWAYS -> true; -+ case NEVER -> false; -+ case SOMETIMES -> ((Entity)this).canBeCollidedWith(null); -+ }; -+ } -+ -+ public HardColliding moonrise$hardCollisionConstant(); - - // for mods to override -- public default boolean moonrise$isHardCollidingUncached() { -- return this instanceof Boat || this instanceof AbstractMinecart || this instanceof Shulker || ((Entity)this).canBeCollidedWith(); -+ public default HardColliding moonrise$computeHardCollisionConstant() { -+ if (this instanceof Boat || this instanceof AbstractMinecart || this instanceof Shulker) return HardColliding.ALWAYS; -+ if (this instanceof HappyGhast) return HardColliding.SOMETIMES; -+ return ((Entity)this).canBeCollidedWith(null) ? HardColliding.ALWAYS : HardColliding.NEVER; - } - - public FullChunkStatus moonrise$getChunkStatus(); -diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index ba20e87d2105ce53cdaf4049de2388d05fcd1b56..64182ab42eb4b9455ed3a861e54a42e6d1ebe664 100644 ---- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -14,6 +14,7 @@ import net.minecraft.nbt.Tag; - import net.minecraft.server.level.FullChunkStatus; - import net.minecraft.server.level.ServerLevel; - import net.minecraft.util.Mth; -+import net.minecraft.util.ProblemReporter; - import net.minecraft.world.entity.Entity; - import net.minecraft.world.entity.EntitySpawnReason; - import net.minecraft.world.entity.EntityType; -@@ -23,6 +24,7 @@ import net.minecraft.world.level.ChunkPos; - import net.minecraft.world.level.Level; - import net.minecraft.world.level.chunk.storage.EntityStorage; - import net.minecraft.world.level.entity.Visibility; -+import net.minecraft.world.level.storage.TagValueInput; - import net.minecraft.world.phys.AABB; - import java.util.ArrayList; - import java.util.Arrays; -@@ -40,6 +42,7 @@ public final class ChunkEntitySlices { - - private final EntityCollectionBySection allEntities; - private final EntityCollectionBySection hardCollidingEntities; -+ private final EntityCollectionBySection sometimesHardCollidingEntities; - private final Reference2ObjectOpenHashMap, EntityCollectionBySection> entitiesByClass; - private final Reference2ObjectOpenHashMap, EntityCollectionBySection> entitiesByType; - private final EntityList entities = new EntityList(); -@@ -67,6 +70,7 @@ public final class ChunkEntitySlices { - - this.allEntities = new EntityCollectionBySection(this); - this.hardCollidingEntities = new EntityCollectionBySection(this); -+ this.sometimesHardCollidingEntities = new EntityCollectionBySection(this); - this.entitiesByClass = new Reference2ObjectOpenHashMap<>(); - this.entitiesByType = new Reference2ObjectOpenHashMap<>(); - -@@ -76,7 +80,11 @@ public final class ChunkEntitySlices { - - public static List readEntities(final ServerLevel world, final CompoundTag compoundTag) { - // TODO check this and below on update for format changes -- return EntityType.loadEntitiesRecursive(compoundTag.getListOrEmpty("Entities"), world, EntitySpawnReason.LOAD).collect(ImmutableList.toImmutableList()); -+ return EntityType.loadEntitiesRecursive( -+ TagValueInput.create(ProblemReporter.DISCARDING, world.registryAccess(), (List) (Object) compoundTag.getListOrEmpty("Entities")), -+ world, -+ EntitySpawnReason.LOAD -+ ).collect(ImmutableList.toImmutableList()); - } - - // Paper start - rewrite chunk system -@@ -117,7 +125,7 @@ public final class ChunkEntitySlices { - } - // Paper end - Entity load/save limit per chunk - CompoundTag compoundTag = new CompoundTag(); -- if (entity.save(compoundTag)) { -+ if (entity.save(net.minecraft.world.level.storage.TagValueOutput.createDiscardingWithContext(compoundTag, world.registryAccess()))) { - entitiesTag.add(compoundTag); - } - } -@@ -244,8 +252,9 @@ public final class ChunkEntitySlices { - - this.allEntities.addEntity(entity, sectionIndex); - -- if (((ChunkSystemEntity)entity).moonrise$isHardColliding()) { -- this.hardCollidingEntities.addEntity(entity, sectionIndex); -+ switch (((ChunkSystemEntity)entity).moonrise$hardCollisionConstant()) { -+ case ALWAYS -> this.hardCollidingEntities.addEntity(entity, sectionIndex); -+ case SOMETIMES -> this.sometimesHardCollidingEntities.addEntity(entity, sectionIndex); - } - - for (final Iterator, EntityCollectionBySection>> iterator = -@@ -278,8 +287,9 @@ public final class ChunkEntitySlices { - - this.allEntities.removeEntity(entity, sectionIndex); - -- if (((ChunkSystemEntity)entity).moonrise$isHardColliding()) { -- this.hardCollidingEntities.removeEntity(entity, sectionIndex); -+ switch (((ChunkSystemEntity)entity).moonrise$hardCollisionConstant()) { -+ case ALWAYS -> this.hardCollidingEntities.removeEntity(entity, sectionIndex); -+ case SOMETIMES -> this.sometimesHardCollidingEntities.removeEntity(entity, sectionIndex); - } - - for (final Iterator, EntityCollectionBySection>> iterator = -@@ -299,6 +309,7 @@ public final class ChunkEntitySlices { - - public void getHardCollidingEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { - this.hardCollidingEntities.getEntities(except, box, into, predicate); -+ this.sometimesHardCollidingEntities.getEntities(except, box, into, e -> e.canBeCollidedWith(except) && (predicate == null || predicate.test(e))); - } - - public void getEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { -diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index cb17579f2fd61e91fa4b220bff1f53f25c0fbaf1..502d83ff853a48f97ac6fbca43011e1171815271 100644 ---- a/net/minecraft/world/entity/Entity.java -+++ b/net/minecraft/world/entity/Entity.java -@@ -383,7 +383,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess - } - // Paper end - // Paper start - rewrite chunk system -- private final boolean isHardColliding = this.moonrise$isHardCollidingUncached(); -+ private final HardColliding constantHardCollision = this.moonrise$computeHardCollisionConstant(); - private net.minecraft.server.level.FullChunkStatus chunkStatus; - private ca.spottedleaf.moonrise.patches.chunk_system.level.chunk.ChunkData chunkData; - private int sectionX = Integer.MIN_VALUE; -@@ -392,8 +392,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess - private boolean updatingSectionStatus; - - @Override -- public final boolean moonrise$isHardColliding() { -- return this.isHardColliding; -+ public final HardColliding moonrise$hardCollisionConstant() { -+ return this.constantHardCollision; - } - - @Override diff --git a/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch b/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch index d2634384c2..2701d3e9a7 100644 --- a/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch +++ b/paper-server/patches/sources/ca/spottedleaf/moonrise/paper/PaperHooks.java.patch @@ -1,6 +1,6 @@ --- /dev/null +++ b/ca/spottedleaf/moonrise/paper/PaperHooks.java -@@ -1,0 +_,249 @@ +@@ -1,0 +_,250 @@ +package ca.spottedleaf.moonrise.paper; + +import ca.spottedleaf.moonrise.common.PlatformHooks; @@ -33,6 +33,8 @@ + +public final class PaperHooks extends BaseChunkSystemHooks implements PlatformHooks { + ++ private static final org.slf4j.Logger LOGGER = com.mojang.logging.LogUtils.getLogger(); ++ + @Override + public String getBrand() { + return "Paper"; @@ -239,10 +241,9 @@ + + @Override + public void postLoadProtoChunk(final ServerLevel world, final ProtoChunk chunk) { -+ net.minecraft.world.level.chunk.status.ChunkStatusTasks.postLoadProtoChunk( -+ world, -+ net.minecraft.world.level.storage.TagValueInput.create(net.minecraft.util.ProblemReporter.DISCARDING, world.registryAccess(), chunk.getEntities()) -+ ); ++ try (final net.minecraft.util.ProblemReporter.ScopedCollector scopedCollector = new net.minecraft.util.ProblemReporter.ScopedCollector(chunk.problemPath(), LOGGER)) { ++ net.minecraft.world.level.chunk.status.ChunkStatusTasks.postLoadProtoChunk(world, net.minecraft.world.level.storage.TagValueInput.create(scopedCollector, world.registryAccess(), chunk.getEntities())); ++ } + } + + @Override