Update Optimise collision checking in player move packet handling

Dieser Commit ist enthalten in:
Jason Penilla 2021-12-05 02:56:09 -08:00
Ursprung 78faaa4f8e
Commit c3ff7e0ff7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0E75A301420E48F8

Datei anzeigen

@ -6,10 +6,10 @@ Subject: [PATCH] Optimise collision checking in player move packet handling
Move collision logic to just the hasNewCollision call instead of getCubes + hasNewCollision
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656c6b02beb 100644
index f4f075c678f30d375d15041860fcc5543eedc7fe..eb7ac0b2a774dc7348eb2a94cc6c61792b47dd1d 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -582,12 +582,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -581,12 +581,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
return;
}
@ -24,7 +24,7 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
double d11 = d7;
d6 = d3 - entity.getX();
@@ -601,16 +602,23 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -600,16 +601,23 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
boolean flag1 = false;
if (d10 > org.spigotmc.SpigotConfig.movedWronglyThreshold) { // Spigot
@ -52,7 +52,7 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
entity.absMoveTo(d0, d1, d2, f, f1);
this.player.absMoveTo(d0, d1, d2, this.player.getYRot(), this.player.getXRot()); // CraftBukkit
this.connection.send(new ClientboundMoveVehiclePacket(entity));
@@ -696,7 +704,32 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -695,7 +703,32 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
private boolean noBlocksAround(Entity entity) {
@ -86,7 +86,7 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
}
@Override
@@ -1233,7 +1266,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1237,7 +1270,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
if (this.awaitingPositionFromClient != null) {
@ -95,7 +95,7 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
}
@@ -1327,7 +1360,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1331,7 +1364,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
}
@ -104,15 +104,15 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
d7 = d0 - this.lastGoodX; // Paper - diff on change, used for checking large move vectors above
d8 = d1 - this.lastGoodY; // Paper - diff on change, used for checking large move vectors above
@@ -1366,6 +1399,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1370,6 +1403,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
this.player.move(MoverType.PLAYER, new Vec3(d7, d8, d9));
+ boolean didCollide = toX != this.player.getX() || toY != this.player.getY() || toZ != this.player.getZ(); // Paper - needed here as the difference in Y can be reset - also note: this is only a guess at whether collisions took place, floating point errors can make this true when it shouldn't be...
this.player.setOnGround(packet.isOnGround()); // CraftBukkit - SPIGOT-5810, SPIGOT-5835: reset by this.player.move
this.player.onGround = packet.isOnGround(); // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move
// Paper start - prevent position desync
if (this.awaitingPositionFromClient != null) {
@@ -1385,12 +1419,23 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1389,12 +1423,23 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
boolean flag1 = false;
if (!this.player.isChangingDimension() && d11 > org.spigotmc.SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.gameMode.isCreative() && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR) { // Spigot
@ -122,7 +122,7 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
}
this.player.absMoveTo(d0, d1, d2, f, f1);
- if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew((LevelReader) worldserver, axisalignedbb))) {
- if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) {
+ // Paper start - optimise out extra getCubes
+ // Original for reference:
+ // boolean teleportBack = flag1 && worldserver.getCubes(this.player, axisalignedbb) || (didCollide && this.a((IWorldReader) worldserver, axisalignedbb));
@ -138,7 +138,7 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
this.teleport(d3, d4, d5, f, f1);
} else {
// CraftBukkit start - fire PlayerMoveEvent
@@ -1477,6 +1522,27 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1481,6 +1526,27 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
}
}
@ -164,5 +164,5 @@ index efa7c4b1e8c2e4297f89eb62aab76c43d2947e16..5d7c47b0a302f7db95a0b2bb811c5656
+ // Paper end - optimise out extra getCubes
+
private boolean isPlayerCollidingWithAnythingNew(LevelReader world, AABB box) {
Stream<VoxelShape> stream = world.getCollisions(this.player, this.player.getBoundingBox().deflate(9.999999747378752E-6D), (entity) -> {
return true;
Iterable<VoxelShape> iterable = world.getCollisions(this.player, this.player.getBoundingBox().deflate(9.999999747378752E-6D));
VoxelShape voxelshape = Shapes.create(box.deflate(9.999999747378752E-6D));