Skip to content

Commit

Permalink
More bounding box fixes (GeyserMC#2132)
Browse files Browse the repository at this point in the history
- Fix decimal formatting error when running Geyser in another region
- Fix sneaking bounding box when flying
  • Loading branch information
Camotoy authored Apr 12, 2021
1 parent 120769c commit 22c492f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ public class GeyserSession implements CommandSender {
/**
* If the current player is flying
*/
@Setter
private boolean flying = false;

/**
Expand Down Expand Up @@ -862,11 +861,10 @@ public void setSneaking(boolean sneaking) {
playerEntity.updateBedrockAttributes(this);
// the server *should* update our pose once it has returned to normal
} else {
this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING;
playerEntity.getMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, sneaking ? 1.5f : playerEntity.getEntityType().getHeight());
playerEntity.getMetadata().getFlags().setFlag(EntityFlag.SNEAKING, sneaking);

collisionManager.updatePlayerBoundingBox();
if (!flying) {
// The pose and bounding box should not be updated if the player is flying
setSneakingPose(sneaking);
}
collisionManager.updateScaffoldingFlags(false);
}

Expand All @@ -878,13 +876,31 @@ public void setSneaking(boolean sneaking) {
}
}

private void setSneakingPose(boolean sneaking) {
this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING;
playerEntity.getMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, sneaking ? 1.5f : playerEntity.getEntityType().getHeight());
playerEntity.getMetadata().getFlags().setFlag(EntityFlag.SNEAKING, sneaking);

collisionManager.updatePlayerBoundingBox();
}

public void setSwimming(boolean swimming) {
this.pose = swimming ? Pose.SWIMMING : Pose.STANDING;
playerEntity.getMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, swimming ? 0.6f : playerEntity.getEntityType().getHeight());
playerEntity.getMetadata().getFlags().setFlag(EntityFlag.SWIMMING, swimming);
playerEntity.updateBedrockMetadata(this);
}

public void setFlying(boolean flying) {
this.flying = flying;

if (sneaking) {
// update bounding box as it is not reduced when flying
setSneakingPose(!flying);
playerEntity.updateBedrockMetadata(this);
}
}

/**
* Adjusts speed if the player is crawling.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class BedrockAdventureSettingsTranslator extends PacketTranslator<Adventu
@Override
public void translate(AdventureSettingsPacket packet, GeyserSession session) {
boolean isFlying = packet.getSettings().contains(AdventureSetting.FLYING);
session.setFlying(isFlying);
ClientPlayerAbilitiesPacket abilitiesPacket = new ClientPlayerAbilitiesPacket(isFlying);
session.sendDownstreamPacket(abilitiesPacket);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
import org.geysermc.connector.network.translators.world.block.BlockTranslator;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class CollisionManager {

Expand Down Expand Up @@ -71,8 +73,9 @@ public class CollisionManager {
public static final double COLLISION_TOLERANCE = 0.00001;
/**
* Trims Y coordinates when jumping to prevent rounding issues being sent to the server.
* The locale used is necessary so other regions don't use <code>,</code> as their decimal separator.
*/
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#####");
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.#####", new DecimalFormatSymbols(Locale.ENGLISH));

public CollisionManager(GeyserSession session) {
this.session = session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package org.geysermc.connector.network.translators.java.entity.player;

import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
import org.geysermc.connector.entity.player.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
Expand All @@ -36,10 +35,6 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer

@Override
public void translate(ServerPlayerAbilitiesPacket packet, GeyserSession session) {
PlayerEntity entity = session.getPlayerEntity();
if (entity == null)
return;

session.setCanFly(packet.isCanFly());
session.setFlying(packet.isFlying());
session.sendAdventureSettings();
Expand Down

0 comments on commit 22c492f

Please sign in to comment.