mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00: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
This commit is contained in:
parent
6cd8b3387c
commit
65aaa07493
5 changed files with 33 additions and 29 deletions
|
@ -181,7 +181,7 @@ public final class EntityDefinitions {
|
||||||
.addTranslator(MetadataType.BOOLEAN, Entity::setDisplayNameVisible)
|
.addTranslator(MetadataType.BOOLEAN, Entity::setDisplayNameVisible)
|
||||||
.addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
|
.addTranslator(MetadataType.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.SILENT, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
|
||||||
.addTranslator(MetadataType.BOOLEAN, Entity::setGravity)
|
.addTranslator(MetadataType.BOOLEAN, Entity::setGravity)
|
||||||
.addTranslator(MetadataType.POSE, Entity::setPose)
|
.addTranslator(MetadataType.POSE, (entity, entityMetadata) -> entity.setPose(entityMetadata.getValue()))
|
||||||
.addTranslator(MetadataType.INT, Entity::setFreezing)
|
.addTranslator(MetadataType.INT, Entity::setFreezing)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,9 @@ public class Entity {
|
||||||
|
|
||||||
protected EntityDefinition<?> definition;
|
protected EntityDefinition<?> definition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the entity has been initialized and spawned
|
||||||
|
*/
|
||||||
protected boolean valid;
|
protected boolean valid;
|
||||||
|
|
||||||
/* Metadata about this specific entity */
|
/* Metadata about this specific entity */
|
||||||
|
@ -372,9 +375,7 @@ public class Entity {
|
||||||
/**
|
/**
|
||||||
* Usually used for bounding box and not animation.
|
* Usually used for bounding box and not animation.
|
||||||
*/
|
*/
|
||||||
public void setPose(EntityMetadata<Pose, ?> entityMetadata) {
|
public void setPose(Pose pose) {
|
||||||
Pose pose = entityMetadata.getValue();
|
|
||||||
|
|
||||||
setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING));
|
setFlag(EntityFlag.SLEEPING, pose.equals(Pose.SLEEPING));
|
||||||
// Triggered when crawling
|
// Triggered when crawling
|
||||||
setFlag(EntityFlag.SWIMMING, pose.equals(Pose.SWIMMING));
|
setFlag(EntityFlag.SWIMMING, pose.equals(Pose.SWIMMING));
|
||||||
|
@ -390,13 +391,15 @@ public class Entity {
|
||||||
setBoundingBoxWidth(definition.width());
|
setBoundingBoxWidth(definition.width());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundingBoxHeight(float height) {
|
public boolean setBoundingBoxHeight(float height) {
|
||||||
if (height != boundingBoxHeight) {
|
if (height != boundingBoxHeight) {
|
||||||
boundingBoxHeight = height;
|
boundingBoxHeight = height;
|
||||||
dirtyMetadata.put(EntityData.BOUNDING_BOX_HEIGHT, boundingBoxHeight);
|
dirtyMetadata.put(EntityData.BOUNDING_BOX_HEIGHT, boundingBoxHeight);
|
||||||
|
|
||||||
updatePassengerOffsets();
|
updatePassengerOffsets();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundingBoxWidth(float width) {
|
public void setBoundingBoxWidth(float width) {
|
||||||
|
|
|
@ -73,13 +73,10 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||||
*/
|
*/
|
||||||
private int fakeTradeXp;
|
private int fakeTradeXp;
|
||||||
|
|
||||||
private final GeyserSession session;
|
|
||||||
|
|
||||||
public SessionPlayerEntity(GeyserSession session) {
|
public SessionPlayerEntity(GeyserSession session) {
|
||||||
super(session, -1, 1, new GameProfile(UUID.randomUUID(), "unknown"), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0);
|
super(session, -1, 1, new GameProfile(UUID.randomUUID(), "unknown"), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0);
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
this.session = session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,7 +92,7 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(Vector3f position) {
|
public void setPosition(Vector3f position) {
|
||||||
if (session != null) { // null during entity initialization
|
if (valid) { // Don't update during session init
|
||||||
session.getCollisionManager().updatePlayerBoundingBox(position);
|
session.getCollisionManager().updatePlayerBoundingBox(position);
|
||||||
}
|
}
|
||||||
super.setPosition(position);
|
super.setPosition(position);
|
||||||
|
@ -117,15 +114,28 @@ public class SessionPlayerEntity extends PlayerEntity {
|
||||||
super.setFlags(entityMetadata);
|
super.setFlags(entityMetadata);
|
||||||
// Swimming/crawling is controlled by the Java server
|
// Swimming/crawling is controlled by the Java server
|
||||||
boolean swimming = (entityMetadata.getPrimitiveValue() & 0x10) == 0x10;
|
boolean swimming = (entityMetadata.getPrimitiveValue() & 0x10) == 0x10;
|
||||||
session.setSwimming(swimming);
|
if (swimming) {
|
||||||
|
setPose(Pose.SWIMMING);
|
||||||
|
}
|
||||||
session.setSwimmingInWater(swimming && getFlag(EntityFlag.SPRINTING));
|
session.setSwimmingInWater(swimming && getFlag(EntityFlag.SPRINTING));
|
||||||
refreshSpeed = true;
|
refreshSpeed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPose(EntityMetadata<Pose, ?> entityMetadata) {
|
public boolean setBoundingBoxHeight(float height) {
|
||||||
super.setPose(entityMetadata);
|
if (super.setBoundingBoxHeight(height)) {
|
||||||
session.setPose(entityMetadata.getValue());
|
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;
|
refreshSpeed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1059,18 +1059,14 @@ public class GeyserSession implements GeyserConnection, CommandSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSneakingPose(boolean sneaking) {
|
private void setSneakingPose(boolean sneaking) {
|
||||||
this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING;
|
if (this.pose == Pose.SNEAKING && !sneaking) {
|
||||||
playerEntity.setBoundingBoxHeight(sneaking ? 1.5f : playerEntity.getDefinition().height());
|
this.pose = Pose.STANDING;
|
||||||
playerEntity.setFlag(EntityFlag.SNEAKING, sneaking);
|
playerEntity.setBoundingBoxHeight(playerEntity.getDefinition().height());
|
||||||
|
} else if (sneaking) {
|
||||||
collisionManager.updatePlayerBoundingBox();
|
this.pose = Pose.SNEAKING;
|
||||||
|
playerEntity.setBoundingBoxHeight(1.5f);
|
||||||
}
|
}
|
||||||
|
playerEntity.setFlag(EntityFlag.SNEAKING, sneaking);
|
||||||
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) {
|
public void setFlying(boolean flying) {
|
||||||
|
|
|
@ -49,10 +49,5 @@ public class BedrockAdventureSettingsTranslator extends PacketTranslator<Adventu
|
||||||
session.setFlying(isFlying);
|
session.setFlying(isFlying);
|
||||||
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(isFlying);
|
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(isFlying);
|
||||||
session.sendDownstreamPacket(abilitiesPacket);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue