From c136222eebbf7a4c6809dcefa4df7ff08d1ce34c Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Tue, 3 Jun 2025 16:58:23 +0200 Subject: [PATCH] Moonrise compile fixes and changes Kept in separate patch for easier revert once leaf smites me. --- .../0015-Moonrise-optimisation-patches.patch | 24 +-- ...additions-for-dynamic-hard-collision.patch | 163 ++++++++++++++++++ 2 files changed, 175 insertions(+), 12 deletions(-) create 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 b53e5b647a..f308e4c430 100644 --- a/paper-server/patches/features/0015-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0015-Moonrise-optimisation-patches.patch @@ -1013,7 +1013,7 @@ index 0000000000000000000000000000000000000000..866f38eb0f379ffbe2888023a7d1c290 +} diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java b/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java new file mode 100644 -index 0000000000000000000000000000000000000000..f3f5a3f04283a130b4e48e6b78732758335629e7 +index 0000000000000000000000000000000000000000..02d596647ab78afb056eefe14ffa0ef2f27867f6 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/chunk_system/ChunkSystemConverters.java @@ -0,0 +1,38 @@ @@ -1034,7 +1034,7 @@ index 0000000000000000000000000000000000000000..f3f5a3f04283a130b4e48e6b78732758 + private static final int DEFAULT_ENTITY_CHUNK_DATA_VERSION = -1; + + private static int getCurrentVersion() { -+ return SharedConstants.getCurrentVersion().getDataVersion().getVersion(); ++ return SharedConstants.getCurrentVersion().dataVersion().version(); + } + + private static int getDataVersion(final CompoundTag data, final int dfl) { @@ -5309,7 +5309,7 @@ index 0000000000000000000000000000000000000000..89b956b8fdf1a0d862a843104511005e +} diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/poi/PoiChunk.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/poi/PoiChunk.java new file mode 100644 -index 0000000000000000000000000000000000000000..8b5eedee7b5876c0981520ec1548f70a935a501f +index 0000000000000000000000000000000000000000..5adbeecd61ab80fd86546f22f0867f27af5a7662 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/poi/PoiChunk.java @@ -0,0 +1,204 @@ @@ -5434,7 +5434,7 @@ index 0000000000000000000000000000000000000000..8b5eedee7b5876c0981520ec1548f70a + final CompoundTag sections = new CompoundTag(); + ret.put("Sections", sections); + -+ ret.putInt("DataVersion", SharedConstants.getCurrentVersion().getDataVersion().getVersion()); ++ ret.putInt("DataVersion", SharedConstants.getCurrentVersion().dataVersion().version()); + + final ServerLevel world = this.world; + final int chunkX = this.chunkX; @@ -5559,7 +5559,7 @@ index 0000000000000000000000000000000000000000..003a857e70ead858e8437e3c1bfaf22f +} diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java new file mode 100644 -index 0000000000000000000000000000000000000000..02a9ef1694c796584c29430d27f0a09047368835 +index 0000000000000000000000000000000000000000..f3bac0906d8a1c5dea7b0dee13c5cd6fdbbcae49 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java @@ -0,0 +1,1089 @@ @@ -5712,7 +5712,7 @@ index 0000000000000000000000000000000000000000..02a9ef1694c796584c29430d27f0a090 + } + + public static int getAPITickViewDistance(final ServerPlayer player) { -+ final ServerLevel level = player.serverLevel(); ++ final ServerLevel level = player.level(); + final PlayerChunkLoaderData data = ((ChunkSystemServerPlayer)player).moonrise$getChunkLoader(); + if (data == null) { + return ((ChunkSystemServerLevel)level).moonrise$getPlayerChunkLoader().getAPITickDistance(); @@ -5721,7 +5721,7 @@ index 0000000000000000000000000000000000000000..02a9ef1694c796584c29430d27f0a090 + } + + public static int getAPIViewDistance(final ServerPlayer player) { -+ final ServerLevel level = player.serverLevel(); ++ final ServerLevel level = player.level(); + final PlayerChunkLoaderData data = ((ChunkSystemServerPlayer)player).moonrise$getChunkLoader(); + if (data == null) { + return ((ChunkSystemServerLevel)level).moonrise$getPlayerChunkLoader().getAPIViewDistance(); @@ -5731,7 +5731,7 @@ index 0000000000000000000000000000000000000000..02a9ef1694c796584c29430d27f0a090 + } + + public static int getAPISendViewDistance(final ServerPlayer player) { -+ final ServerLevel level = player.serverLevel(); ++ final ServerLevel level = player.level(); + final PlayerChunkLoaderData data = ((ChunkSystemServerPlayer)player).moonrise$getChunkLoader(); + if (data == null) { + return ((ChunkSystemServerLevel)level).moonrise$getPlayerChunkLoader().getAPISendViewDistance(); @@ -16359,7 +16359,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..a97a2a8492f3858e3b622d26768b4d819c9b47a7 +index 0000000000000000000000000000000000000000..9f8fb5d96d7a9776a5b809c4bd474b404b452145 --- /dev/null +++ b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java @@ -0,0 +1,2185 @@ @@ -18456,7 +18456,7 @@ index 0000000000000000000000000000000000000000..a97a2a8492f3858e3b622d26768b4d81 + continue; + } + -+ if ((entity == null && otherEntity.canBeCollidedWith()) || (entity != null && entity.canCollideWith(otherEntity))) { ++ if ((entity == null && otherEntity.canBeCollidedWith(null)) || (entity != null && entity.canCollideWith(otherEntity))) { + if (checkOnly) { + return true; + } else { @@ -29623,7 +29623,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..892a7c1eb1b321ca6d5ca709142e7feae1220815 100644 +index 300f3ed58109219d97846082941b860585f66fed..67f47982e238430b7adaa93f5e730b5e87eac741 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 +29735,7 @@ index 300f3ed58109219d97846082941b860585f66fed..892a7c1eb1b321ca6d5ca709142e7fea + continue; + } + -+ if ((entity == null && otherEntity.canBeCollidedWith()) || (entity != null && entity.canCollideWith(otherEntity))) { ++ if ((entity == null && otherEntity.canBeCollidedWith(null)) || (entity != null && entity.canCollideWith(otherEntity))) { + ret.add(Shapes.create(otherEntity.getBoundingBox())); } } 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 new file mode 100644 index 0000000000..fc0b53c47a --- /dev/null +++ b/paper-server/patches/features/0030-Moonrise-additions-for-dynamic-hard-collision.patch @@ -0,0 +1,163 @@ +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