3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Address some reviews

Dieser Commit ist enthalten in:
AJ Ferguson 2024-06-21 00:35:22 -04:00
Ursprung 97c42d34d5
Commit d49a3ec5dd
5 geänderte Dateien mit 66 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -40,7 +40,6 @@ import org.geysermc.geyser.api.entity.type.GeyserEntity;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.GeyserDirtyMetadata;
import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager;
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.text.MessageTranslator;
@ -224,13 +223,6 @@ public class Entity implements GeyserEntity {
}
public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) {
if (this instanceof ClientVehicle clientVehicle) {
if (clientVehicle.isClientControlled()) {
return;
}
clientVehicle.getVehicleComponent().moveRelative(relX, relY, relZ);
}
position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
MoveEntityDeltaPacket moveEntityPacket = new MoveEntityDeltaPacket();
@ -466,10 +458,6 @@ public class Entity implements GeyserEntity {
dirtyMetadata.put(EntityDataTypes.HEIGHT, boundingBoxHeight);
updatePassengerOffsets();
if (valid && this instanceof ClientVehicle clientVehicle) {
clientVehicle.getVehicleComponent().setHeight(boundingBoxHeight);
}
return true;
}
return false;
@ -479,10 +467,6 @@ public class Entity implements GeyserEntity {
if (width != boundingBoxWidth) {
boundingBoxWidth = width;
dirtyMetadata.put(EntityDataTypes.WIDTH, boundingBoxWidth);
if (valid && this instanceof ClientVehicle clientVehicle) {
clientVehicle.getVehicleComponent().setWidth(boundingBoxWidth);
}
}
}

Datei anzeigen

@ -289,6 +289,36 @@ public class LivingEntity extends Entity {
return super.interact(hand);
}
@Override
public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) {
if (this instanceof ClientVehicle clientVehicle) {
if (clientVehicle.isClientControlled()) {
return;
}
clientVehicle.getVehicleComponent().moveRelative(relX, relY, relZ);
}
super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround);
}
@Override
public boolean setBoundingBoxHeight(float height) {
if (valid && this instanceof ClientVehicle clientVehicle) {
clientVehicle.getVehicleComponent().setHeight(height);
}
return super.setBoundingBoxHeight(height);
}
@Override
public void setBoundingBoxWidth(float width) {
if (valid && this instanceof ClientVehicle clientVehicle) {
clientVehicle.getVehicleComponent().setWidth(width);
}
super.setBoundingBoxWidth(width);
}
/**
* Checks to see if a nametag interaction would go through.
*/

Datei anzeigen

@ -38,6 +38,7 @@ import org.geysermc.erosion.util.BlockPositionIterator;
import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.block.Blocks;
import org.geysermc.geyser.level.block.property.Properties;
@ -132,6 +133,21 @@ public class CollisionManager {
playerBoundingBox.setSizeY(playerHeight);
}
/**
* Gets the bounding box to use for player movement.
* <p>
* This will return either the bounding box of a {@link ClientVehicle}, or the player's own bounding box.
*
* @return the bounding box to use for movement calculations
*/
public BoundingBox getActiveBoundingBox() {
if (session.getPlayerEntity().getVehicle() instanceof ClientVehicle clientVehicle && clientVehicle.isClientControlled()) {
return clientVehicle.getVehicleComponent().getBoundingBox();
}
return playerBoundingBox;
}
/**
* Adjust the Bedrock position before sending to the Java server to account for inaccuracies in movement between
* the two versions. Will also send corrected movement packets back to Bedrock if they collide with pistons.
@ -154,6 +170,15 @@ public class CollisionManager {
Vector3d position = Vector3d.from(Double.parseDouble(Float.toString(bedrockPosition.getX())), javaY,
Double.parseDouble(Float.toString(bedrockPosition.getZ())));
// Don't correct position if controlling a vehicle
if (session.getPlayerEntity().getVehicle() instanceof ClientVehicle clientVehicle && clientVehicle.isClientControlled()) {
playerBoundingBox.setMiddleX(position.getX());
playerBoundingBox.setMiddleY(position.getY() + playerBoundingBox.getSizeY() / 2);
playerBoundingBox.setMiddleZ(position.getZ());
return playerBoundingBox.getBottomCenter();
}
Vector3d startingPos = playerBoundingBox.getBottomCenter();
Vector3d movement = position.sub(startingPos);
Vector3d adjustedMovement = correctPlayerMovement(movement, false, teleported);

Datei anzeigen

@ -167,10 +167,17 @@ public class BlockCollision {
return offset;
}
public boolean isBelow(double y, BoundingBox boundingBox) {
/**
* Checks if this block collision is below the given bounding box.
*
* @param blockY the y position of the block in the world
* @param boundingBox the bounding box to compare
* @return true if this block collision is below the bounding box
*/
public boolean isBelow(int blockY, BoundingBox boundingBox) {
double minY = boundingBox.getMiddleY() - boundingBox.getSizeY() / 2;
for (BoundingBox b : boundingBoxes) {
double offset = y + b.getMiddleY() + b.getSizeY() / 2 - minY;
double offset = blockY + b.getMiddleY() + b.getSizeY() / 2 - minY;
if (offset > CollisionManager.COLLISION_TOLERANCE) {
return false;
}

Datei anzeigen

@ -601,14 +601,7 @@ public class PistonBlockEntity {
movingBlockMap.put(getPistonHeadPos(), this);
Vector3i movement = getMovement();
BoundingBox playerBoundingBox;
if (session.getPlayerEntity().getVehicle() instanceof ClientVehicle clientVehicle && clientVehicle.isClientControlled()) {
playerBoundingBox = clientVehicle.getVehicleComponent().getBoundingBox().clone();
} else {
playerBoundingBox = session.getCollisionManager().getPlayerBoundingBox().clone();
}
BoundingBox playerBoundingBox = session.getCollisionManager().getActiveBoundingBox().clone();
if (orientation == Direction.UP) {
// Extend the bounding box down, to catch collisions when the player is falling down
playerBoundingBox.extend(0, -256, 0);
@ -653,14 +646,8 @@ public class PistonBlockEntity {
}
placedFinalBlocks = true;
BoundingBox playerBoundingBox;
if (session.getPlayerEntity().getVehicle() instanceof ClientVehicle clientVehicle && clientVehicle.isClientControlled()) {
playerBoundingBox = clientVehicle.getVehicleComponent().getBoundingBox().clone();
} else {
playerBoundingBox = session.getCollisionManager().getPlayerBoundingBox().clone();
}
Vector3i movement = getMovement();
BoundingBox playerBoundingBox = session.getCollisionManager().getActiveBoundingBox().clone();
attachedBlocks.forEach((blockPos, state) -> {
blockPos = blockPos.add(movement);
// Don't place blocks that collide with the player