Skip to content

Commit b9dd524

Browse files
committed
Allow projectiles to load chunks for collisions
1 parent eed499d commit b9dd524

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

patches/server/0003-Sakura-Configuration-Files.patch

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,10 @@ index 0000000000000000000000000000000000000000..dd5a70f70c2e7bdc30b8f5655b0b7a08
647647
+}
648648
diff --git a/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
649649
new file mode 100644
650-
index 0000000000000000000000000000000000000000..5c639ca9f4e61bba31b4174f2501a313727fba4f
650+
index 0000000000000000000000000000000000000000..99f243d8620056739470b5bf53b8c8076eef98fb
651651
--- /dev/null
652652
+++ b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
653-
@@ -0,0 +1,230 @@
653+
@@ -0,0 +1,236 @@
654654
+package me.samsuik.sakura.configuration;
655655
+
656656
+import com.mojang.logging.LogUtils;
@@ -855,6 +855,12 @@ index 0000000000000000000000000000000000000000..5c639ca9f4e61bba31b4174f2501a313
855855
+ public class EnderPearl extends ConfigurationPart {
856856
+ public boolean useOutlineForCollision = false;
857857
+ }
858+
+
859+
+ @Comment(
860+
+ "Allows projectiles to load chunks for collisions\n" +
861+
+ "This restores vanilla chunk loading behaviour"
862+
+ )
863+
+ public boolean projectilesLoadChunksForCollisions = false;
858864
+ }
859865
+
860866
+ public Environment environment;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Samsuik <[email protected]>
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

Comments
 (0)