Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Hardcore Mode #5216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private volatile boolean closed;

private GameMode gameMode = GameMode.SURVIVAL;
@Setter
private boolean hardcore = false;

/**
* Keeps track of the world name for respawning.
Expand Down Expand Up @@ -667,7 +669,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
@Setter
private int stepTicks = 0;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop tickEventLoop) {
this.geyser = geyser;
this.upstream = new UpstreamSession(bedrockServerSession);
Expand Down Expand Up @@ -1640,6 +1642,7 @@ private void startGame() {
startGamePacket.setUniqueEntityId(playerEntity.getGeyserId());
startGamePacket.setRuntimeEntityId(playerEntity.getGeyserId());
startGamePacket.setPlayerGameType(EntityUtils.toBedrockGamemode(gameMode));
startGamePacket.setHardcore(hardcore);
startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0));
startGamePacket.setRotation(Vector2f.from(1, 1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import net.kyori.adventure.key.Key;
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.SetPlayerGameTypePacket;
import org.geysermc.erosion.Constants;
Expand Down Expand Up @@ -83,13 +84,21 @@ public void translate(GeyserSession session, ClientboundLoginPacket packet) {
session.setWorldName(spawnInfo.getWorldName());
session.setLevels(Arrays.stream(packet.getWorldNames()).map(Key::asString).toArray(String[]::new));
session.setGameMode(spawnInfo.getGameMode());
session.setHardcore(packet.isHardcore());

boolean needsSpawnPacket = !session.isSentSpawnPacket();
if (needsSpawnPacket) {
// The player has yet to spawn so let's do that using some of the information in this Java packet
DimensionUtils.setBedrockDimension(session, newDimension.bedrockId());
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
session.getUpstream().sendPostStartGamePackets();
} else {
Expand Down
Loading