Fix air bubbles for Bedrock 1.21

This commit is contained in:
Camotoy 2024-06-04 17:09:57 -04:00
parent 0ca42308eb
commit 42ae9eba55
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 13 additions and 1 deletions

View file

@ -31,9 +31,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.AttributeData;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.network.GameProtocol;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.AttributeUtils; import org.geysermc.geyser.util.AttributeUtils;
import org.geysermc.geyser.util.DimensionUtils; import org.geysermc.geyser.util.DimensionUtils;
@ -65,6 +67,8 @@ public class SessionPlayerEntity extends PlayerEntity {
@Getter @Getter
private boolean isRidingInFront; private boolean isRidingInFront;
private int lastAirSupply = getMaxAir();
public SessionPlayerEntity(GeyserSession session) { public SessionPlayerEntity(GeyserSession session) {
super(session, -1, 1, null, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, null, null); super(session, -1, 1, null, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, null, null);
@ -159,7 +163,13 @@ public class SessionPlayerEntity extends PlayerEntity {
@Override @Override
protected void setAirSupply(int amount) { protected void setAirSupply(int amount) {
if (amount == getMaxAir()) { // Seemingly required to be sent as of Bedrock 1.21. Otherwise, bubbles will appear as empty
// Also, this changes how the air bubble graphics/sounds are presented. Breathing on means sound effects and
// the bubbles visually pop
setFlag(EntityFlag.BREATHING, amount >= this.lastAirSupply);
this.lastAirSupply = amount;
if (amount == getMaxAir() && GameProtocol.isPre1_21_0(session)) {
super.setAirSupply(0); // Hide the bubble counter from the UI for the player super.setAirSupply(0); // Hide the bubble counter from the UI for the player
} else { } else {
super.setAirSupply(amount); super.setAirSupply(amount);

View file

@ -132,6 +132,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
} }
session.getUpstream().getSession().setCodec(packetCodec); session.getUpstream().getSession().setCodec(packetCodec);
// FIXME temporary until 1.20.80 is dropped
session.getPlayerEntity().resetAir();
return true; return true;
} }