mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-03-25 00:07:31 +01:00
implement hardcore mode
This commit is contained in:
parent
ba5b4224d8
commit
0fe4bbcb38
2 changed files with 13 additions and 1 deletions
|
@ -368,6 +368,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
private volatile boolean closed;
|
private volatile boolean closed;
|
||||||
|
|
||||||
private GameMode gameMode = GameMode.SURVIVAL;
|
private GameMode gameMode = GameMode.SURVIVAL;
|
||||||
|
@Setter
|
||||||
|
private boolean hardcore = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps track of the world name for respawning.
|
* Keeps track of the world name for respawning.
|
||||||
|
@ -667,7 +669,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
@Setter
|
@Setter
|
||||||
private int stepTicks = 0;
|
private int stepTicks = 0;
|
||||||
|
|
||||||
|
|
||||||
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop tickEventLoop) {
|
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop tickEventLoop) {
|
||||||
this.geyser = geyser;
|
this.geyser = geyser;
|
||||||
this.upstream = new UpstreamSession(bedrockServerSession);
|
this.upstream = new UpstreamSession(bedrockServerSession);
|
||||||
|
@ -1640,6 +1642,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||||
startGamePacket.setUniqueEntityId(playerEntity.getGeyserId());
|
startGamePacket.setUniqueEntityId(playerEntity.getGeyserId());
|
||||||
startGamePacket.setRuntimeEntityId(playerEntity.getGeyserId());
|
startGamePacket.setRuntimeEntityId(playerEntity.getGeyserId());
|
||||||
startGamePacket.setPlayerGameType(EntityUtils.toBedrockGamemode(gameMode));
|
startGamePacket.setPlayerGameType(EntityUtils.toBedrockGamemode(gameMode));
|
||||||
|
startGamePacket.setHardcore(hardcore);
|
||||||
startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0));
|
startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0));
|
||||||
startGamePacket.setRotation(Vector2f.from(1, 1));
|
startGamePacket.setRotation(Vector2f.from(1, 1));
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ package org.geysermc.geyser.translator.protocol.java;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.GameRuleData;
|
import org.cloudburstmc.protocol.bedrock.data.GameRuleData;
|
||||||
|
import org.cloudburstmc.protocol.bedrock.packet.DeathInfoPacket;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.GameRulesChangedPacket;
|
import org.cloudburstmc.protocol.bedrock.packet.GameRulesChangedPacket;
|
||||||
import org.cloudburstmc.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
import org.cloudburstmc.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
||||||
import org.geysermc.erosion.Constants;
|
import org.geysermc.erosion.Constants;
|
||||||
|
@ -83,6 +84,7 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
|
||||||
session.setWorldName(spawnInfo.getWorldName());
|
session.setWorldName(spawnInfo.getWorldName());
|
||||||
session.setLevels(Arrays.stream(packet.getWorldNames()).map(Key::asString).toArray(String[]::new));
|
session.setLevels(Arrays.stream(packet.getWorldNames()).map(Key::asString).toArray(String[]::new));
|
||||||
session.setGameMode(spawnInfo.getGameMode());
|
session.setGameMode(spawnInfo.getGameMode());
|
||||||
|
session.setHardcore(packet.isHardcore());
|
||||||
|
|
||||||
boolean needsSpawnPacket = !session.isSentSpawnPacket();
|
boolean needsSpawnPacket = !session.isSentSpawnPacket();
|
||||||
if (needsSpawnPacket) {
|
if (needsSpawnPacket) {
|
||||||
|
@ -90,6 +92,13 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
|
||||||
DimensionUtils.setBedrockDimension(session, newDimension.bedrockId());
|
DimensionUtils.setBedrockDimension(session, newDimension.bedrockId());
|
||||||
session.connect();
|
session.connect();
|
||||||
|
|
||||||
|
// This is to ensure that you don't get stuck without a respawn screen in hardcore
|
||||||
|
if (!entity.isAlive()) {
|
||||||
|
DeathInfoPacket deathInfoPacket = new DeathInfoPacket();
|
||||||
|
deathInfoPacket.setCauseAttackName("");
|
||||||
|
session.sendUpstreamPacket(deathInfoPacket);
|
||||||
|
}
|
||||||
|
|
||||||
// It is now safe to send these packets
|
// It is now safe to send these packets
|
||||||
session.getUpstream().sendPostStartGamePackets();
|
session.getUpstream().sendPostStartGamePackets();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue