|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Mon, 2 Sep 2024 22:11:46 +0100 |
| 4 | +Subject: [PATCH] Allow projectiles to load chunks for collisions |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java |
| 8 | +index e8faca6e443239968f0111519f9e5cd018ed3297..36b645842a65dd017b6a8d1d12b751dd01ddfde0 100644 |
| 9 | +--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java |
| 10 | ++++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java |
| 11 | +@@ -213,7 +213,7 @@ public abstract class AbstractArrow extends Projectile { |
| 12 | + Vec3 vec3d2 = this.position(); |
| 13 | + |
| 14 | + vec3d1 = vec3d2.add(vec3d); |
| 15 | +- Object object = this.level().clip(new ClipContext(vec3d2, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)); |
| 16 | ++ Object object = this.level().clip(new ClipContext(vec3d2, vec3d1, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this), this.level().sakuraConfig().entity.projectilesLoadChunksForCollisions); // Sakura - allow projectiles to load chunks for collisions |
| 17 | + |
| 18 | + if (((HitResult) object).getType() != HitResult.Type.MISS) { |
| 19 | + vec3d1 = ((HitResult) object).getLocation(); |
| 20 | +diff --git a/src/main/java/net/minecraft/world/entity/projectile/ProjectileUtil.java b/src/main/java/net/minecraft/world/entity/projectile/ProjectileUtil.java |
| 21 | +index 3ab65cb7d891ddba011afd795dbf699f37cb8a17..451ccf4b02c7f43a81d5735d73cd923a155353fd 100644 |
| 22 | +--- a/src/main/java/net/minecraft/world/entity/projectile/ProjectileUtil.java |
| 23 | ++++ b/src/main/java/net/minecraft/world/entity/projectile/ProjectileUtil.java |
| 24 | +@@ -46,7 +46,7 @@ public final class ProjectileUtil { |
| 25 | + Vec3 pos, Entity entity, Predicate<Entity> predicate, Vec3 velocity, Level world, float margin, ClipContext.Block raycastShapeType |
| 26 | + ) { |
| 27 | + Vec3 vec3 = pos.add(velocity); |
| 28 | +- HitResult hitResult = world.clip(new ClipContext(pos, vec3, raycastShapeType, ClipContext.Fluid.NONE, entity)); |
| 29 | ++ HitResult hitResult = world.clip(new ClipContext(pos, vec3, raycastShapeType, ClipContext.Fluid.NONE, entity), world.sakuraConfig().entity.projectilesLoadChunksForCollisions); // Sakura - allow projectiles to load chunks for collisions |
| 30 | + if (hitResult.getType() != HitResult.Type.MISS) { |
| 31 | + vec3 = hitResult.getLocation(); |
| 32 | + } |
| 33 | +diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java |
| 34 | +index c2c0d80adb6fa8cb74fa5fe3ce5bc7ac0609abba..42d7a96c176368fdfcd433cba564ad18b451ff35 100644 |
| 35 | +--- a/src/main/java/net/minecraft/world/level/Level.java |
| 36 | ++++ b/src/main/java/net/minecraft/world/level/Level.java |
| 37 | +@@ -639,8 +639,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable { |
| 38 | + |
| 39 | + private static final FluidState AIR_FLUIDSTATE = Fluids.EMPTY.defaultFluidState(); |
| 40 | + |
| 41 | ++ // Sakura start - allow projectiles to load chunks for collisions |
| 42 | + private static net.minecraft.world.phys.BlockHitResult fastClip(final Vec3 from, final Vec3 to, final Level level, |
| 43 | + final ClipContext clipContext) { |
| 44 | ++ return fastClip(from, to, level, clipContext, false); |
| 45 | ++ } |
| 46 | ++ private static net.minecraft.world.phys.BlockHitResult fastClip(final Vec3 from, final Vec3 to, final Level level, |
| 47 | ++ final ClipContext clipContext, final boolean loadChunks) { |
| 48 | ++ // Sakura end - allow projectiles to load chunks for collisions |
| 49 | + final double adjX = io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON * (from.x - to.x); |
| 50 | + final double adjY = io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON * (from.y - to.y); |
| 51 | + final double adjZ = io.papermc.paper.util.CollisionUtil.COLLISION_EPSILON * (from.z - to.z); |
| 52 | +@@ -703,7 +709,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { |
| 53 | + |
| 54 | + if ((chunkDiff | chunkYDiff) != 0) { |
| 55 | + if (chunkDiff != 0) { |
| 56 | +- LevelChunk chunk = chunkProvider.getChunkAtIfLoadedImmediately(newChunkX, newChunkZ); |
| 57 | ++ LevelChunk chunk = loadChunks ? level.getChunk(newChunkX, newChunkZ) : chunkProvider.getChunkAtIfLoadedImmediately(newChunkX, newChunkZ); // Sakura - allow projectiles to load chunks for collisions |
| 58 | + lastChunk = chunk == null ? null : chunk.getSections(); // diff: don't load chunks for this |
| 59 | + } |
| 60 | + final int sectionY = newChunkY - minSection; |
| 61 | +@@ -774,6 +780,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable { |
| 62 | + return fastClip(clipContext.getFrom(), clipContext.getTo(), this, clipContext); |
| 63 | + } |
| 64 | + |
| 65 | ++ // Sakura start - allow projectiles to load chunks for collisions |
| 66 | ++ public final net.minecraft.world.phys.BlockHitResult clip(final ClipContext clipContext, final boolean loadChunks) { |
| 67 | ++ return fastClip(clipContext.getFrom(), clipContext.getTo(), this, clipContext, loadChunks); |
| 68 | ++ } |
| 69 | ++ // Sakura end - allow projectiles to load chunks for collisions |
| 70 | ++ |
| 71 | + @Override |
| 72 | + public final boolean noCollision(final Entity entity, final AABB box, final boolean loadChunks) { |
| 73 | + int flags = io.papermc.paper.util.CollisionUtil.COLLISION_FLAG_CHECK_ONLY; |
0 commit comments