Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 07:40:10 +01:00
Fix sneaking speed adjustment and bounding box (#2728)
* Fix sneaking speed adjustment and bounding box Also remove redundant session variable in SessionPlayerEntity * Add comment to valid field * Hopefully fix crawling after swimming in water
Dieser Commit ist enthalten in:
Ursprung
6cd8b3387c
Commit
65aaa07493
@ -181,7 +181,7 @@ public final class EntityDefinitions {
|
||||
.addTranslator(MetadataType.BOOLEAN, Entity::setDisplayNameVisible)
|
||||
.addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
|
||||
.addTranslator(MetadataType.BOOLEAN, Entity::setGravity)
|
||||
.addTranslator(MetadataType.POSE, Entity::setPose)
|
||||
.addTranslator(MetadataType.POSE, (entity, entityMetadata) -> entity.setPose(entityMetadata.getValue()))
|
||||
.addTranslator(MetadataType.INT, Entity::setFreezing)
|
||||
.build();
|
||||
|
||||
|
@ -81,6 +81,9 @@ public class Entity {
|
||||
|
||||
protected EntityDefinition<?> definition;
|
||||
|
||||
/**
|
||||
* Indicates if the entity has been initialized and spawned
|
||||
*/
|
||||
protected boolean valid;
|
||||
|
||||
/* Metadata about this specific entity */
|
||||
@ -372,9 +375,7 @@ public class Entity {
|
||||
/**
|
||||
* Usually used for bounding box and not animation.
|
||||
*/
|
||||
public void setPose(EntityMetadata<Pose, ?> entityMetadata) {
|
||||
Pose pose = entityMetadata.getValue();
|
||||
|
||||
public void setPose(Pose pose) {
|
||||
setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING));
|
||||
// Triggered when crawling
|
||||
setFlag(EntityFlag.SWIMMING, pose.equals(Pose.SWIMMING));
|
||||
@ -390,13 +391,15 @@ public class Entity {
|
||||
setBoundingBoxWidth(definition.width());
|
||||
}
|
||||
|
||||
public void setBoundingBoxHeight(float height) {
|
||||
public boolean setBoundingBoxHeight(float height) {
|
||||
if (height != boundingBoxHeight) {
|
||||
boundingBoxHeight = height;
|
||||
dirtyMetadata.put(EntityData.BOUNDING_BOX_HEIGHT, boundingBoxHeight);
|
||||
|
||||
updatePassengerOffsets();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setBoundingBoxWidth(float width) {
|
||||
|
@ -73,13 +73,10 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
*/
|
||||
private int fakeTradeXp;
|
||||
|
||||
private final GeyserSession session;
|
||||
|
||||
public SessionPlayerEntity(GeyserSession session) {
|
||||
super(session, -1, 1, new GameProfile(UUID.randomUUID(), "unknown"), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0);
|
||||
|
||||
valid = true;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,7 +92,7 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
|
||||
@Override
|
||||
public void setPosition(Vector3f position) {
|
||||
if (session != null) { // null during entity initialization
|
||||
if (valid) { // Don't update during session init
|
||||
session.getCollisionManager().updatePlayerBoundingBox(position);
|
||||
}
|
||||
super.setPosition(position);
|
||||
@ -117,15 +114,28 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||
super.setFlags(entityMetadata);
|
||||
// Swimming/crawling is controlled by the Java server
|
||||
boolean swimming = (entityMetadata.getPrimitiveValue() & 0x10) == 0x10;
|
||||
session.setSwimming(swimming);
|
||||
if (swimming) {
|
||||
setPose(Pose.SWIMMING);
|
||||
}
|
||||
session.setSwimmingInWater(swimming && getFlag(EntityFlag.SPRINTING));
|
||||
refreshSpeed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPose(EntityMetadata<Pose, ?> entityMetadata) {
|
||||
super.setPose(entityMetadata);
|
||||
session.setPose(entityMetadata.getValue());
|
||||
public boolean setBoundingBoxHeight(float height) {
|
||||
if (super.setBoundingBoxHeight(height)) {
|
||||
if (valid) { // Don't update during session init
|
||||
session.getCollisionManager().updatePlayerBoundingBox();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPose(Pose pose) {
|
||||
super.setPose(pose);
|
||||
session.setPose(pose);
|
||||
refreshSpeed = true;
|
||||
}
|
||||
|
||||
|
@ -1059,18 +1059,14 @@ public class GeyserSession implements GeyserConnection, CommandSender {
|
||||
}
|
||||
|
||||
private void setSneakingPose(boolean sneaking) {
|
||||
this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING;
|
||||
playerEntity.setBoundingBoxHeight(sneaking ? 1.5f : playerEntity.getDefinition().height());
|
||||
if (this.pose == Pose.SNEAKING && !sneaking) {
|
||||
this.pose = Pose.STANDING;
|
||||
playerEntity.setBoundingBoxHeight(playerEntity.getDefinition().height());
|
||||
} else if (sneaking) {
|
||||
this.pose = Pose.SNEAKING;
|
||||
playerEntity.setBoundingBoxHeight(1.5f);
|
||||
}
|
||||
playerEntity.setFlag(EntityFlag.SNEAKING, sneaking);
|
||||
|
||||
collisionManager.updatePlayerBoundingBox();
|
||||
}
|
||||
|
||||
public void setSwimming(boolean swimming) {
|
||||
this.pose = swimming ? Pose.SWIMMING : Pose.STANDING;
|
||||
playerEntity.setBoundingBoxHeight(swimming ? 0.6f : playerEntity.getDefinition().height());
|
||||
playerEntity.setFlag(EntityFlag.SWIMMING, swimming);
|
||||
playerEntity.updateBedrockMetadata();
|
||||
}
|
||||
|
||||
public void setFlying(boolean flying) {
|
||||
|
@ -49,10 +49,5 @@ public class BedrockAdventureSettingsTranslator extends PacketTranslator<Adventu
|
||||
session.setFlying(isFlying);
|
||||
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(isFlying);
|
||||
session.sendDownstreamPacket(abilitiesPacket);
|
||||
|
||||
if (isFlying && session.getPlayerEntity().getFlag(EntityFlag.SWIMMING)) {
|
||||
// Bedrock can fly and swim at the same time? Make sure that can't happen
|
||||
session.setSwimming(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren