forked from GeyserMC/Geyser
Bugfixes
This commit is contained in:
parent
89550a5ecb
commit
a7bd9da644
8 changed files with 43 additions and 7 deletions
|
@ -137,7 +137,7 @@ public class Entity {
|
|||
|
||||
public EntityDataDictionary getMetadata() {
|
||||
EntityFlags flags = new EntityFlags();
|
||||
flags.setFlag(EntityFlag.HAS_GRAVITY, true);
|
||||
flags.setFlag(EntityFlag.HAS_GRAVITY, !is(PlayerEntity.class) || as(PlayerEntity.class).isGravity());
|
||||
flags.setFlag(EntityFlag.HAS_COLLISION, true);
|
||||
flags.setFlag(EntityFlag.CAN_SHOW_NAME, true);
|
||||
flags.setFlag(EntityFlag.CAN_CLIMB, true);
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.github.steveice10.mc.auth.data.GameProfile;
|
|||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
|
@ -44,6 +45,7 @@ public class PlayerEntity extends Entity {
|
|||
private String username;
|
||||
private long lastSkinUpdate = -1;
|
||||
private boolean playerList = true;
|
||||
private boolean gravity = false;
|
||||
|
||||
private ItemData helmet;
|
||||
private ItemData chestplate;
|
||||
|
@ -74,6 +76,17 @@ public class PlayerEntity extends Entity {
|
|||
session.getUpstream().sendPacket(armorEquipmentPacket);
|
||||
}
|
||||
|
||||
public void enableGravity(GeyserSession session) {
|
||||
if (!gravity && session.getPlayerEntity().getGeyserId() == getGeyserId()) {
|
||||
gravity = true;
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
entityDataPacket.setRuntimeEntityId(geyserId);
|
||||
entityDataPacket.getMetadata().putAll(getMetadata());
|
||||
session.getUpstream().sendPacket(entityDataPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean despawnEntity(GeyserSession session) {
|
||||
super.despawnEntity(session);
|
||||
|
|
|
@ -16,6 +16,7 @@ public class UpstreamSession {
|
|||
@Getter private final BedrockServerSession session;
|
||||
private Queue<BedrockPacket> packets = new ConcurrentLinkedQueue<>();
|
||||
@Getter private boolean frozen = false;
|
||||
private boolean queueCleared = true;
|
||||
|
||||
public void sendPacket(@NonNull BedrockPacket packet) {
|
||||
if (frozen || !packets.isEmpty()) {
|
||||
|
@ -55,4 +56,20 @@ public class UpstreamSession {
|
|||
public InetSocketAddress getAddress() {
|
||||
return session.getAddress();
|
||||
}
|
||||
|
||||
public boolean hasQueue() {
|
||||
return !packets.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true the first time this method is called after the queue is empty.<br>
|
||||
* This will enable gravity because now the client is ready to explore
|
||||
*/
|
||||
public boolean isQueueCleared() {
|
||||
if (!hasQueue() && queueCleared) {
|
||||
queueCleared = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ public class TranslatorsInit {
|
|||
Registry.registerBedrock(MobEquipmentPacket.class, new BedrockMobEquipmentTranslator());
|
||||
Registry.registerBedrock(MovePlayerPacket.class, new BedrockMovePlayerTranslator());
|
||||
Registry.registerBedrock(PlayerActionPacket.class, new BedrockActionTranslator());
|
||||
Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitialized());
|
||||
Registry.registerBedrock(SetLocalPlayerAsInitializedPacket.class, new BedrockPlayerInitializedTranslator());
|
||||
Registry.registerBedrock(TextPacket.class, new BedrockTextTranslator());
|
||||
|
||||
itemTranslator = new ItemTranslator();
|
||||
|
|
|
@ -31,18 +31,24 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
|
|||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.PlayerEntity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.item.BedrockItem;
|
||||
|
||||
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
|
||||
|
||||
@Override
|
||||
public void translate(MovePlayerPacket packet, GeyserSession session) {
|
||||
Entity entity = session.getPlayerEntity();
|
||||
PlayerEntity entity = session.getPlayerEntity();
|
||||
if (entity == null || !session.isSpawned()) return;
|
||||
|
||||
// can cause invalid moves when packet queue is not empty
|
||||
if (session.getUpstream().hasQueue()) return;
|
||||
if (session.getUpstream().isQueueCleared()) {
|
||||
entity.enableGravity(session);
|
||||
}
|
||||
|
||||
if (!isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) {
|
||||
session.getConnector().getLogger().info("Recalculating position...");
|
||||
recalculatePosition(session, entity, entity.getPosition());
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;
|
|||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
||||
public class BedrockPlayerInitialized extends PacketTranslator<SetLocalPlayerAsInitializedPacket> {
|
||||
public class BedrockPlayerInitializedTranslator extends PacketTranslator<SetLocalPlayerAsInitializedPacket> {
|
||||
@Override
|
||||
public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession session) {
|
||||
if (session.getPlayerEntity().getGeyserId() == packet.getRuntimeEntityId()) {
|
|
@ -34,7 +34,7 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||
break;
|
||||
case UPDATE_HEALTH:
|
||||
bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE);
|
||||
bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE);
|
||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||
break;
|
||||
case REMOVE:
|
||||
|
|
|
@ -142,7 +142,7 @@ public class Scoreboard {
|
|||
boolean teamAdd = team != null && (team.getUpdateType() == ADD || team.getUpdateType() == UPDATE);
|
||||
boolean teamRemove = team != null && (team.getUpdateType() == REMOVE || team.getUpdateType() == UPDATE);
|
||||
|
||||
if (team != null && (team.getUpdateType() == REMOVE || inTeam)) score.setTeam(null);
|
||||
if (team != null && (team.getUpdateType() == REMOVE || !inTeam)) score.setTeam(null);
|
||||
|
||||
boolean add = (hasUpdate || globalAdd || teamAdd || teamRemove || score.getUpdateType() == ADD || score.getUpdateType() == UPDATE) && (score.getUpdateType() != REMOVE);
|
||||
boolean remove = hasUpdate || globalRemove || teamAdd || teamRemove || score.getUpdateType() == REMOVE || score.getUpdateType() == UPDATE;
|
||||
|
|
Loading…
Reference in a new issue