Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-03 14:50:19 +01:00
Fix flying in creative mode
Flying with commands such as /fly will not work for now (it didn't in the first place). This will need to be addressed later.
Dieser Commit ist enthalten in:
Ursprung
7a4621cf51
Commit
faffa07e89
@ -126,7 +126,9 @@ public class TranslatorsInit {
|
|||||||
Registry.registerJava(ServerPlayerSetExperiencePacket.class, new JavaPlayerSetExperienceTranslator());
|
Registry.registerJava(ServerPlayerSetExperiencePacket.class, new JavaPlayerSetExperienceTranslator());
|
||||||
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
||||||
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
||||||
Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
|
|
||||||
|
// FIXME: This translator messes with allowing flight in creative mode. Will need to be addressed later
|
||||||
|
// Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
|
||||||
|
|
||||||
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
||||||
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
||||||
|
@ -28,9 +28,9 @@ package org.geysermc.connector.network.translators.java.world;
|
|||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
|
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
||||||
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.packet.ShowCreditsPacket;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
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;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
@ -41,6 +41,10 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerNotifyClientPacket packet, GeyserSession session) {
|
public void translate(ServerNotifyClientPacket packet, GeyserSession session) {
|
||||||
|
Entity entity = session.getPlayerEntity();
|
||||||
|
if (entity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (packet.getNotification()) {
|
switch (packet.getNotification()) {
|
||||||
case START_RAIN:
|
case START_RAIN:
|
||||||
LevelEventPacket startRainPacket = new LevelEventPacket();
|
LevelEventPacket startRainPacket = new LevelEventPacket();
|
||||||
@ -57,17 +61,35 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
session.getUpstream().sendPacket(stopRainPacket);
|
session.getUpstream().sendPacket(stopRainPacket);
|
||||||
break;
|
break;
|
||||||
case CHANGE_GAMEMODE:
|
case CHANGE_GAMEMODE:
|
||||||
|
int playerFlags = 0;
|
||||||
|
|
||||||
GameMode gameMode = (GameMode) packet.getValue();
|
GameMode gameMode = (GameMode) packet.getValue();
|
||||||
|
playerFlags = setPlayerFlag(0x01, gameMode == GameMode.ADVENTURE, playerFlags); // world immutable
|
||||||
|
playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump
|
||||||
|
playerFlags = setPlayerFlag(0x40, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR, playerFlags); // can fly
|
||||||
|
playerFlags = setPlayerFlag(0x80, gameMode == GameMode.SPECTATOR, playerFlags); // no clip
|
||||||
|
playerFlags = setPlayerFlag(0x200, gameMode == GameMode.SPECTATOR, playerFlags); // is flying
|
||||||
|
|
||||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||||
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
||||||
session.getUpstream().sendPacket(playerGameTypePacket);
|
session.getUpstream().sendPacket(playerGameTypePacket);
|
||||||
session.setGameMode(gameMode);
|
session.setGameMode(gameMode);
|
||||||
|
|
||||||
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||||
|
adventureSettingsPacket.setPlayerPermission(1);
|
||||||
|
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||||
|
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
||||||
|
session.getUpstream().sendPacket(adventureSettingsPacket);
|
||||||
|
|
||||||
|
EntityDataDictionary metadata = entity.getMetadata();
|
||||||
|
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR);
|
||||||
|
|
||||||
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
|
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
|
entityDataPacket.getMetadata().putAll(metadata);
|
||||||
|
session.getUpstream().sendPacket(entityDataPacket);
|
||||||
break;
|
break;
|
||||||
case ENTER_CREDITS:
|
case ENTER_CREDITS:
|
||||||
Entity entity = session.getPlayerEntity();
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket();
|
ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket();
|
||||||
showCreditsPacket.setStatus(ShowCreditsPacket.Status.START_CREDITS);
|
showCreditsPacket.setStatus(ShowCreditsPacket.Status.START_CREDITS);
|
||||||
showCreditsPacket.setRuntimeEntityId(entity.getGeyserId());
|
showCreditsPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
@ -77,4 +99,12 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int setPlayerFlag(int flag, boolean value, int playerFlags) {
|
||||||
|
if (value) {
|
||||||
|
return playerFlags | flag;
|
||||||
|
} else {
|
||||||
|
return playerFlags & ~flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren