mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix movement against spawners (#2409)
This commit is contained in:
parent
a93f3119f6
commit
c6589136bf
2 changed files with 64 additions and 28 deletions
|
@ -54,6 +54,11 @@ public class BlockCollision {
|
|||
@EqualsAndHashCode.Exclude
|
||||
protected double pushUpTolerance = 1;
|
||||
|
||||
/**
|
||||
* This is used to control the maximum distance a face of a bounding box can push the player away
|
||||
*/
|
||||
protected double pushAwayTolerance = CollisionManager.COLLISION_TOLERANCE * 1.1;
|
||||
|
||||
public void setPosition(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -95,44 +100,38 @@ public class BlockCollision {
|
|||
// 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() - (playerCollision.getSizeY() / 2) - y,
|
||||
playerCollision.getMiddleY() - y,
|
||||
playerCollision.getMiddleZ() - z);
|
||||
|
||||
Vector3d northFacePos = Vector3d.from(b.getMiddleX(),
|
||||
b.getMiddleY(),
|
||||
b.getMiddleZ() - (b.getSizeZ() / 2));
|
||||
|
||||
Vector3d southFacePos = Vector3d.from(b.getMiddleX(),
|
||||
b.getMiddleY(),
|
||||
b.getMiddleZ() + (b.getSizeZ() / 2));
|
||||
|
||||
Vector3d eastFacePos = Vector3d.from(b.getMiddleX() + (b.getSizeX() / 2),
|
||||
b.getMiddleY(),
|
||||
b.getMiddleZ());
|
||||
|
||||
Vector3d westFacePos = Vector3d.from(b.getMiddleX() - (b.getSizeX() / 2),
|
||||
b.getMiddleY(),
|
||||
b.getMiddleZ());
|
||||
|
||||
double translateDistance = northFacePos.getZ() - relativePlayerPosition.getZ() - (playerCollision.getSizeZ() / 2);
|
||||
if (Math.abs(translateDistance) < CollisionManager.COLLISION_TOLERANCE * 1.1) {
|
||||
double northFaceZPos = b.getMiddleZ() - (b.getSizeZ() / 2);
|
||||
double translateDistance = northFaceZPos - relativePlayerPosition.getZ() - (playerCollision.getSizeZ() / 2);
|
||||
if (Math.abs(translateDistance) < pushAwayTolerance) {
|
||||
playerCollision.translate(0, 0, translateDistance);
|
||||
}
|
||||
|
||||
translateDistance = southFacePos.getZ() - relativePlayerPosition.getZ() + (playerCollision.getSizeZ() / 2);
|
||||
if (Math.abs(translateDistance) < CollisionManager.COLLISION_TOLERANCE * 1.1) {
|
||||
double southFaceZPos = b.getMiddleZ() + (b.getSizeZ() / 2);
|
||||
translateDistance = southFaceZPos - relativePlayerPosition.getZ() + (playerCollision.getSizeZ() / 2);
|
||||
if (Math.abs(translateDistance) < pushAwayTolerance) {
|
||||
playerCollision.translate(0, 0, translateDistance);
|
||||
}
|
||||
|
||||
translateDistance = eastFacePos.getX() - relativePlayerPosition.getX() + (playerCollision.getSizeX() / 2);
|
||||
if (Math.abs(translateDistance) < CollisionManager.COLLISION_TOLERANCE * 1.1) {
|
||||
double eastFaceXPos = b.getMiddleX() + (b.getSizeX() / 2);
|
||||
translateDistance = eastFaceXPos - relativePlayerPosition.getX() + (playerCollision.getSizeX() / 2);
|
||||
if (Math.abs(translateDistance) < pushAwayTolerance) {
|
||||
playerCollision.translate(translateDistance, 0, 0);
|
||||
}
|
||||
|
||||
translateDistance = westFacePos.getX() - relativePlayerPosition.getX() - (playerCollision.getSizeX() / 2);
|
||||
if (Math.abs(translateDistance) < CollisionManager.COLLISION_TOLERANCE * 1.1) {
|
||||
double westFaceXPos = b.getMiddleX() - (b.getSizeX() / 2);
|
||||
translateDistance = westFaceXPos - relativePlayerPosition.getX() - (playerCollision.getSizeX() / 2);
|
||||
if (Math.abs(translateDistance) < pushAwayTolerance) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the collision size back to normal
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2021 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.connector.network.translators.collision.translators;
|
||||
|
||||
import org.geysermc.connector.network.translators.collision.CollisionRemapper;
|
||||
|
||||
@CollisionRemapper(regex = "^spawner$")
|
||||
public class SpawnerCollision extends SolidCollision {
|
||||
public SpawnerCollision(String params) {
|
||||
super(params);
|
||||
// Increase pushAwayTolerance to work around https://bugs.mojang.com/browse/MCPE-41996
|
||||
pushAwayTolerance = 0.0002;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue