forked from GeyserMC/Geyser
Fix elytra flying in creative mode (#956)
Sending a ClientPlayerAbilitiesPacket allows the player to successfully fly. This commit also removes the setting of the CAN_FLY entity flag on creative mode. This did not break anything in my testing.
This commit is contained in:
parent
221e5bd103
commit
e5fc66d72f
3 changed files with 7 additions and 21 deletions
|
@ -26,9 +26,11 @@
|
||||||
package org.geysermc.connector.network.translators.bedrock;
|
package org.geysermc.connector.network.translators.bedrock;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerAbilitiesPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
@ -70,6 +72,11 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
||||||
session.sendDownstreamPacket(stopSwimPacket);
|
session.sendDownstreamPacket(stopSwimPacket);
|
||||||
break;
|
break;
|
||||||
case START_GLIDE:
|
case START_GLIDE:
|
||||||
|
// Otherwise gliding will not work in creative
|
||||||
|
ClientPlayerAbilitiesPacket playerAbilitiesPacket = new ClientPlayerAbilitiesPacket(
|
||||||
|
false, false, false, session.getGameMode() == GameMode.CREATIVE
|
||||||
|
);
|
||||||
|
session.sendDownstreamPacket(playerAbilitiesPacket);
|
||||||
case STOP_GLIDE:
|
case STOP_GLIDE:
|
||||||
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
||||||
session.sendDownstreamPacket(glidePacket);
|
session.sendDownstreamPacket(glidePacket);
|
||||||
|
|
|
@ -29,10 +29,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.Serv
|
||||||
import com.nukkitx.protocol.bedrock.data.AdventureSetting;
|
import com.nukkitx.protocol.bedrock.data.AdventureSetting;
|
||||||
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
|
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
@ -50,14 +47,6 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EntityDataMap metadata = entity.getMetadata();
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());
|
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
|
||||||
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
||||||
entityDataPacket.getMetadata().putAll(metadata);
|
|
||||||
session.sendUpstreamPacket(entityDataPacket);
|
|
||||||
|
|
||||||
Set<AdventureSetting> playerFlags = new ObjectOpenHashSet<>();
|
Set<AdventureSetting> playerFlags = new ObjectOpenHashSet<>();
|
||||||
playerFlags.add(AdventureSetting.AUTO_JUMP);
|
playerFlags.add(AdventureSetting.AUTO_JUMP);
|
||||||
if (packet.isCanFly())
|
if (packet.isCanFly())
|
||||||
|
|
|
@ -35,9 +35,7 @@ import com.nukkitx.protocol.bedrock.data.AdventureSetting;
|
||||||
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
|
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
|
@ -107,14 +105,6 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
||||||
session.sendUpstreamPacket(adventureSettingsPacket);
|
session.sendUpstreamPacket(adventureSettingsPacket);
|
||||||
}, 50, TimeUnit.MILLISECONDS);
|
}, 50, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
EntityDataMap metadata = entity.getMetadata();
|
|
||||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE);
|
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
|
||||||
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
||||||
entityDataPacket.getMetadata().putAll(metadata);
|
|
||||||
session.sendUpstreamPacket(entityDataPacket);
|
|
||||||
|
|
||||||
// Update the crafting grid to add/remove barriers for creative inventory
|
// Update the crafting grid to add/remove barriers for creative inventory
|
||||||
PlayerInventoryTranslator.updateCraftingGrid(session, session.getInventory());
|
PlayerInventoryTranslator.updateCraftingGrid(session, session.getInventory());
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue