mirror of
https://github.com/GeyserMC/Geyser.git
synced 2026-01-04 15:31:36 +00:00
Refactor: Movement collision system (#5779)
* Initial work on fixing the collision system. * More work. * Clean this up. * Oops. * More work. * Added comment. * Start fixing other collisions. * Properly fix trapdoor collision. * Properly fix door collision. * Fixed glass pane/iron bars collision. * Fixed comment. * Removed debug print. * Cleanup the code. * Revert some dumb changes. * Move player position down when standing on chest. * Also state that this resolve #4955. * Requested changes. * Update core/src/main/java/org/geysermc/geyser/session/GeyserSession.java Co-authored-by: chris <github@onechris.mozmail.com> * Update core/src/main/java/org/geysermc/geyser/session/GeyserSession.java Co-authored-by: chris <github@onechris.mozmail.com> * Added a TODO to remove collision expansion if not needed. --------- Co-authored-by: chris <github@onechris.mozmail.com>
This commit is contained in:
@@ -117,6 +117,12 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
@Getter @Setter
|
||||
private Vector2f bedrockInteractRotation = Vector2f.ZERO;
|
||||
|
||||
/**
|
||||
* If the player is colliding on the vertical axis or not according to the client.
|
||||
*/
|
||||
@Getter @Setter
|
||||
private boolean collidingVertically;
|
||||
|
||||
@Getter @Setter
|
||||
private float javaYaw;
|
||||
|
||||
|
||||
@@ -142,6 +142,47 @@ public class BoundingBox implements Cloneable {
|
||||
};
|
||||
}
|
||||
|
||||
public void pushOutOfBoundingBox(BoundingBox playerBox, Direction direction, double maxPushTolerance) {
|
||||
switch (direction) {
|
||||
case NORTH -> {
|
||||
double distance = this.getMin(Axis.Z) - playerBox.getMax(Axis.Z);
|
||||
if (Math.abs(distance) < maxPushTolerance) {
|
||||
playerBox.translate(0, 0, distance);
|
||||
}
|
||||
}
|
||||
case SOUTH -> {
|
||||
double distance = this.getMax(Axis.Z) - playerBox.getMin(Axis.Z);
|
||||
if (Math.abs(distance) < maxPushTolerance) {
|
||||
playerBox.translate(0, 0, distance);
|
||||
}
|
||||
}
|
||||
case EAST -> {
|
||||
double distance = this.getMax(Axis.X) - playerBox.getMin(Axis.X);
|
||||
if (Math.abs(distance) < maxPushTolerance) {
|
||||
playerBox.translate(distance, 0, 0);
|
||||
}
|
||||
}
|
||||
case WEST -> {
|
||||
double distance = this.getMin(Axis.X) - playerBox.getMax(Axis.X);
|
||||
if (Math.abs(distance) < maxPushTolerance) {
|
||||
playerBox.translate(distance, 0, 0);
|
||||
}
|
||||
}
|
||||
case UP -> {
|
||||
double distance = this.getMax(Axis.Y) - playerBox.getMin(Axis.Y);
|
||||
if (Math.abs(distance) < maxPushTolerance) {
|
||||
playerBox.translate(0, distance, 0);
|
||||
}
|
||||
}
|
||||
case DOWN -> {
|
||||
double distance = this.getMin(Axis.Y) - playerBox.getMax(Axis.Y);
|
||||
if (Math.abs(distance) < maxPushTolerance) {
|
||||
playerBox.translate(0, distance, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the maximum offset of another bounding box in an axis that will not collide with this bounding box
|
||||
*
|
||||
|
||||
@@ -186,11 +186,8 @@ public class CollisionManager {
|
||||
playerBoundingBox.translate(adjustedMovement.getX(), adjustedMovement.getY(), adjustedMovement.getZ());
|
||||
playerBoundingBox.translate(pistonCache.getPlayerMotion().getX(), pistonCache.getPlayerMotion().getY(), pistonCache.getPlayerMotion().getZ());
|
||||
// Correct player position
|
||||
if (!correctPlayerPosition()) {
|
||||
// Cancel the movement if it needs to be cancelled
|
||||
recalculatePosition();
|
||||
return null;
|
||||
}
|
||||
correctPlayerPosition();
|
||||
|
||||
// The server can't complain about our movement if we never send it
|
||||
// TODO get rid of this and handle teleports smoothly
|
||||
if (pistonCache.isPlayerCollided()) {
|
||||
@@ -255,12 +252,10 @@ public class CollisionManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if the movement is invalid, and in this case it shouldn't be sent to the server and should be
|
||||
* cancelled
|
||||
* Silently compensate for movement problems due to collision and floating points errors on bedrock.
|
||||
* See {@link BlockCollision#correctPosition(GeyserSession, int, int, int, BoundingBox)} for more info
|
||||
*/
|
||||
public boolean correctPlayerPosition() {
|
||||
|
||||
public void correctPlayerPosition() {
|
||||
// These may be set to true by the correctPosition method in ScaffoldingCollision
|
||||
touchingScaffolding = false;
|
||||
onScaffolding = false;
|
||||
@@ -268,12 +263,6 @@ public class CollisionManager {
|
||||
// Used when correction code needs to be run before the main correction
|
||||
BlockPositionIterator iter = session.getCollisionManager().playerCollidableBlocksIterator();
|
||||
int[] blocks = session.getGeyser().getWorldManager().getBlocksAt(session, iter);
|
||||
for (iter.reset(); iter.hasNext(); iter.next()) {
|
||||
BlockCollision blockCollision = BlockUtils.getCollision(blocks[iter.getIteration()]);
|
||||
if (blockCollision != null) {
|
||||
blockCollision.beforeCorrectPosition(iter.getX(), iter.getY(), iter.getZ(), playerBoundingBox);
|
||||
}
|
||||
}
|
||||
|
||||
// Main correction code
|
||||
for (iter.reset(); iter.hasNext(); iter.next()) {
|
||||
@@ -287,15 +276,11 @@ public class CollisionManager {
|
||||
|
||||
BlockCollision blockCollision = BlockUtils.getCollision(blockId);
|
||||
if (blockCollision != null) {
|
||||
if (!blockCollision.correctPosition(session, iter.getX(), iter.getY(), iter.getZ(), playerBoundingBox)) {
|
||||
return false;
|
||||
}
|
||||
blockCollision.correctPosition(session, iter.getX(), iter.getY(), iter.getZ(), playerBoundingBox);
|
||||
}
|
||||
}
|
||||
|
||||
updateScaffoldingFlags(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Vector3d correctPlayerMovement(Vector3d movement, boolean checkWorld, boolean teleported) {
|
||||
|
||||
@@ -27,11 +27,11 @@ package org.geysermc.geyser.translator.collision;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
import org.geysermc.geyser.level.physics.Axis;
|
||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
import org.geysermc.geyser.level.physics.Direction;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
@EqualsAndHashCode
|
||||
@@ -40,17 +40,6 @@ public class BlockCollision {
|
||||
@Getter
|
||||
protected final BoundingBox[] boundingBoxes;
|
||||
|
||||
/**
|
||||
* This is used for the step up logic.
|
||||
* Usually, the player can only step up a block if they are on the same Y level as its bottom face or higher
|
||||
* For snow layers, due to its beforeCorrectPosition method the player can be slightly below (0.125 blocks) and
|
||||
* still need to step up
|
||||
* This used to be 0 but for now this has been set to 1 as it fixes bed collision
|
||||
* I didn't just set it for beds because other collision may also be slightly raised off the ground.
|
||||
* If this causes any problems, change this back to 0 and add an exception for beds.
|
||||
*/
|
||||
protected double pushUpTolerance = 1;
|
||||
|
||||
/**
|
||||
* This is used to control the maximum distance a face of a bounding box can push the player away
|
||||
*/
|
||||
@@ -61,87 +50,41 @@ public class BlockCollision {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden in classes like GrassPathCollision when correction code needs to be run before the
|
||||
* main correction
|
||||
* Silently move player bounding box/position out of block when needed to.
|
||||
*/
|
||||
public void beforeCorrectPosition(int x, int y, int z, BoundingBox playerCollision) {}
|
||||
public void correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
final double collisionExpansion = CollisionManager.COLLISION_TOLERANCE * 2;
|
||||
// Make player collision slightly bigger to pick up on blocks that could cause problems with Passable
|
||||
// TODO: Is this still needed? This should be removed if it's not needed anymore.
|
||||
playerCollision.expand(collisionExpansion);
|
||||
|
||||
/**
|
||||
* Returns false if the movement is invalid, and in this case it shouldn't be sent to the server and should be
|
||||
* cancelled
|
||||
* While the Java server should do this, it could result in false flags by anticheat
|
||||
* This functionality is currently only used in 6 or 7 layer snow
|
||||
*/
|
||||
public boolean correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
double playerMinY = playerCollision.getMiddleY() - (playerCollision.getSizeY() / 2);
|
||||
for (BoundingBox b : this.boundingBoxes) {
|
||||
double boxMinY = (b.getMiddleY() + y) - (b.getSizeY() / 2);
|
||||
double boxMaxY = (b.getMiddleY() + y) + (b.getSizeY() / 2);
|
||||
if (b.checkIntersection(x, y, z, playerCollision) && (playerMinY + pushUpTolerance) >= boxMinY) {
|
||||
// Max steppable distance in Minecraft as far as we know is 0.5625 blocks (for beds)
|
||||
if (boxMaxY - playerMinY <= 0.5625) {
|
||||
playerCollision.translate(0, boxMaxY - playerMinY, 0);
|
||||
// Update player Y for next collision box
|
||||
playerMinY = playerCollision.getMiddleY() - (playerCollision.getSizeY() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Make player collision slightly bigger to pick up on blocks that could cause problems with Passable
|
||||
playerCollision.setSizeX(playerCollision.getSizeX() + CollisionManager.COLLISION_TOLERANCE * 2);
|
||||
playerCollision.setSizeZ(playerCollision.getSizeZ() + CollisionManager.COLLISION_TOLERANCE * 2);
|
||||
|
||||
// If the player still intersects the block, then push them out
|
||||
// This fixes NoCheatPlus's Passable check
|
||||
// This check doesn't allow players right up against the block, so they must be pushed slightly away
|
||||
if (b.checkIntersection(x, y, z, playerCollision)) {
|
||||
Vector3d relativePlayerPosition = Vector3d.from(playerCollision.getMiddleX() - x,
|
||||
playerCollision.getMiddleY() - y,
|
||||
playerCollision.getMiddleZ() - z);
|
||||
|
||||
// The ULP should give an upper bound on the floating point error
|
||||
double xULP = Math.ulp((float) Math.max(Math.abs(playerCollision.getMiddleX()) + playerCollision.getSizeX() / 2.0, Math.abs(x) + 1));
|
||||
double zULP = Math.ulp((float) Math.max(Math.abs(playerCollision.getMiddleZ()) + playerCollision.getSizeZ() / 2.0, Math.abs(z) + 1));
|
||||
|
||||
double xPushAwayTolerance = Math.max(pushAwayTolerance, xULP);
|
||||
double zPushAwayTolerance = Math.max(pushAwayTolerance, zULP);
|
||||
|
||||
double northFaceZPos = b.getMiddleZ() - (b.getSizeZ() / 2);
|
||||
double translateDistance = northFaceZPos - relativePlayerPosition.getZ() - (playerCollision.getSizeZ() / 2);
|
||||
if (Math.abs(translateDistance) < zPushAwayTolerance) {
|
||||
playerCollision.translate(0, 0, translateDistance);
|
||||
}
|
||||
|
||||
double southFaceZPos = b.getMiddleZ() + (b.getSizeZ() / 2);
|
||||
translateDistance = southFaceZPos - relativePlayerPosition.getZ() + (playerCollision.getSizeZ() / 2);
|
||||
if (Math.abs(translateDistance) < zPushAwayTolerance) {
|
||||
playerCollision.translate(0, 0, translateDistance);
|
||||
}
|
||||
|
||||
double eastFaceXPos = b.getMiddleX() + (b.getSizeX() / 2);
|
||||
translateDistance = eastFaceXPos - relativePlayerPosition.getX() + (playerCollision.getSizeX() / 2);
|
||||
if (Math.abs(translateDistance) < xPushAwayTolerance) {
|
||||
playerCollision.translate(translateDistance, 0, 0);
|
||||
}
|
||||
|
||||
double westFaceXPos = b.getMiddleX() - (b.getSizeX() / 2);
|
||||
translateDistance = westFaceXPos - relativePlayerPosition.getX() - (playerCollision.getSizeX() / 2);
|
||||
if (Math.abs(translateDistance) < xPushAwayTolerance) {
|
||||
playerCollision.translate(translateDistance, 0, 0);
|
||||
}
|
||||
|
||||
double bottomFaceYPos = b.getMiddleY() - (b.getSizeY() / 2);
|
||||
translateDistance = bottomFaceYPos - relativePlayerPosition.getY() - (playerCollision.getSizeY() / 2);
|
||||
if (Math.abs(translateDistance) < pushAwayTolerance) {
|
||||
playerCollision.translate(0, translateDistance, 0);
|
||||
}
|
||||
// Due to floating points errors, or possibly how collision is handled on Bedrock, player could be slightly clipping into the block.
|
||||
// So we check if the player is intersecting the block, if they do then push them out. This fixes NoCheatPlus's Passable check and other anticheat checks.
|
||||
// This check doesn't allow players right up against the block, so they must be pushed slightly away. However, we should only do it if the
|
||||
// push distance is smaller than "pushAwayTolerance", we don't want to push player out when they're actually inside a block.
|
||||
for (BoundingBox boundingBox : this.boundingBoxes) {
|
||||
if (!boundingBox.checkIntersection(x, y, z, playerCollision)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set the collision size back to normal
|
||||
playerCollision.setSizeX(0.6);
|
||||
playerCollision.setSizeZ(0.6);
|
||||
boundingBox = boundingBox.clone();
|
||||
boundingBox.translate(x, y, z);
|
||||
|
||||
// The ULP should give an upper bound on the floating point error
|
||||
double xULP = Math.ulp((float) Math.max(Math.abs(playerCollision.getMiddleX()) + playerCollision.getSizeX() / 2.0, Math.abs(x) + 1));
|
||||
double zULP = Math.ulp((float) Math.max(Math.abs(playerCollision.getMiddleZ()) + playerCollision.getSizeZ() / 2.0, Math.abs(z) + 1));
|
||||
double xPushAwayTolerance = Math.max(pushAwayTolerance, xULP), zPushAwayTolerance = Math.max(pushAwayTolerance, zULP);
|
||||
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.NORTH, zPushAwayTolerance);
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.SOUTH, zPushAwayTolerance);
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.EAST, xPushAwayTolerance);
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.WEST, xPushAwayTolerance);
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.UP, pushAwayTolerance);
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.DOWN, pushAwayTolerance);
|
||||
}
|
||||
|
||||
return true;
|
||||
// Set the collision size back to normal
|
||||
playerCollision.expand(-collisionExpansion);
|
||||
}
|
||||
|
||||
public boolean checkIntersection(double x, double y, double z, BoundingBox playerCollision) {
|
||||
@@ -184,4 +127,4 @@ public class BlockCollision {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2025 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.translator.collision;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.level.physics.Axis;
|
||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@CollisionRemapper(regex = "^chest$", passDefaultBoxes = true)
|
||||
public class ChestCollision extends BlockCollision {
|
||||
public ChestCollision(BlockState state, BoundingBox[] boxes) {
|
||||
super(boxes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
super.correctPosition(session, x, y, z, playerCollision);
|
||||
|
||||
final SessionPlayerEntity player = session.getPlayerEntity();
|
||||
|
||||
// Player haven't even fall on the blocks yet, no need to move them down.
|
||||
if (!player.isCollidingVertically()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final double collisionExpansion = CollisionManager.COLLISION_TOLERANCE * 2;
|
||||
// Slightly expand the collision so we can see if the player is actually colliding with the block or not.
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() + collisionExpansion);
|
||||
|
||||
double beforeYVelocity = player.getLastTickEndVelocity().getY();
|
||||
// If the player is already colliding with the block or player velocity y is larger than 0 then player likely don't need to be correct.
|
||||
if (beforeYVelocity > 0 || playerCollision.getMin(Axis.Y) - player.position().getY() > 0 || this.checkIntersection(x, y, z, playerCollision)) {
|
||||
playerCollision.setSizeY(playerCollision.getSizeX() - collisionExpansion);
|
||||
return;
|
||||
}
|
||||
playerCollision.setSizeY(playerCollision.getSizeX() - collisionExpansion);
|
||||
|
||||
BoundingBox previous = playerCollision.clone();
|
||||
previous.setMiddleX(player.getPosition().getX());
|
||||
previous.setMiddleY(player.position().getY() + (playerCollision.getSizeY() / 2));
|
||||
previous.setMiddleZ(player.getPosition().getZ());
|
||||
|
||||
// Check for chest bug (chest are 0.875 blocks thick on Java but 0.95 blocks thick on Bedrock)
|
||||
// We grab the player velocity from last tick then apply collision on it, if the player can still fall then we correct
|
||||
// their position to fall down. If not then just use the player current position. Also do the same when player is jumping, if player
|
||||
// haven't collided yet, then correct them. Resolve #3277 and #4955
|
||||
double yVelocity = Math.max(beforeYVelocity, this.computeCollisionOffset(x, y, z, previous, Axis.Y, beforeYVelocity));
|
||||
// Player velocity is close enough, no need to correct, avoid moving player position silently if possible. Also don't move the player upwards.
|
||||
if (Math.abs(beforeYVelocity - yVelocity) <= CollisionManager.COLLISION_TOLERANCE || yVelocity > CollisionManager.COLLISION_TOLERANCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
previous.translate(0, yVelocity, 0);
|
||||
playerCollision.setMiddleY(previous.getMiddleY());
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.translator.collision;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@CollisionRemapper(regex = "^dirt_path$", passDefaultBoxes = true)
|
||||
public class DirtPathCollision extends BlockCollision {
|
||||
public DirtPathCollision(BlockState state, BoundingBox[] defaultBoxes) {
|
||||
super(defaultBoxes);
|
||||
}
|
||||
|
||||
// Needs to run before the main correction code or it can move the player into blocks
|
||||
// This is counteracted by the main collision code pushing them out
|
||||
@Override
|
||||
public void beforeCorrectPosition(int x, int y, int z, BoundingBox playerCollision) {
|
||||
// In Bedrock, dirt paths are solid blocks, so the player must be pushed down.
|
||||
double playerMinY = playerCollision.getMiddleY() - (playerCollision.getSizeY() / 2);
|
||||
double blockMaxY = y + 1;
|
||||
if (Math.abs(blockMaxY - playerMinY) <= CollisionManager.COLLISION_TOLERANCE) {
|
||||
playerCollision.translate(0, -0.0625, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ import lombok.EqualsAndHashCode;
|
||||
import org.geysermc.geyser.level.block.property.Properties;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
import org.geysermc.geyser.level.physics.Direction;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -59,26 +61,25 @@ public class DoorCollision extends BlockCollision {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
boolean result = super.correctPosition(session, x, y, z, playerCollision);
|
||||
// Hack to prevent false positives
|
||||
playerCollision.setSizeX(playerCollision.getSizeX() - 0.0001);
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() - 0.0001);
|
||||
playerCollision.setSizeZ(playerCollision.getSizeZ() - 0.0001);
|
||||
public void correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
super.correctPosition(session, x, y, z, playerCollision);
|
||||
final double maxPushDistance = 0.005 + CollisionManager.COLLISION_TOLERANCE * 1.01F;
|
||||
|
||||
// Check for door bug (doors are 0.1875 blocks thick on Java but 0.1825 blocks thick on Bedrock)
|
||||
if (this.checkIntersection(x, y, z, playerCollision)) {
|
||||
switch (facing) {
|
||||
case 1 -> playerCollision.setMiddleZ(z + 0.5125); // North
|
||||
case 2 -> playerCollision.setMiddleX(x + 0.5125); // East
|
||||
case 3 -> playerCollision.setMiddleZ(z + 0.4875); // South
|
||||
case 4 -> playerCollision.setMiddleX(x + 0.4875); // West
|
||||
for (BoundingBox boundingBox : this.boundingBoxes) {
|
||||
if (!boundingBox.checkIntersection(x, y, z, playerCollision)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boundingBox = boundingBox.clone();
|
||||
boundingBox.translate(x, y, z);
|
||||
|
||||
switch (this.facing) {
|
||||
case 1 -> boundingBox.pushOutOfBoundingBox(playerCollision, Direction.NORTH, maxPushDistance);
|
||||
case 2 -> boundingBox.pushOutOfBoundingBox(playerCollision, Direction.EAST, maxPushDistance);
|
||||
case 3 -> boundingBox.pushOutOfBoundingBox(playerCollision, Direction.SOUTH, maxPushDistance);
|
||||
case 4 -> boundingBox.pushOutOfBoundingBox(playerCollision, Direction.WEST, maxPushDistance);
|
||||
}
|
||||
}
|
||||
|
||||
playerCollision.setSizeX(playerCollision.getSizeX() + 0.0001);
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() + 0.0001);
|
||||
playerCollision.setSizeZ(playerCollision.getSizeZ() + 0.0001);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import lombok.EqualsAndHashCode;
|
||||
import org.geysermc.geyser.level.block.property.Properties;
|
||||
import org.geysermc.geyser.level.block.type.BlockState;
|
||||
import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
import org.geysermc.geyser.level.physics.Direction;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -68,46 +70,36 @@ public class GlassPaneAndIronBarsCollision extends BlockCollision {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
boolean result = super.correctPosition(session, x, y, z, playerCollision);
|
||||
playerCollision.setSizeX(playerCollision.getSizeX() - 0.0001);
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() - 0.0001);
|
||||
playerCollision.setSizeZ(playerCollision.getSizeZ() - 0.0001);
|
||||
public void correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
super.correctPosition(session, x, y, z, playerCollision);
|
||||
|
||||
if (this.checkIntersection(x, y, z, playerCollision)) {
|
||||
double newMiddleX = x;
|
||||
double newMiddleZ = z;
|
||||
final double maxPushDistance = 0.0625 + CollisionManager.COLLISION_TOLERANCE * 1.01F;
|
||||
|
||||
switch (facing) {
|
||||
case 1 -> newMiddleZ += 0.8625; // North
|
||||
case 2 -> newMiddleX += 0.1375; // East
|
||||
case 3 -> newMiddleZ += 0.1375; // South
|
||||
case 4 -> newMiddleX += 0.8625; // West
|
||||
case 5 -> { // North, East
|
||||
newMiddleZ += 0.8625;
|
||||
newMiddleX += 0.1375;
|
||||
}
|
||||
case 6 -> { // East, South
|
||||
newMiddleX += 0.1375;
|
||||
newMiddleZ += 0.1375;
|
||||
}
|
||||
case 7 -> { // South, West
|
||||
newMiddleZ += 0.1375;
|
||||
newMiddleX += 0.8625;
|
||||
}
|
||||
case 8 -> { // West, North
|
||||
newMiddleX += 0.8625;
|
||||
newMiddleZ += 0.8625;
|
||||
}
|
||||
// Check for glass pane/iron bars bug (pane/iron bars is 0.5 blocks thick on Bedrock but 0.5625 on Java when only 1 side is connected).
|
||||
for (BoundingBox boundingBox : this.boundingBoxes) {
|
||||
if (!boundingBox.checkIntersection(x, y, z, playerCollision)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
playerCollision.setMiddleX(newMiddleX);
|
||||
playerCollision.setMiddleZ(newMiddleZ);
|
||||
}
|
||||
boundingBox = boundingBox.clone();
|
||||
boundingBox.translate(x, y, z);
|
||||
|
||||
playerCollision.setSizeX(playerCollision.getSizeX() + 0.0001);
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() + 0.0001);
|
||||
playerCollision.setSizeZ(playerCollision.getSizeZ() + 0.0001);
|
||||
return result;
|
||||
// Also we want to flip the direction since the direction here is indicating the block side the glass is connected to.
|
||||
if (this.facing == 2 || this.facing == 6 || this.facing == 5) { // East
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.WEST, maxPushDistance);
|
||||
}
|
||||
|
||||
if (this.facing == 1 || this.facing == 5 || this.facing == 8) { // North.
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.SOUTH, maxPushDistance);
|
||||
}
|
||||
|
||||
if (this.facing == 3 || this.facing == 6 || this.facing == 7) { // South
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.NORTH, maxPushDistance);
|
||||
}
|
||||
|
||||
if (this.facing == 4 || this.facing == 7 || this.facing == 8) { // West
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, Direction.EAST, maxPushDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.geysermc.geyser.level.physics.BoundingBox;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OtherCollision extends BlockCollision {
|
||||
|
||||
public OtherCollision(BoundingBox[] boundingBoxes) {
|
||||
super(boundingBoxes);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ScaffoldingCollision extends BlockCollision {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
public void correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
// Hack to not check below the player
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() - 0.001);
|
||||
playerCollision.setMiddleY(playerCollision.getMiddleY() + 0.002);
|
||||
@@ -66,8 +66,5 @@ public class ScaffoldingCollision extends BlockCollision {
|
||||
playerCollision.setSizeY(playerCollision.getSizeY() - 0.001);
|
||||
playerCollision.setMiddleY(playerCollision.getMiddleY() + 0.002);
|
||||
}
|
||||
|
||||
// Normal move correction isn't really needed for scaffolding
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,32 +52,20 @@ public class TrapdoorCollision extends BlockCollision {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
boolean result = super.correctPosition(session, x, y, z, playerCollision);
|
||||
// Check for door bug (doors are 0.1875 blocks thick on Java but 0.1825 blocks thick on Bedrock)
|
||||
if (this.checkIntersection(x, y, z, playerCollision)) {
|
||||
switch (facing) {
|
||||
case NORTH:
|
||||
playerCollision.setMiddleZ(z + 0.5125);
|
||||
break;
|
||||
case EAST:
|
||||
playerCollision.setMiddleX(x + 0.5125);
|
||||
break;
|
||||
case SOUTH:
|
||||
playerCollision.setMiddleZ(z + 0.4875);
|
||||
break;
|
||||
case WEST:
|
||||
playerCollision.setMiddleX(x + 0.4875);
|
||||
break;
|
||||
case UP:
|
||||
// Up-facing trapdoors are handled by the step-up check
|
||||
break;
|
||||
case DOWN:
|
||||
// (top y of trap door) - (trap door thickness) = top y of player
|
||||
playerCollision.setMiddleY(y + 1 - (3.0 / 16.0) - playerCollision.getSizeY() / 2.0 - CollisionManager.COLLISION_TOLERANCE);
|
||||
break;
|
||||
public void correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
||||
super.correctPosition(session, x, y, z, playerCollision);
|
||||
|
||||
final double maxPushDistance = 0.005 + CollisionManager.COLLISION_TOLERANCE * 1.01F;
|
||||
|
||||
// Check for trapdoor bug (trapdoors are 0.1875 blocks thick on Java but 0.1825 blocks thick on Bedrock)
|
||||
for (BoundingBox boundingBox : this.boundingBoxes) {
|
||||
if (!boundingBox.checkIntersection(x, y, z, playerCollision)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boundingBox = boundingBox.clone();
|
||||
boundingBox.translate(x, y, z);
|
||||
boundingBox.pushOutOfBoundingBox(playerCollision, facing, maxPushDistance);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,8 @@ final class BedrockMovePlayer {
|
||||
entity.setLastTickEndVelocity(Vector3f.from(entity.getLastTickEndVelocity().getX(), 0.2F, entity.getLastTickEndVelocity().getZ()));
|
||||
}
|
||||
|
||||
entity.setCollidingVertically(packet.getInputData().contains(PlayerAuthInputData.VERTICAL_COLLISION));
|
||||
|
||||
// Client is telling us it wants to move down, but something is blocking it from doing so.
|
||||
boolean isOnGround;
|
||||
if (hasVehicle || session.isNoClip()) {
|
||||
@@ -113,7 +115,7 @@ final class BedrockMovePlayer {
|
||||
// Also do this if player have no clip ability since they shouldn't be able to collide with anything.
|
||||
isOnGround = false;
|
||||
} else {
|
||||
isOnGround = packet.getInputData().contains(PlayerAuthInputData.VERTICAL_COLLISION) && entity.getLastTickEndVelocity().getY() < 0;
|
||||
isOnGround = entity.isCollidingVertically() && entity.getLastTickEndVelocity().getY() < 0;
|
||||
}
|
||||
|
||||
// Resolve https://github.com/GeyserMC/Geyser/issues/3521, no void floor on java so player not supposed to collide with anything.
|
||||
@@ -148,9 +150,6 @@ final class BedrockMovePlayer {
|
||||
session.setNoClip(!possibleOnGround);
|
||||
}
|
||||
|
||||
entity.setLastTickEndVelocity(packet.getDelta());
|
||||
entity.setMotion(packet.getDelta());
|
||||
|
||||
// This takes into account no movement sent from the client, but the player is trying to move anyway.
|
||||
// (Press into a wall in a corner - you're trying to move but nothing actually happens)
|
||||
// This isn't sent when a player is riding a vehicle (as of 1.21.62)
|
||||
@@ -217,6 +216,9 @@ final class BedrockMovePlayer {
|
||||
session.sendDownstreamGamePacket(new ServerboundMovePlayerStatusOnlyPacket(isOnGround, horizontalCollision));
|
||||
}
|
||||
|
||||
entity.setLastTickEndVelocity(packet.getDelta());
|
||||
entity.setMotion(packet.getDelta());
|
||||
|
||||
session.getInputCache().setLastHorizontalCollision(horizontalCollision);
|
||||
entity.setOnGround(isOnGround);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user