Merge pull request #1410 from ludovic111/fix/setworldspawn
🤖 Agent: merged after verify passed; lan_e2e (absorption breath lava contacts shield deathmining worldspawn drops underwater beds minecarts levels) passes in both single-player modes on the top of the chain, plus clippy and the client tests.
This commit is contained in:
@@ -2337,7 +2337,19 @@ impl Game<'_> {
|
||||
Some(Arg::Coords(c)) => c.rotation(self.source_rotation()),
|
||||
_ => [0.0, 0.0],
|
||||
};
|
||||
self.level.spawn = Some([f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])]);
|
||||
// LevelData.setRespawnData: the world's spawn (level.dat `spawn`).
|
||||
let old = self.level.world_spawn.replace(pos);
|
||||
self.level.world_spawn_angle = rot;
|
||||
// A player whose respawn point is the world spawn (no bed, anchor or
|
||||
// spawnpoint of its own) respawns at the new one.
|
||||
let floor = |s: Vec3| [s.x.floor() as i32, s.y.floor() as i32, s.z.floor() as i32];
|
||||
if self.respawn_config.is_none() && self.spawn.map(floor) == old {
|
||||
self.spawn = Some(Vec3::new(
|
||||
f64::from(pos[0]) + 0.5,
|
||||
f64::from(pos[1]),
|
||||
f64::from(pos[2]) + 0.5,
|
||||
));
|
||||
}
|
||||
let args = [
|
||||
Text::literal(pos[0].to_string()),
|
||||
Text::literal(pos[1].to_string()),
|
||||
|
||||
@@ -72,7 +72,12 @@ pub fn apply(guest: &mut Guest, level: &Level) {
|
||||
guest.game_mode = level.mode();
|
||||
guest.flying = level.flying;
|
||||
guest.selected = (level.selected_slot.max(0) as usize).min(8);
|
||||
guest.spawn = level.spawn.map(|s| [s[0] + 0.5, s[1], s[2] + 0.5]);
|
||||
// A point that is the world spawn is none of the player's own: it
|
||||
// respawns wherever the world spawn is then (`setworldspawn`).
|
||||
guest.spawn = level
|
||||
.spawn
|
||||
.filter(|s| Some(s.map(|v| v.floor() as i32)) != level.world_spawn)
|
||||
.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.recipe_book = level.recipe_book.clone();
|
||||
|
||||
@@ -2292,6 +2292,8 @@ pub struct Level {
|
||||
pub dimension: String,
|
||||
/// World spawn (`level.dat` `spawn`), distinct from a bed respawn point.
|
||||
pub world_spawn: Option<[i32; 3]>,
|
||||
/// The world spawn's yaw and pitch (`setworldspawn`'s rotation).
|
||||
pub world_spawn_angle: [f32; 2],
|
||||
pub difficulty: String,
|
||||
pub hardcore: bool,
|
||||
/// `difficulty_settings.locked` (LevelData.isDifficultyLocked).
|
||||
@@ -2369,6 +2371,11 @@ impl Level {
|
||||
]
|
||||
}),
|
||||
};
|
||||
let angle = |k: &str| match data.get("spawn").and_then(|s| s.get(k)) {
|
||||
Some(Tag::Float(b)) => f32::from_bits(*b),
|
||||
_ => 0.0,
|
||||
};
|
||||
level.world_spawn_angle = [angle("yaw"), angle("pitch")];
|
||||
if let Some(d) = data.get("difficulty_settings") {
|
||||
level.difficulty = text(d.get("difficulty")).unwrap_or_else(|| "normal".into());
|
||||
level.hardcore = n(d.get("hardcore")) != 0;
|
||||
@@ -2864,8 +2871,8 @@ impl Level {
|
||||
Tag::compound([
|
||||
("pos", Tag::IntArray(spawn.to_vec())),
|
||||
("dimension", string("minecraft:overworld")),
|
||||
("yaw", Tag::Float(0f32.to_bits())),
|
||||
("pitch", Tag::Float(0f32.to_bits())),
|
||||
("yaw", Tag::Float(self.world_spawn_angle[0].to_bits())),
|
||||
("pitch", Tag::Float(self.world_spawn_angle[1].to_bits())),
|
||||
]),
|
||||
),
|
||||
("difficulty_settings", difficulty),
|
||||
@@ -4134,6 +4141,7 @@ mod tests {
|
||||
xp_total: 30,
|
||||
dimension: "minecraft:the_nether".into(),
|
||||
world_spawn: Some([8, 64, 8]),
|
||||
world_spawn_angle: [45.0, -10.0],
|
||||
spawn: Some([20.0, 70.0, 20.0]),
|
||||
difficulty_locked: true,
|
||||
flying: true,
|
||||
@@ -4169,6 +4177,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(back.dimension, "minecraft:the_nether");
|
||||
assert_eq!(back.world_spawn, Some([8, 64, 8]));
|
||||
assert_eq!(back.world_spawn_angle, [45.0, -10.0]);
|
||||
assert_eq!(back.spawn, Some([20.0, 70.0, 20.0]));
|
||||
assert!(back.difficulty_locked);
|
||||
assert!(back.weather.raining);
|
||||
|
||||
+38
-4
@@ -138,6 +138,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
get off by sneaking; the other side sees the animal move.
|
||||
- lightning: a bolt summoned beside the host, then the guest: both sides get the bolt and flash the
|
||||
sky (on its server thread the host's window is a client of it too).
|
||||
- worldspawn: the host moves the world spawn (`setworldspawn`): the host and the guest, with no bed,
|
||||
respawn there (#1310).
|
||||
- shield: the host axes the guest's raised shield, then the guest the host's: it stays disabled
|
||||
for 5 s on that player's own cooldown, then blocks again (#1316).
|
||||
- deathmining: the host and the guest each die while breaking obsidian and let go on the death
|
||||
@@ -192,7 +194,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
GUEST_NAME = 'Guest'
|
||||
# The host plays single player on its server thread (--server-thread).
|
||||
SERVER_THREAD = False
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning', 'riding', 'mounts', 'worldspawn', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -2604,6 +2606,8 @@ def check_flight(host, guest, out):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def own(game):
|
||||
"""The player's own state, as its client has it."""
|
||||
return game('state')['player']
|
||||
@@ -2743,6 +2747,36 @@ def respawn_when_ready(game):
|
||||
return game.raw('respawn')
|
||||
|
||||
|
||||
def check_world_spawn(host, guest, out):
|
||||
"""`setworldspawn` moves the world spawn: the host and the guest, with no bed of their own,
|
||||
respawn there once killed (#1310)."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
sx, sz = hx + 24, hz
|
||||
host('command', command='gamerule respawn_radius 0')
|
||||
host('command', command=f'fill {sx - 2} {hy - 1} {sz - 2} {sx + 2} {hy - 1} {sz + 2} minecraft:stone')
|
||||
host('command', command=f'fill {sx - 2} {hy} {sz - 2} {sx + 2} {hy + 3} {sz + 2} minecraft:air')
|
||||
seen = {}
|
||||
try:
|
||||
host('command', command=f'setworldspawn {sx} {hy} {sz}')
|
||||
for game in (host, guest):
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='kill @s')
|
||||
game.wait(20)
|
||||
respawn_when_ready(game)
|
||||
game.wait(60)
|
||||
seen[game.name] = [round(v, 2) for v in pos_of(game)]
|
||||
game.shot(out, 'world-spawn')
|
||||
finally:
|
||||
host('command', command=f'setworldspawn {hx} {hy} {hz}')
|
||||
host('command', command='gamerule respawn_radius 10')
|
||||
for game in (host, guest):
|
||||
game('command', command=f'tp @s {hx + 0.5} {hy} {hz + 0.5}')
|
||||
guest.wait(20)
|
||||
for name, at in seen.items():
|
||||
assert abs(at[0] - (sx + 0.5)) < 1 and abs(at[2] - (sz + 0.5)) < 1, f'{name}: {seen}, spawn {sx} {sz}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_death_mining(host, guest, out):
|
||||
"""A player who dies while breaking obsidian, and lets go of attack on the death screen, doesn't
|
||||
break it once respawned: death forgets the digging (#1315)."""
|
||||
@@ -3664,9 +3698,9 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'light': check_light, 'plates': check_plates,
|
||||
'swings': check_swings, 'cracks': check_cracks,
|
||||
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder, 'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'lightning': check_lightning, 'riding': check_riding, 'mounts': check_mounts,
|
||||
'shield': check_shield, 'deathmining': check_death_mining, 'contacts': check_contacts,
|
||||
'absorption': check_absorption, 'breath': check_breath, 'lava': check_lava,
|
||||
'levels': check_levels}
|
||||
'worldspawn': check_world_spawn, 'shield': check_shield, 'deathmining': check_death_mining,
|
||||
'contacts': check_contacts, 'absorption': check_absorption, 'breath': check_breath,
|
||||
'lava': check_lava, 'levels': check_levels}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user