2020-05-09 19:47:08 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 2 Apr 2020 02:37:57 -0400
|
|
|
|
Subject: [PATCH] Optimize Collision to not load chunks
|
|
|
|
|
|
|
|
The collision code takes an AABB and generates a cuboid of checks rather
|
|
|
|
than a cylinder, so at high velocity this can generate a lot of chunk checks.
|
|
|
|
|
|
|
|
Treat an unloaded chunk as a collision for entities, and also for players if
|
|
|
|
the "prevent moving into unloaded chunks" setting is enabled.
|
|
|
|
|
|
|
|
If that serting is not enabled, collisions will be ignored for players, since
|
|
|
|
movement will load only the chunk the player enters anyways and avoids loading
|
|
|
|
massive amounts of surrounding chunks due to large AABB lookups.
|
|
|
|
|
2020-05-14 08:58:47 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
index 7434f859f7f9acff0f881ff594c8dffdfa249c76..7fb34a86dc35cb4bf51e1ce5220e56642096fece 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
@@ -80,6 +80,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
|
|
private CraftEntity bukkitEntity;
|
|
|
|
|
|
|
|
PlayerChunkMap.EntityTracker tracker; // Paper
|
|
|
|
+ boolean collisionLoadChunks = false; // Paper
|
|
|
|
Throwable addedToWorldStack; // Paper - entity debug
|
|
|
|
public CraftEntity getBukkitEntity() {
|
|
|
|
if (bukkitEntity == null) {
|
2020-05-09 19:47:08 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ICollisionAccess.java b/src/main/java/net/minecraft/server/ICollisionAccess.java
|
2020-06-20 09:22:09 +00:00
|
|
|
index f851ed11df14fd9aa8017f44d82fb6cfc3bde345..3eefbf4d5f10b53f930759a0afa5661253b92c60 100644
|
2020-05-09 19:47:08 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ICollisionAccess.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ICollisionAccess.java
|
2020-06-20 09:22:09 +00:00
|
|
|
@@ -43,7 +43,9 @@ public interface ICollisionAccess extends IBlockAccess {
|
2020-05-14 08:58:47 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 09:22:09 +00:00
|
|
|
default boolean a(@Nullable Entity entity, AxisAlignedBB axisalignedbb, Set<Entity> set) {
|
|
|
|
+ try { if (entity != null) entity.collisionLoadChunks = true; // Paper
|
|
|
|
return this.c(entity, axisalignedbb, set).allMatch(VoxelShape::isEmpty);
|
|
|
|
+ } finally { if (entity != null) entity.collisionLoadChunks = false; } // Paper
|
2020-05-14 08:58:47 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 09:22:09 +00:00
|
|
|
default Stream<VoxelShape> b(@Nullable Entity entity, AxisAlignedBB axisalignedbb, Set<Entity> set) {
|
|
|
|
@@ -83,19 +85,33 @@ public interface ICollisionAccess extends IBlockAccess {
|
2020-05-09 19:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (cursorposition.a()) {
|
|
|
|
- int k1 = cursorposition.b();
|
|
|
|
- int l1 = cursorposition.c();
|
|
|
|
- int i2 = cursorposition.d();
|
|
|
|
+ int k1 = cursorposition.b();int x = k1; // Paper
|
|
|
|
+ int l1 = cursorposition.c();int y = l1; // Paper
|
|
|
|
+ int i2 = cursorposition.d();int z = i2; // Paper
|
|
|
|
int j2 = cursorposition.e();
|
|
|
|
|
|
|
|
if (j2 != 3) {
|
2020-05-10 09:36:35 +00:00
|
|
|
- int k2 = k1 >> 4;
|
|
|
|
- int l2 = i2 >> 4;
|
2020-05-09 19:47:08 +00:00
|
|
|
- IBlockAccess iblockaccess = ICollisionAccess.this.c(k2, l2);
|
|
|
|
-
|
|
|
|
- if (iblockaccess != null) {
|
|
|
|
- blockposition_mutableblockposition.d(k1, l1, i2);
|
|
|
|
- IBlockData iblockdata = iblockaccess.getType(blockposition_mutableblockposition);
|
2020-05-10 09:36:35 +00:00
|
|
|
+ // Paper start - ensure we don't load chunks
|
|
|
|
+ //int k2 = k1 >> 4;
|
|
|
|
+ //int l2 = i2 >> 4;
|
2020-05-11 02:49:58 +00:00
|
|
|
+ boolean far = entity != null && MCUtil.distanceSq(entity.locX(), y, entity.locZ(), x, y, z) > 14;
|
2020-05-10 06:26:21 +00:00
|
|
|
+ blockposition_mutableblockposition.setValues(x, y, z);
|
2020-05-09 23:18:26 +00:00
|
|
|
+
|
2020-05-10 06:26:21 +00:00
|
|
|
+ boolean isRegionLimited = ICollisionAccess.this instanceof RegionLimitedWorldAccess;
|
2020-05-14 08:58:47 +00:00
|
|
|
+ IBlockData iblockdata = isRegionLimited ? Blocks.VOID_AIR.getBlockData() : ((!far && entity instanceof EntityPlayer) || (entity != null && entity.collisionLoadChunks)
|
2020-05-10 09:36:35 +00:00
|
|
|
+ ? ICollisionAccess.this.getType(blockposition_mutableblockposition)
|
|
|
|
+ : ICollisionAccess.this.getTypeIfLoaded(blockposition_mutableblockposition)
|
|
|
|
+ );
|
2020-05-09 19:47:08 +00:00
|
|
|
+ if (iblockdata == null) {
|
|
|
|
+ if (!(entity instanceof EntityPlayer) || entity.world.paperConfig.preventMovingIntoUnloadedChunks) {
|
2020-05-09 23:18:26 +00:00
|
|
|
+ VoxelShape voxelshape3 = VoxelShapes.of(far ? entity.getBoundingBox() : new AxisAlignedBB(new BlockPosition(x, y, z)));
|
2020-05-09 19:47:08 +00:00
|
|
|
+ consumer.accept(voxelshape3);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //blockposition_mutableblockposition.d(k1, l1, i2); // moved up
|
|
|
|
+ //IBlockData iblockdata = iblockaccess.getType(blockposition_mutableblockposition); // moved up
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
if ((j2 != 1 || iblockdata.f()) && (j2 != 2 || iblockdata.getBlock() == Blocks.MOVING_PISTON)) {
|
|
|
|
VoxelShape voxelshape2 = iblockdata.b((IBlockAccess) ICollisionAccess.this, blockposition_mutableblockposition, voxelshapecollision);
|
2020-05-10 01:13:30 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-06-20 09:22:09 +00:00
|
|
|
index 0ba103a5c60d8f5b8f332fe63364c597925a6450..157738f452493aabdefb228cd527ba85400baad5 100644
|
2020-05-10 01:13:30 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
@@ -677,6 +677,7 @@ public abstract class PlayerList {
|
|
|
|
entityplayer1.forceSetPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2020-05-11 03:58:04 +00:00
|
|
|
+ worldserver.getChunkProvider().addTicket(TicketType.POST_TELEPORT, new ChunkCoordIntPair(location.getBlockX() >> 4, location.getBlockZ() >> 4), 1, entityplayer.getId()); // Paper
|
2020-05-10 01:13:30 +00:00
|
|
|
while (avoidSuffocation && !worldserver.getCubes(entityplayer1) && entityplayer1.locY() < 256.0D) {
|
|
|
|
entityplayer1.setPosition(entityplayer1.locX(), entityplayer1.locY() + 1.0D, entityplayer1.locZ());
|
|
|
|
}
|
2020-05-09 19:47:08 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/VoxelShapes.java b/src/main/java/net/minecraft/server/VoxelShapes.java
|
2020-04-22 15:11:50 +00:00
|
|
|
index 335142ec0dfad822cfe40877e99dec0f307e1a58..e641d4b8d8b4ac5d539e6d9c0eaf345601e0b499 100644
|
2020-05-09 19:47:08 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/VoxelShapes.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/VoxelShapes.java
|
2020-04-22 15:11:50 +00:00
|
|
|
@@ -239,7 +239,8 @@ public final class VoxelShapes {
|
2020-05-09 19:47:08 +00:00
|
|
|
|
|
|
|
if (k2 < 3) {
|
|
|
|
blockposition_mutableblockposition.a(enumaxiscycle1, i2, j2, l1);
|
|
|
|
- IBlockData iblockdata = iworldreader.getType(blockposition_mutableblockposition);
|
|
|
|
+ IBlockData iblockdata = iworldreader.getTypeIfLoaded(blockposition_mutableblockposition); // Paper
|
|
|
|
+ if (iblockdata == null) return 0.0D; // Paper
|
|
|
|
|
|
|
|
if ((k2 != 1 || iblockdata.f()) && (k2 != 2 || iblockdata.getBlock() == Blocks.MOVING_PISTON)) {
|
|
|
|
d0 = iblockdata.b((IBlockAccess) iworldreader, blockposition_mutableblockposition, voxelshapecollision).a(enumdirection_enumaxis2, axisalignedbb.d((double) (-blockposition_mutableblockposition.getX()), (double) (-blockposition_mutableblockposition.getY()), (double) (-blockposition_mutableblockposition.getZ())), d0);
|