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
This commit is contained in:
Spottedleaf 2024-12-01 13:43:37 -08:00
parent 86e20be366
commit 6788ba5e80

View File

@ -18347,11 +18347,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ public CollisionContext getDelegate() { + public CollisionContext getDelegate() {
+ this.delegated = true; + 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; + return this.delegate == null ? this.delegate = (entity == null ? CollisionContext.empty() : CollisionContext.of(entity)) : this.delegate;
+ } + }
+ +
+ @Override + @Override
+ public Entity getEntity() {
+ this.getDelegate();
+ return super.getEntity();
+ }
+
+ @Override
+ public boolean isDescending() { + public boolean isDescending() {
+ return this.getDelegate().isDescending(); + return this.getDelegate().isDescending();
+ } + }
@ -31088,9 +31094,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - optimise collisions + // Paper start - optimise collisions
+ if (this.cache != null) { + if (this.cache != null) {
+ final VoxelShape collisionShape = this.cache.collisionShape; + final VoxelShape collisionShape = this.cache.collisionShape;
+ try { + if (this.isAir()) {
+ this.constantCollisionShape = this.getCollisionShape(null, null, null); + this.constantCollisionShape = Shapes.empty();
+ } catch (final Throwable throwable) { + } else {
+ this.constantCollisionShape = null; + this.constantCollisionShape = null;
+ } + }
+ this.occludesFullBlock = ((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)collisionShape).moonrise$occludesFullBlock(); + this.occludesFullBlock = ((ca.spottedleaf.moonrise.patches.collisions.shape.CollisionVoxelShape)collisionShape).moonrise$occludesFullBlock();