From 6788ba5e80e70685d0753dd6d83e5d3554f2cc32 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Sun, 1 Dec 2024 13:43:37 -0800 Subject: [PATCH] Fix non-null initialisation of context collision shape Force LazyEntityCollisionContext#getEntity() to delegate - By delegating when the entity is retrieved, we can correctly catch cases where the collision method is inspecting some entity state. Adjust constant collision shape determination - Our previous hack did not actually catch every case. For now, it will only assume a constant collision shape of EMPTY for air blocks. Fixes https://github.com/PaperMC/Paper/issues/11697 --- patches/server/Moonrise-optimisation-patches.patch | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/patches/server/Moonrise-optimisation-patches.patch b/patches/server/Moonrise-optimisation-patches.patch index d80d876e60..deecdad6e9 100644 --- a/patches/server/Moonrise-optimisation-patches.patch +++ b/patches/server/Moonrise-optimisation-patches.patch @@ -18347,11 +18347,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + public CollisionContext getDelegate() { + this.delegated = true; -+ final Entity entity = this.getEntity(); ++ final Entity entity = super.getEntity(); + return this.delegate == null ? this.delegate = (entity == null ? CollisionContext.empty() : CollisionContext.of(entity)) : this.delegate; + } + + @Override ++ public Entity getEntity() { ++ this.getDelegate(); ++ return super.getEntity(); ++ } ++ ++ @Override + public boolean isDescending() { + return this.getDelegate().isDescending(); + } @@ -31088,9 +31094,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - optimise collisions + if (this.cache != null) { + final VoxelShape collisionShape = this.cache.collisionShape; -+ try { -+ this.constantCollisionShape = this.getCollisionShape(null, null, null); -+ } catch (final Throwable throwable) { ++ if (this.isAir()) { ++ this.constantCollisionShape = Shapes.empty(); ++ } else { + this.constantCollisionShape = null; + } + this.occludesFullBlock = ((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)collisionShape).moonrise$occludesFullBlock();