Show the poem and credits on a player's first End exit in server-thread mode
This commit is contained in:
@@ -77,6 +77,10 @@ pub(super) struct GuestPlay {
|
||||
last_inventory: u64,
|
||||
/// `Entity.portalProcess` and `portalCooldown` (game/server_travel.rs).
|
||||
pub(super) portal: horizon_client::nether_portal::PortalState,
|
||||
/// `ServerPlayer.wonGame`: the End poem is showing, the player waits for
|
||||
/// its client's PERFORM_RESPAWN (`respawn_requested`).
|
||||
pub(super) won_game: bool,
|
||||
pub(super) respawn_requested: bool,
|
||||
/// `Player.takeXpDelay`: ticks until the next orb can be taken.
|
||||
xp_delay: u32,
|
||||
/// What last killed the guest outright (`/kill`): the death message's key.
|
||||
@@ -1308,6 +1312,13 @@ impl Game<'_> {
|
||||
self.guest_suggestions(host, conn, &payload);
|
||||
}
|
||||
S::PlaceRecipe(p) => self.lan_place_recipe(host, conn, &p),
|
||||
// handleClientCommand: PERFORM_RESPAWN after the poem leaves the End
|
||||
// (the next server tick sends the player on).
|
||||
S::ClientCommand(c)
|
||||
if c.action == 0 && host.play.get(&conn).is_some_and(|p| p.won_game) =>
|
||||
{
|
||||
host.play.entry(conn).or_default().respawn_requested = true;
|
||||
}
|
||||
S::ClientCommand(c) if c.action == 0 => self.guest_respawn(host, conn),
|
||||
// ServerStatsCounter.sendStats.
|
||||
S::ClientCommand(c) if c.action == 1 => {
|
||||
|
||||
@@ -13,6 +13,7 @@ use super::respawn_anchor::RespawnConfig;
|
||||
use super::{Dim, Game, lan::LanHost};
|
||||
use horizon_client::{lan::hub::TickCtx, text::Text};
|
||||
use horizon_core::{geometry::Vec3, position::BlockPos};
|
||||
use horizon_protocol::packets::play::{self, Clientbound as C};
|
||||
|
||||
/// A trip under way: the player is in the destination's level, whose
|
||||
/// chunks are loading around `target`.
|
||||
@@ -103,8 +104,35 @@ impl Game<'_> {
|
||||
if let Some(pos) = self.nether_portal_inside(at) {
|
||||
self.portals.player.set_inside(pos, PLAYER_DELAY);
|
||||
}
|
||||
// `ServerPlayer.showEndCredits`: the player stays out of the world while the
|
||||
// poem rolls, then PERFORM_RESPAWN takes it to its respawn point.
|
||||
let play = host.play.entry(conn).or_default();
|
||||
if play.won_game {
|
||||
if std::mem::take(&mut play.respawn_requested) {
|
||||
play.won_game = false;
|
||||
self.start_server_trip(host, conn, Dim::Overworld, None);
|
||||
self.portals.player.cooldown = 10;
|
||||
}
|
||||
return;
|
||||
}
|
||||
let (end_portal, gateway) = self.inside_end_portals(at, WIDTH, HEIGHT);
|
||||
if end_portal {
|
||||
// EndPortalBlock.entityInside: the first exit from the End shows the credits.
|
||||
if self.dim == Dim::End && !host.hub.guest(conn).is_some_and(|g| g.seen_credits) {
|
||||
if let Some(g) = host.hub.guests.iter_mut().find(|g| g.conn == conn) {
|
||||
g.seen_credits = true;
|
||||
}
|
||||
host.play.entry(conn).or_default().won_game = true;
|
||||
// ClientboundGameEventPacket.WIN_GAME.
|
||||
host.hub.send_to(
|
||||
conn,
|
||||
&C::GameEvent(play::GameEvent {
|
||||
event: 4,
|
||||
param: 0.0,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if self.portals.player.cooldown == 0 {
|
||||
let target = if self.dim == Dim::End {
|
||||
Dim::Overworld
|
||||
|
||||
@@ -237,6 +237,8 @@ pub struct Guest {
|
||||
pub drag: Option<(u8, Vec<usize>)>,
|
||||
/// The compound this player was loaded from, for fields Horizon does not model.
|
||||
pub saved: Option<horizon_world::nbt::Tag>,
|
||||
/// `ServerPlayer.seenCredits`: the end poem has been shown.
|
||||
pub seen_credits: bool,
|
||||
/// `ServerPlayer.recipeBook`.
|
||||
pub recipe_book: crate::recipe_book::Settings,
|
||||
/// `PlayerAdvancements`: the criteria obtained, whether they came from
|
||||
@@ -358,6 +360,7 @@ impl Guest {
|
||||
next_window: 0,
|
||||
drag: None,
|
||||
saved: None,
|
||||
seen_credits: false,
|
||||
recipe_book: Default::default(),
|
||||
advancements: Default::default(),
|
||||
advancements_loaded: false,
|
||||
|
||||
@@ -85,6 +85,7 @@ pub fn apply(guest: &mut Guest, level: &Level) {
|
||||
.map(|s| [s[0] + 0.5, s[1], s[2] + 0.5]);
|
||||
guest.respawn_elsewhere = level.respawn_elsewhere.clone();
|
||||
guest.saved = level.player_extra.clone();
|
||||
guest.seen_credits = level.seen_credits;
|
||||
let extra = level.player_extra.as_ref();
|
||||
let short = |key: &str, default: i64| {
|
||||
extra
|
||||
@@ -166,6 +167,7 @@ pub fn store(guest: &Guest, level: &mut Level) {
|
||||
level.spawn = guest.spawn.map(|s| [s[0] - 0.5, s[1], s[2] - 0.5]);
|
||||
level.respawn_elsewhere = guest.respawn_elsewhere.clone();
|
||||
level.on_ground = guest.on_ground;
|
||||
level.seen_credits = guest.seen_credits;
|
||||
level.player_extra = guest.saved.clone();
|
||||
// The live body's fire, air and fall distance (Entity.saveWithoutId),
|
||||
// or what the file had while the player has no body yet.
|
||||
|
||||
Reference in New Issue
Block a user