Merge origin/main into t3/fix-critical-hit-particles
Keep both critical-hit and replant regressions. Co-Authored-By: OpenCode (agentrouter/gpt-6.1-sol) <noreply@openai.com>
This commit is contained in:
@@ -29,7 +29,8 @@ env:
|
||||
|
||||
jobs:
|
||||
audit:
|
||||
runs-on: [self-hosted, horizon-game]
|
||||
# The Mac mini's runners only: the audit compares with the previous one, so it stays on one platform.
|
||||
runs-on: [self-hosted, horizon-game, macOS]
|
||||
timeout-minutes: 150
|
||||
steps:
|
||||
- name: 03:00 in Paris
|
||||
|
||||
@@ -23,7 +23,9 @@ env:
|
||||
|
||||
jobs:
|
||||
parity-main:
|
||||
runs-on: [self-hosted, horizon-game]
|
||||
# The Mac mini's runners only: a desktop job slowed down because the maintainer came back could time out, and a
|
||||
# failure here bisects and comments on merges.
|
||||
runs-on: [self-hosted, horizon-game, macOS]
|
||||
timeout-minutes: 240 # a core-crate batch reruns ~300 harnesses (~60-90 min), a bisect a few rounds of the failures
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
Generated
+2
@@ -1408,6 +1408,8 @@ dependencies = [
|
||||
name = "horizon-prepare"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"regex",
|
||||
"sha1",
|
||||
"sha2",
|
||||
|
||||
@@ -598,6 +598,7 @@ fn print(out: &mut String, t: i32, i: usize, m: &Mob, player_down: bool, now: i6
|
||||
let _ = writeln!(out, " removed {reason}");
|
||||
return;
|
||||
}
|
||||
let _ = write!(out, "\tleashed {}", u8::from(m.extra.leash.is_some()));
|
||||
let p = m.position;
|
||||
let v = m.velocity;
|
||||
let _ = write!(
|
||||
@@ -977,6 +978,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
}
|
||||
// Set once the brain exists (below).
|
||||
x if x.starts_with("cooldown=") => {}
|
||||
"dead" => m.health = 0.0,
|
||||
"leashed" => m.extra.leash = Some(horizon_client::mobs::leash::Holder::Player),
|
||||
x if x.starts_with("leashto=") => {
|
||||
let n: u32 = x[8..].parse().unwrap();
|
||||
@@ -1097,6 +1099,7 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
}
|
||||
};
|
||||
}
|
||||
let mut dropped_leads = 0;
|
||||
for t in 1..=s.ticks {
|
||||
world.game_time += 1;
|
||||
if s.daycycle {
|
||||
@@ -1208,6 +1211,16 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
if !alive {
|
||||
m.removed = true;
|
||||
}
|
||||
// Apply the same detach/drop event as Game::break_leash.
|
||||
for event in &events[from..] {
|
||||
if let MobEvent::LeashBreak { mob, drop, .. } = event
|
||||
&& let Some(m) = mobs.iter_mut().find(|m| m.id == *mob)
|
||||
&& horizon_client::mobs::leash::remove(m).is_some()
|
||||
&& *drop
|
||||
{
|
||||
dropped_leads += 1;
|
||||
}
|
||||
}
|
||||
horizon_client::mobs::apply_brain_events(&mut mobs, &mut events, from);
|
||||
villager_events(
|
||||
&mut mobs,
|
||||
@@ -1427,6 +1440,9 @@ pub fn main() -> horizon_client::Result<()> {
|
||||
world.game_time,
|
||||
);
|
||||
}
|
||||
if s.name.starts_with("leash_death_") {
|
||||
let _ = writeln!(out, "{t} leads {dropped_leads}");
|
||||
}
|
||||
for e in &events {
|
||||
if let MobEvent::Sound(name, _, volume, pitch) = e {
|
||||
let _ = writeln!(
|
||||
|
||||
@@ -33,7 +33,11 @@ impl Cost {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Enchantment {
|
||||
pub id: Arc<str>,
|
||||
/// The name the pinned English map gave at load: the fallback for a
|
||||
/// language that has no entry for the key below.
|
||||
pub description: String,
|
||||
/// `description`'s translation key (`enchantment.minecraft.<name>`).
|
||||
pub description_key: String,
|
||||
pub max_level: u32,
|
||||
pub weight: u32,
|
||||
pub anvil_cost: u32,
|
||||
@@ -224,6 +228,7 @@ impl Enchantments {
|
||||
.get(key)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| id.trim_start_matches("minecraft:").replace('_', " ")),
|
||||
description_key: key.to_owned(),
|
||||
max_level: v["max_level"].as_u64().unwrap_or(1) as u32,
|
||||
weight: v["weight"].as_u64().unwrap_or(1) as u32,
|
||||
anvil_cost: v["anvil_cost"].as_u64().unwrap_or(0) as u32,
|
||||
@@ -329,16 +334,26 @@ impl Enchantments {
|
||||
}
|
||||
/// `Enchantment.getFullname` as plain text and whether it is a curse (red).
|
||||
pub fn full_name(&self, id: &str, level: u32) -> (String, bool) {
|
||||
let language = crate::lang::current();
|
||||
self.full_name_in(language.as_deref(), id, level)
|
||||
}
|
||||
/// `full_name` against `language`; `None` (no language loaded: a
|
||||
/// dedicated server, the probes) keeps the English names loaded above.
|
||||
pub fn full_name_in(
|
||||
&self,
|
||||
language: Option<&crate::lang::Language>,
|
||||
id: &str,
|
||||
level: u32,
|
||||
) -> (String, bool) {
|
||||
let tr = |key: &str| language.and_then(|l| l.get(key).map(str::to_owned));
|
||||
let Some(e) = self.get(id) else {
|
||||
return (format!("{id} {}", level_name(level)), false);
|
||||
};
|
||||
let mut name = e.description.clone();
|
||||
let mut name = tr(&e.description_key).unwrap_or_else(|| e.description.clone());
|
||||
if level != 1 || e.max_level != 1 {
|
||||
name.push(' ');
|
||||
name.push_str(
|
||||
self.lang
|
||||
.get(&format!("enchantment.level.{level}"))
|
||||
.map_or(&level_name(level), |s| s),
|
||||
&tr(&format!("enchantment.level.{level}")).unwrap_or_else(|| level_name(level)),
|
||||
);
|
||||
}
|
||||
(name, self.is_curse(id))
|
||||
@@ -771,7 +786,7 @@ pub(crate) mod tests {
|
||||
let defs = [
|
||||
(
|
||||
"minecraft:sharpness",
|
||||
json!({"anvil_cost":1,"exclusive_set":"#minecraft:exclusive_set/damage","max_cost":{"base":21,"per_level_above_first":11},"max_level":5,"min_cost":{"base":1,"per_level_above_first":11},"primary_items":"#minecraft:enchantable/melee_weapon","supported_items":"#minecraft:enchantable/sharp_weapon","weight":10,"slots":["mainhand"],"effects":{"minecraft:damage":[{"effect":{"type":"minecraft:add","value":{"type":"minecraft:linear","base":1.0,"per_level_above_first":0.5}}}]}}),
|
||||
json!({"anvil_cost":1,"description":{"translate":"enchantment.minecraft.sharpness"},"exclusive_set":"#minecraft:exclusive_set/damage","max_cost":{"base":21,"per_level_above_first":11},"max_level":5,"min_cost":{"base":1,"per_level_above_first":11},"primary_items":"#minecraft:enchantable/melee_weapon","supported_items":"#minecraft:enchantable/sharp_weapon","weight":10,"slots":["mainhand"],"effects":{"minecraft:damage":[{"effect":{"type":"minecraft:add","value":{"type":"minecraft:linear","base":1.0,"per_level_above_first":0.5}}}]}}),
|
||||
),
|
||||
(
|
||||
"minecraft:smite",
|
||||
@@ -795,6 +810,7 @@ pub(crate) mod tests {
|
||||
.map(|(id, v)| Enchantment {
|
||||
id: Arc::from(*id),
|
||||
description: id.trim_start_matches("minecraft:").into(),
|
||||
description_key: v["description"]["translate"].as_str().unwrap_or("").into(),
|
||||
max_level: v["max_level"].as_u64().unwrap() as u32,
|
||||
weight: v["weight"].as_u64().unwrap() as u32,
|
||||
anvil_cost: v["anvil_cost"].as_u64().unwrap() as u32,
|
||||
@@ -1088,4 +1104,33 @@ pub(crate) mod tests {
|
||||
assert!(!e.compatible("minecraft:sharpness", "minecraft:smite"));
|
||||
assert!(e.compatible("minecraft:sharpness", "minecraft:unbreaking"));
|
||||
}
|
||||
|
||||
/// The enchantment's name and its level come from the selected language,
|
||||
/// with the English name loaded above as the fallback.
|
||||
#[test]
|
||||
fn names_follow_the_language() {
|
||||
struct Mem(HashMap<String, Vec<u8>>);
|
||||
impl crate::lang::ResourceSource for Mem {
|
||||
fn read(&self, path: &str) -> Option<Vec<u8>> {
|
||||
self.0.get(path).cloned()
|
||||
}
|
||||
}
|
||||
let ru = Mem(HashMap::from([(
|
||||
"assets/minecraft/lang/ru_ru.json".to_owned(),
|
||||
r#"{"enchantment.minecraft.sharpness":"Острота","enchantment.level.5":"V"}"#
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
)]));
|
||||
let ru = crate::lang::Language::load(&[&ru], "ru_ru");
|
||||
let e = sample();
|
||||
assert_eq!(
|
||||
e.full_name_in(Some(&ru), "minecraft:sharpness", 5).0,
|
||||
"Острота V"
|
||||
);
|
||||
// mending carries no key in the fixture: the English name stays.
|
||||
assert_eq!(
|
||||
e.full_name_in(Some(&ru), "minecraft:mending", 1).0,
|
||||
"mending"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2772,7 +2772,13 @@ impl Game<'_> {
|
||||
}
|
||||
_ => 1.0,
|
||||
};
|
||||
self.audio.play(name, c, volume, pitch);
|
||||
if matches!(id, 1029 | 1030) {
|
||||
// Clients play the anvil sound from its level event;
|
||||
// capturing it also sends a duplicate sound packet.
|
||||
self.audio.play_unshared(name, c, volume, pitch);
|
||||
} else {
|
||||
self.audio.play(name, c, volume, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
LevelEvent::Sound {
|
||||
|
||||
@@ -1137,9 +1137,9 @@ impl Game<'_> {
|
||||
for e in events {
|
||||
if let horizon_world::level::LevelEvent::LevelEvent { id, pos, data } = e {
|
||||
// The acting guest does not predict the egg's teleport
|
||||
// particles, nor bone meal's growth (BoneMealItem.useOn's
|
||||
// levelEvent names no player).
|
||||
let except = if matches!(*id, 2015 | 1505) {
|
||||
// particles, bone meal's growth, or anvil result sounds
|
||||
// (these levelEvent calls name no excluded player).
|
||||
let except = if matches!(*id, 2015 | 1505 | 1029 | 1030) {
|
||||
None
|
||||
} else {
|
||||
self.lan_acting
|
||||
|
||||
@@ -1808,14 +1808,13 @@ impl Game<'_> {
|
||||
g.use_delay -= 1;
|
||||
}
|
||||
});
|
||||
// ServerPlayerGameMode.handleBlockBreakAction: a creative
|
||||
// player's START breaks the block once (destroyAndAck) and
|
||||
// leaves nothing being destroyed; its client sends no STOP.
|
||||
// Kept, the dig broke whatever was put there next, every
|
||||
// destroy delay, for as long as the player broke nothing else.
|
||||
// ServerPlayerGameMode.handleBlockBreakAction: creative and
|
||||
// instant survival STARTs finish without a STOP from the client.
|
||||
// tick_mining clears mining on completion; forget the START too,
|
||||
// so a flower or crop planted here later is not broken again.
|
||||
if digging.is_some()
|
||||
&& host.hub.guests[gi].creative()
|
||||
&& let Some(play) = host.play.get_mut(&conn)
|
||||
&& (host.hub.guests[gi].creative() || play.mining.is_none())
|
||||
{
|
||||
play.digging = None;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,8 @@ impl Game<'_> {
|
||||
if horizon_client::mobs::leash::remove(m).is_none() {
|
||||
return;
|
||||
}
|
||||
// Leashable.tickLeash gates a dying entity's lead drop on entity_drops.
|
||||
let drop = drop && (m.alive() || self.ui.rules.bool("entity_drops"));
|
||||
let at = [m.position.x, m.position.y, m.position.z];
|
||||
if sound {
|
||||
self.lead_sound("break", at);
|
||||
|
||||
@@ -484,30 +484,28 @@ impl Game<'_> {
|
||||
}
|
||||
|
||||
/// A `ui` screen's title and widgets as the mod last pushed them; None
|
||||
/// when the surface is gone (the mod stopped or closed it).
|
||||
fn mod_ui_view(&self) -> Option<(String, Vec<UiWidget>)> {
|
||||
let ms = self.mods.screen.as_ref()?;
|
||||
/// when the surface is gone (the mod stopped or closed it). Borrows
|
||||
/// `mods` only, so `self.mods.screen` may stay borrowed for the scrolls.
|
||||
fn mod_ui_view<'a>(mods: &'a Mods, ms: &ModScreen) -> Option<(&'a str, &'a [UiWidget])> {
|
||||
if ms.settings {
|
||||
let widgets = self.mods.mods.settings_widgets(ms.owner);
|
||||
let widgets = mods.settings_widgets(ms.owner);
|
||||
if widgets.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let name = self
|
||||
.mods
|
||||
.mods
|
||||
let name = mods
|
||||
.entries()
|
||||
.get(ms.owner)
|
||||
.and_then(|e| e.manifest.as_ref())
|
||||
.map_or("Mod", |m| m.name.as_str());
|
||||
Some((name.to_string(), widgets.to_vec()))
|
||||
Some((name, widgets))
|
||||
} else {
|
||||
let s: &UiScreen = self.mods.mods.screen(ms.owner)?;
|
||||
Some((s.title.clone(), s.widgets.clone()))
|
||||
let s: &UiScreen = mods.screen(ms.owner)?;
|
||||
Some((s.title.as_str(), s.widgets.as_slice()))
|
||||
}
|
||||
}
|
||||
/// The layout the mod screen's widgets get at `h`: (widget, top,
|
||||
/// height), the column being `COLUMN` wide down the middle.
|
||||
fn mod_ui_layout(&self, h: f32, widgets: &[UiWidget]) -> Vec<(f32, f32)> {
|
||||
fn mod_ui_layout(h: f32, widgets: &[UiWidget]) -> Vec<(f32, f32)> {
|
||||
let mut out = Vec::with_capacity(widgets.len());
|
||||
let mut y = MOD_UI_TOP;
|
||||
for w in widgets {
|
||||
@@ -572,13 +570,19 @@ impl Game<'_> {
|
||||
/// The mod's screen or settings page: its title over widgets stacked
|
||||
/// down the middle, a Done button, Esc to leave (vanilla's menus).
|
||||
pub(super) fn draw_mod_screen(&mut self, batch: &mut HudBatch) {
|
||||
if self.mods.screen.is_none() {
|
||||
let Some(ms) = self.mods.screen.as_mut() else {
|
||||
// The screen was dropped while it was up: back to the world,
|
||||
// mouse held again like any return to Playing.
|
||||
self.screen = Screen::Playing;
|
||||
if self.player.is_some() {
|
||||
self.capture(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some((title, widgets)) = self.mod_ui_view() else {
|
||||
self.mods.screen = None;
|
||||
self.screen = Screen::Playing;
|
||||
};
|
||||
let Some((title, widgets)) = Self::mod_ui_view(&self.mods.mods, ms) else {
|
||||
// The mod's surface is gone (it stopped or cleared it): leave
|
||||
// the screen like Done did, without `closed` — the mod ended it.
|
||||
self.close_mod_screen(false);
|
||||
return;
|
||||
};
|
||||
// Item icons draw in a second pass: `draw_item` needs `&mut self`,
|
||||
@@ -598,7 +602,7 @@ impl Game<'_> {
|
||||
);
|
||||
let cx = (batch.width / 2.0).floor();
|
||||
let x = cx - MOD_UI_COLUMN / 2.0;
|
||||
let layout = self.mod_ui_layout(batch.height, &widgets);
|
||||
let layout = Self::mod_ui_layout(batch.height, widgets);
|
||||
let mut list_i = 0usize;
|
||||
for (w, &(wy, wh)) in widgets.iter().zip(&layout) {
|
||||
match w {
|
||||
@@ -639,11 +643,8 @@ impl Game<'_> {
|
||||
);
|
||||
}
|
||||
UiWidget::List(l) => {
|
||||
let scroll = {
|
||||
let ms = self.mods.screen.as_mut().expect("checked");
|
||||
ms.scrolls.resize_with(list_i + 1, ui::Scroll::default);
|
||||
ms.scrolls[list_i]
|
||||
};
|
||||
ms.scrolls.resize_with(list_i + 1, ui::Scroll::default);
|
||||
let scroll = ms.scrolls[list_i];
|
||||
list_i += 1;
|
||||
let rows_top = wy + 4.0;
|
||||
let rows_bottom = wy + wh - 4.0;
|
||||
@@ -714,53 +715,53 @@ impl Game<'_> {
|
||||
self.close_mod_screen(true);
|
||||
return;
|
||||
}
|
||||
let Some((_, widgets)) = self.mod_ui_view() else {
|
||||
let Some(ms) = self.mods.screen.as_ref() else {
|
||||
return;
|
||||
};
|
||||
let Some((_, widgets)) = Self::mod_ui_view(&self.mods.mods, ms) else {
|
||||
return;
|
||||
};
|
||||
let owner = ms.owner;
|
||||
let x = (w / 2.0).floor() - MOD_UI_COLUMN / 2.0;
|
||||
let layout = self.mod_ui_layout(h, &widgets);
|
||||
let layout = Self::mod_ui_layout(h, widgets);
|
||||
let mut list_i = 0usize;
|
||||
// The `ui_select` call needs `&mut`: find the pick first.
|
||||
let mut hit = None;
|
||||
for (w, &(wy, wh)) in widgets.iter().zip(&layout) {
|
||||
let UiWidget::List(l) = w else { continue };
|
||||
let scroll = self
|
||||
.mods
|
||||
.screen
|
||||
.as_ref()
|
||||
.and_then(|ms| ms.scrolls.get(list_i).copied())
|
||||
.unwrap_or_default();
|
||||
let scroll = ms.scrolls.get(list_i).copied().unwrap_or_default();
|
||||
list_i += 1;
|
||||
let row = ((cursor.1 - (wy + 4.0) + scroll.amount) / 12.0) as i64;
|
||||
if ui::hovered(cursor, x + 1.0, wy + 1.0, MOD_UI_COLUMN - 7.0, wh - 2.0)
|
||||
&& row >= 0
|
||||
&& (row as usize) < l.rows.len()
|
||||
{
|
||||
self.audio.play_button_click();
|
||||
self.mods.mods.ui_select(
|
||||
self.mods.screen.as_ref().map_or(0, |ms| ms.owner),
|
||||
l.id,
|
||||
row as u32,
|
||||
);
|
||||
self.show_mod_output();
|
||||
return;
|
||||
hit = Some((l.id, row as u32));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some((id, row)) = hit {
|
||||
self.audio.play_button_click();
|
||||
self.mods.mods.ui_select(owner, id, row);
|
||||
self.show_mod_output();
|
||||
}
|
||||
}
|
||||
/// The wheel over a `list` scrolls it.
|
||||
pub(super) fn mod_screen_scroll(&mut self, delta: f32) {
|
||||
let (w, h) = self.gui_size();
|
||||
let cursor = self.cursor;
|
||||
let Some((_, widgets)) = self.mod_ui_view() else {
|
||||
let Some(ms) = self.mods.screen.as_mut() else {
|
||||
return;
|
||||
};
|
||||
let Some((_, widgets)) = Self::mod_ui_view(&self.mods.mods, ms) else {
|
||||
return;
|
||||
};
|
||||
let x = (w / 2.0).floor() - MOD_UI_COLUMN / 2.0;
|
||||
let layout = self.mod_ui_layout(h, &widgets);
|
||||
let layout = Self::mod_ui_layout(h, widgets);
|
||||
let mut list_i = 0usize;
|
||||
for (w, &(wy, wh)) in widgets.iter().zip(&layout) {
|
||||
let UiWidget::List(l) = w else { continue };
|
||||
let over = ui::hovered(cursor, x, wy, MOD_UI_COLUMN, wh);
|
||||
let Some(ms) = self.mods.screen.as_mut() else {
|
||||
return;
|
||||
};
|
||||
ms.scrolls.resize_with(list_i + 1, ui::Scroll::default);
|
||||
if over {
|
||||
let content = l.rows.len() as f32 * 12.0;
|
||||
|
||||
@@ -240,6 +240,42 @@ impl Game<'_> {
|
||||
discrete: false,
|
||||
});
|
||||
}
|
||||
// ItemFrameRenderer.shouldShowName/getNameTag: only the targeted
|
||||
// frame's custom-named item, with the HUD visible (also glow frames).
|
||||
if !self.ui.hide_gui
|
||||
&& let Some((i, distance)) = self.frame_hit()
|
||||
&& self.before_block(distance)
|
||||
&& self.mob_hit().is_none_or(|(_, d)| d > distance)
|
||||
&& let Some(name) = self.item_frames[i]
|
||||
.item
|
||||
.as_ref()
|
||||
.and_then(|item| item.custom_name())
|
||||
{
|
||||
let frame = &self.item_frames[i];
|
||||
let (lo, hi) = frame.bounds();
|
||||
let center = glam::DVec3::from_array(std::array::from_fn(|a| (lo[a] + hi[a]) / 2.0));
|
||||
if center.distance_squared(camera) < 64.0 * 64.0 {
|
||||
// NAME_TAG is at the entity height (0.5), then the name
|
||||
// submitter lifts it 0.5. ItemFrameRenderer offsets rendering
|
||||
// 0.3 toward its facing and -0.25 vertically.
|
||||
let step = frame.step();
|
||||
tags.push(NameTag {
|
||||
at: center
|
||||
+ glam::DVec3::new(
|
||||
f64::from(step[0] as f32 * 0.3),
|
||||
0.75,
|
||||
f64::from(step[2] as f32 * 0.3),
|
||||
),
|
||||
lines: vec![(Text::literal(name).resolve_legacy(), 0.0)],
|
||||
light: self.world.light(
|
||||
center.x.floor() as i32,
|
||||
center.y.floor() as i32,
|
||||
center.z.floor() as i32,
|
||||
),
|
||||
discrete: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
tags
|
||||
}
|
||||
/// `SubmitNodeCollection.submitNameTag`: a discrete name is drawn once,
|
||||
|
||||
@@ -142,6 +142,8 @@ impl Game<'_> {
|
||||
}
|
||||
let server = &self.server_packs.active;
|
||||
let root = startup_root(&vanilla, &self.settings.resource_packs, server)?;
|
||||
let root =
|
||||
super::mods::content_root(&root, &self.settings.mods.enabled, &self.options.dev_mods);
|
||||
self.reload_resources(&root)
|
||||
}
|
||||
fn reload_resources(&mut self, root: &Path) -> horizon_client::Result<()> {
|
||||
@@ -192,6 +194,10 @@ impl Game<'_> {
|
||||
let context = pack.context.clone();
|
||||
self.pack = pack;
|
||||
self.gui = gui;
|
||||
// The atlas's sprites moved: the particle engine re-reads every rect
|
||||
// and the packs' sprite sets, or every particle draws a stale region.
|
||||
self.particles
|
||||
.reload(root, &self.gui.atlas.sprites, &self.gui.atlas.translucent);
|
||||
horizon_client::ui_theme::reset_atlas();
|
||||
// Villager hats come from the pack's texture metadata (shared data, swapped in place).
|
||||
*self
|
||||
|
||||
@@ -261,11 +261,17 @@ impl PlayerHealth {
|
||||
self.hurt_animation_time = 10;
|
||||
}
|
||||
/// `LocalPlayer.hurtTo` with `flashOnSetHealth`: a drop below the current
|
||||
/// health starts the hurt animation.
|
||||
/// health starts the hurt animation; `damageCooldownTime` (20 on a drop,
|
||||
/// 10 on a gain) is what lets `Hud.extractPlayerHealth` blink the hearts.
|
||||
pub fn flash_health_change(&mut self, health: f32) {
|
||||
let damage = self.health() - health;
|
||||
if damage > 0.0 {
|
||||
if damage <= 0.0 {
|
||||
if damage < 0.0 {
|
||||
self.hurt.cooldown = 10;
|
||||
}
|
||||
} else {
|
||||
self.hurt.last_hurt = damage;
|
||||
self.hurt.cooldown = 20;
|
||||
self.animate_hurt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +198,15 @@ pub fn tick(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
m.extra.leash_spin = 0.0;
|
||||
return;
|
||||
};
|
||||
// Leashable.tickLeash: a dying entity cannot interact with the level.
|
||||
if !m.alive() {
|
||||
events.push(MobEvent::LeashBreak {
|
||||
mob: m.id,
|
||||
drop: true,
|
||||
sound: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
let Some(state) = holder_state(w, holder) else {
|
||||
// The holder is gone: the lead drops.
|
||||
if !matches!(holder, Holder::Player) {
|
||||
|
||||
@@ -3076,8 +3076,13 @@ mod tests {
|
||||
if client_side {
|
||||
w.player.health.flash_health_change(20.0);
|
||||
assert_eq!(w.player.health.hurt_animation_time, 0);
|
||||
assert_eq!(w.player.health.hurt.cooldown, 0);
|
||||
w.player.health.flash_health_change(12.0);
|
||||
assert_eq!(w.player.health.hurt_animation_time, 10);
|
||||
// LocalPlayer.hurtTo's damageCooldownTime: the HUD's hearts blink.
|
||||
assert_eq!(w.player.health.hurt.cooldown, 20);
|
||||
w.player.health.flash_health_change(25.0);
|
||||
assert_eq!(w.player.health.hurt.cooldown, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1212,10 +1212,7 @@ impl ParticleEngine {
|
||||
requested: None,
|
||||
names: Vec::new(),
|
||||
rects: Vec::new(),
|
||||
atlas: atlas
|
||||
.iter()
|
||||
.map(|(name, &rect)| (name.clone(), (rect, translucent.contains(name))))
|
||||
.collect(),
|
||||
atlas: HashMap::new(),
|
||||
sets: HashMap::new(),
|
||||
set_sprites: Vec::new(),
|
||||
emitters: Vec::new(),
|
||||
@@ -1225,6 +1222,34 @@ impl ParticleEngine {
|
||||
made: Default::default(),
|
||||
item_sprites: HashMap::new(),
|
||||
};
|
||||
engine.reload(root, atlas, translucent);
|
||||
engine
|
||||
}
|
||||
/// `onResourceManagerReload`: sprite rects and sets come from the
|
||||
/// reloaded atlas and pack; a live particle keeps drawing its sprite by
|
||||
/// name or index.
|
||||
pub fn reload(
|
||||
&mut self,
|
||||
root: &Path,
|
||||
atlas: &HashMap<String, Rect>,
|
||||
translucent: &HashSet<String>,
|
||||
) {
|
||||
self.atlas = atlas
|
||||
.iter()
|
||||
.map(|(name, &rect)| (name.clone(), (rect, translucent.contains(name))))
|
||||
.collect();
|
||||
self.rects = self
|
||||
.names
|
||||
.iter()
|
||||
.map(|name| self.atlas.get(name).map(|&(rect, _)| rect))
|
||||
.collect();
|
||||
self.sets.clear();
|
||||
self.set_sprites.clear();
|
||||
self.item_sprites.clear();
|
||||
self.load_sprites(root);
|
||||
}
|
||||
/// The sprite sets of every `particles/*.json` under `root`.
|
||||
fn load_sprites(&mut self, root: &Path) {
|
||||
let dir = root.join("assets/minecraft/particles");
|
||||
for &ty in ParticleType::ALL {
|
||||
let Ok(bytes) = std::fs::read(dir.join(format!("{}.json", ty.name()))) else {
|
||||
@@ -1239,18 +1264,16 @@ impl ParticleEngine {
|
||||
a.iter()
|
||||
.filter_map(|t| t.as_str())
|
||||
.map(|t| {
|
||||
engine
|
||||
.intern(&format!("particle/{}", t.trim_start_matches("minecraft:")))
|
||||
self.intern(&format!("particle/{}", t.trim_start_matches("minecraft:")))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if !sprites.is_empty() {
|
||||
engine.sets.insert(ty, engine.set_sprites.len() as u32);
|
||||
engine.set_sprites.push(sprites);
|
||||
self.sets.insert(ty, self.set_sprites.len() as u32);
|
||||
self.set_sprites.push(sprites);
|
||||
}
|
||||
}
|
||||
engine
|
||||
}
|
||||
fn intern(&mut self, name: &str) -> u32 {
|
||||
if let Some(i) = self.names.iter().position(|n| n == name) {
|
||||
@@ -1601,7 +1624,10 @@ impl ParticleEngine {
|
||||
return;
|
||||
}
|
||||
if let Some(set) = p.set {
|
||||
let sprites = &self.set_sprites[set as usize];
|
||||
// A sprite set's index can outlive the reload that rebuilt them.
|
||||
let Some(sprites) = self.set_sprites.get(set as usize) else {
|
||||
return;
|
||||
};
|
||||
let lifetime = p.lifetime.max(1);
|
||||
let index = (p.age.max(0) as i64 * (sprites.len() as i64 - 1) / i64::from(lifetime))
|
||||
.clamp(0, sprites.len() as i64 - 1);
|
||||
|
||||
@@ -6,11 +6,15 @@ license = "MIT"
|
||||
description = "Prepares Horizon's resources from the player's own Minecraft: imports and checks the pinned jars, runs the vanilla exporters, writes the resource folder"
|
||||
|
||||
[dependencies]
|
||||
crc32fast = "1"
|
||||
regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] }
|
||||
sha1 = "0.10"
|
||||
sha2 = "0.10"
|
||||
zip = { version = "2", default-features = false, features = ["deflate"] }
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
sha2 = "0.10"
|
||||
|
||||
|
||||
@@ -143,31 +143,17 @@ pub(crate) fn import_copy(
|
||||
algorithm: &str,
|
||||
hint: &str,
|
||||
) -> Result<PathBuf, String> {
|
||||
fs::create_dir_all(destination.parent().unwrap()).map_err(|e| e.to_string())?;
|
||||
if destination.exists() && digest(destination, algorithm)? == checksum {
|
||||
return Ok(destination.to_path_buf());
|
||||
}
|
||||
if !source.is_file() {
|
||||
return Err(format!("Missing {}. {hint}", source.display())
|
||||
.trim()
|
||||
.to_string());
|
||||
}
|
||||
let actual = digest(source, algorithm)?;
|
||||
if actual != checksum {
|
||||
return Err(format!(
|
||||
"{} is not the pinned file: expected {algorithm} {checksum}, got {actual}",
|
||||
source.display()
|
||||
));
|
||||
}
|
||||
let temporary = destination.with_file_name(format!(
|
||||
".{}.partial-{}",
|
||||
destination.file_name().unwrap().to_string_lossy(),
|
||||
std::process::id()
|
||||
));
|
||||
let copied = fs::copy(source, &temporary).and_then(|_| fs::rename(&temporary, destination));
|
||||
let _ = fs::remove_file(&temporary);
|
||||
copied.map_err(|e| format!("{}: {e}", destination.display()))?;
|
||||
Ok(destination.to_path_buf())
|
||||
crate::files::Import::stage(source, destination, checksum, algorithm, false)
|
||||
.map_err(|error| {
|
||||
if !source.is_file() {
|
||||
format!("Missing {}. {hint}", source.display())
|
||||
.trim()
|
||||
.to_string()
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?
|
||||
.commit()
|
||||
}
|
||||
|
||||
/// The pinned version JSON from the launcher's versions/ directory. The launcher's copy wins
|
||||
@@ -653,9 +639,17 @@ pub struct Artifacts {
|
||||
|
||||
/// Reuses checked imports from this root or another installed version beside it.
|
||||
pub fn reuse_imported(root: &Path, log: Log) -> Result<bool, String> {
|
||||
Ok(reuse_verified(root, log)?.is_some())
|
||||
}
|
||||
|
||||
/// Keep this preparation's verified artifacts and client libraries for the exporters.
|
||||
pub(crate) fn reuse_verified(
|
||||
root: &Path,
|
||||
log: Log,
|
||||
) -> Result<Option<(Artifacts, Vec<PathBuf>)>, String> {
|
||||
let root = fs::canonicalize(root).map_err(|e| format!("{}: {e}", root.display()))?;
|
||||
let lock = Lock::read(&root)?;
|
||||
let checked = |directory: PathBuf| -> Result<Vec<PathBuf>, String> {
|
||||
let checked = |directory: PathBuf| -> Result<(Artifacts, Vec<PathBuf>), String> {
|
||||
let candidate = Lock {
|
||||
json: lock.json.clone(),
|
||||
version: lock.version.clone(),
|
||||
@@ -664,17 +658,9 @@ pub fn reuse_imported(root: &Path, log: Log) -> Result<bool, String> {
|
||||
};
|
||||
let found = verify(&candidate)?;
|
||||
let client = client_libraries(&candidate, &found.manifest)?;
|
||||
let mut files = vec![
|
||||
candidate.directory.join("manifest.json"),
|
||||
candidate.directory.join("jars/client.jar"),
|
||||
candidate.directory.join("jars/server.jar"),
|
||||
found.jars["server"].clone(),
|
||||
];
|
||||
files.extend(found.libraries);
|
||||
files.extend(client);
|
||||
Ok(files)
|
||||
Ok((found, client))
|
||||
};
|
||||
if checked(lock.directory.clone()).is_ok() {
|
||||
if let Ok((found, client_libraries)) = checked(lock.directory.clone()) {
|
||||
if [
|
||||
"prepared.json",
|
||||
"reports/client-inventory.json",
|
||||
@@ -683,8 +669,6 @@ pub fn reuse_imported(root: &Path, log: Log) -> Result<bool, String> {
|
||||
.iter()
|
||||
.any(|path| !lock.directory.join(path).is_file())
|
||||
{
|
||||
let found = verify(&lock)?;
|
||||
let client_libraries = client_libraries(&lock, &found.manifest)?;
|
||||
write_import_metadata(
|
||||
&root,
|
||||
&lock,
|
||||
@@ -696,10 +680,10 @@ pub fn reuse_imported(root: &Path, log: Log) -> Result<bool, String> {
|
||||
)?;
|
||||
}
|
||||
log(&format!("Using imported Minecraft {}", lock.version));
|
||||
return Ok(true);
|
||||
return Ok(Some((found, client_libraries)));
|
||||
}
|
||||
let Some(versions) = root.parent() else {
|
||||
return Ok(false);
|
||||
return Ok(None);
|
||||
};
|
||||
// Sibling discovery is intended for the launcher's versions/ folder.
|
||||
let mut siblings: Vec<_> = fs::read_dir(versions)
|
||||
@@ -711,9 +695,17 @@ pub fn reuse_imported(root: &Path, log: Log) -> Result<bool, String> {
|
||||
siblings.sort();
|
||||
for sibling in siblings {
|
||||
let source = sibling.join(".local/minecraft").join(&lock.version);
|
||||
let Ok(files) = checked(source.clone()) else {
|
||||
let Ok((found, client)) = checked(source.clone()) else {
|
||||
continue;
|
||||
};
|
||||
let mut files = vec![
|
||||
source.join("manifest.json"),
|
||||
source.join("jars/client.jar"),
|
||||
source.join("jars/server.jar"),
|
||||
found.jars["server"].clone(),
|
||||
];
|
||||
files.extend(found.libraries);
|
||||
files.extend(client);
|
||||
for file in files {
|
||||
let relative = file.strip_prefix(&source).map_err(|e| e.to_string())?;
|
||||
import_copy(
|
||||
@@ -740,9 +732,9 @@ pub fn reuse_imported(root: &Path, log: Log) -> Result<bool, String> {
|
||||
lock.version,
|
||||
sibling.display()
|
||||
));
|
||||
return Ok(true);
|
||||
return Ok(Some((found, client_libraries)));
|
||||
}
|
||||
Ok(false)
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn verify(lock: &Lock) -> Result<Artifacts, String> {
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
//! Independent copies, using filesystem cloning when available. Never hard links: exporters
|
||||
//! rewrite prepared resources in place. Checked imports publish only after verifying the copy.
|
||||
|
||||
use crate::{digest, hex};
|
||||
use sha2::Digest;
|
||||
use std::fs;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
fn clone_file(from: &Path, to: &Path) -> io::Result<()> {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use std::os::fd::AsRawFd;
|
||||
let source = fs::File::open(from)?;
|
||||
let target = fs::File::create(to)?;
|
||||
// SAFETY: FICLONE takes a source fd, both descriptors stay open for the call.
|
||||
if unsafe { libc::ioctl(target.as_raw_fd(), libc::FICLONE, source.as_raw_fd()) } == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use std::ffi::CString;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
let path = |p: &Path| {
|
||||
CString::new(p.as_os_str().as_bytes())
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))
|
||||
};
|
||||
let (source, target) = (path(from)?, path(to)?);
|
||||
// SAFETY: both paths are valid NUL-terminated strings for the duration of the call.
|
||||
if unsafe { libc::clonefile(source.as_ptr(), target.as_ptr(), 0) } == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
Err(io::Error::last_os_error())
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
{
|
||||
let _ = (from, to);
|
||||
Err(io::ErrorKind::Unsupported.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies an independent file, attempting a reflink first. The destination may be replaced.
|
||||
pub fn clone_or_copy(from: &Path, to: &Path) -> io::Result<()> {
|
||||
clone_file(from, to).or_else(|_| fs::copy(from, to).map(|_| ()))
|
||||
}
|
||||
|
||||
fn copy_hash<D: Digest>(from: &Path, to: &Path) -> io::Result<String> {
|
||||
let mut source = fs::File::open(from)?;
|
||||
let mut target = fs::File::create(to)?;
|
||||
let mut hash = D::new();
|
||||
let mut buffer = vec![0; 64 * 1024];
|
||||
loop {
|
||||
let n = source.read(&mut buffer)?;
|
||||
if n == 0 {
|
||||
return Ok(hex(&hash.finalize()));
|
||||
}
|
||||
target.write_all(&buffer[..n])?;
|
||||
hash.update(&buffer[..n]);
|
||||
}
|
||||
}
|
||||
|
||||
/// A verified replacement staged beside its destination. Dropping an unfinished set cleans
|
||||
/// every temporary file, so a corrupt late panorama face cannot replace earlier placeholders.
|
||||
pub(crate) struct Import {
|
||||
temporary: Option<PathBuf>,
|
||||
destination: PathBuf,
|
||||
}
|
||||
|
||||
impl Import {
|
||||
pub(crate) fn stage(
|
||||
source: &Path,
|
||||
destination: &Path,
|
||||
checksum: &str,
|
||||
algorithm: &str,
|
||||
verified: bool,
|
||||
) -> Result<Self, String> {
|
||||
let mut import = Self {
|
||||
temporary: None,
|
||||
destination: destination.into(),
|
||||
};
|
||||
if verified || (destination.is_file() && digest(destination, algorithm)? == checksum) {
|
||||
return Ok(import);
|
||||
}
|
||||
fs::create_dir_all(destination.parent().unwrap()).map_err(|e| e.to_string())?;
|
||||
static COPIES: AtomicUsize = AtomicUsize::new(0);
|
||||
let temporary = destination.with_file_name(format!(
|
||||
".{}.partial-{}-{}",
|
||||
destination.file_name().unwrap().to_string_lossy(),
|
||||
std::process::id(),
|
||||
COPIES.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
import.temporary = Some(temporary.clone());
|
||||
let actual = if clone_file(source, &temporary).is_ok() {
|
||||
digest(&temporary, algorithm)?
|
||||
} else {
|
||||
match algorithm {
|
||||
"sha1" => copy_hash::<sha1::Sha1>(source, &temporary),
|
||||
_ => copy_hash::<sha2::Sha256>(source, &temporary),
|
||||
}
|
||||
.map_err(|e| format!("{}: {e}", source.display()))?
|
||||
};
|
||||
if actual != checksum {
|
||||
return Err(format!(
|
||||
"{} is not the pinned file: expected {algorithm} {checksum}, got {actual}",
|
||||
source.display()
|
||||
));
|
||||
}
|
||||
Ok(import)
|
||||
}
|
||||
|
||||
pub(crate) fn commit(mut self) -> Result<PathBuf, String> {
|
||||
if let Some(temporary) = &self.temporary {
|
||||
fs::rename(temporary, &self.destination)
|
||||
.map_err(|e| format!("{}: {e}", self.destination.display()))?;
|
||||
}
|
||||
self.temporary = None;
|
||||
Ok(self.destination.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Import {
|
||||
fn drop(&mut self) {
|
||||
if let Some(temporary) = &self.temporary {
|
||||
let _ = fs::remove_file(temporary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn copies_are_independent_and_checked_before_publication() {
|
||||
let dir = std::env::temp_dir().join(format!("horizon-file-copy-{}", std::process::id()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let source = dir.join("source");
|
||||
let target = dir.join("target");
|
||||
let data = vec![42; 200_000]; // More than one streaming buffer.
|
||||
fs::write(&source, &data).unwrap();
|
||||
for algorithm in ["sha1", "sha256"] {
|
||||
let checksum = digest(&source, algorithm).unwrap();
|
||||
Import::stage(&source, &target, &checksum, algorithm, false)
|
||||
.unwrap()
|
||||
.commit()
|
||||
.unwrap();
|
||||
assert_eq!(digest(&target, algorithm).unwrap(), checksum);
|
||||
fs::write(&target, b"old destination").unwrap();
|
||||
assert_eq!(fs::read(&source).unwrap(), data);
|
||||
assert!(Import::stage(&source, &target, "bad hash", algorithm, false).is_err());
|
||||
assert_eq!(fs::read(&target).unwrap(), b"old destination");
|
||||
// Explicitly exercise ordinary streaming copies even on a reflink filesystem.
|
||||
let streamed = if algorithm == "sha1" {
|
||||
copy_hash::<sha1::Sha1>(&source, &target).unwrap()
|
||||
} else {
|
||||
copy_hash::<sha2::Sha256>(&source, &target).unwrap()
|
||||
};
|
||||
assert_eq!(streamed, checksum);
|
||||
assert_eq!(fs::read(&target).unwrap(), data);
|
||||
}
|
||||
clone_or_copy(&source, &target).unwrap();
|
||||
fs::write(&target, b"rewrite").unwrap();
|
||||
assert_eq!(fs::read(&source).unwrap(), data);
|
||||
let staged = Import::stage(
|
||||
&source,
|
||||
&target,
|
||||
&digest(&source, "sha1").unwrap(),
|
||||
"sha1",
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(fs::read_dir(&dir).unwrap().count(), 3);
|
||||
drop(staged);
|
||||
assert_eq!(fs::read_dir(&dir).unwrap().count(), 2);
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,14 @@
|
||||
//! run, keyed by the sha256 of their inputs and outputs recorded in the manifest, as before.
|
||||
|
||||
pub mod artifacts;
|
||||
mod files;
|
||||
mod inventory;
|
||||
pub mod java;
|
||||
pub mod pyjson;
|
||||
mod sounds;
|
||||
mod survival;
|
||||
|
||||
pub use files::clone_or_copy;
|
||||
pub use sounds::{fonts, languages, packs, panorama, sounds, BUILT_IN_PACKS};
|
||||
|
||||
use pyjson::Value;
|
||||
@@ -419,16 +421,28 @@ pub fn prepare(options: &Options, log: Log) -> Result<PathBuf, String> {
|
||||
&artifacts::minecraft_dir(options.minecraft_dir.as_deref()).join("runtime"),
|
||||
));
|
||||
let jdk = java::find(lock.java_major, &homes)?;
|
||||
if options.import && !artifacts::reuse_imported(root, log)? {
|
||||
artifacts::import(
|
||||
root,
|
||||
&lock,
|
||||
options.minecraft_dir.as_deref(),
|
||||
options.server_jar.as_deref(),
|
||||
log,
|
||||
)?;
|
||||
}
|
||||
let found = artifacts::verify(&lock)?;
|
||||
let reused = if options.import {
|
||||
artifacts::reuse_verified(root, log)?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let (found, client_libraries) = match reused {
|
||||
Some(checked) => checked,
|
||||
None => {
|
||||
if options.import {
|
||||
artifacts::import(
|
||||
root,
|
||||
&lock,
|
||||
options.minecraft_dir.as_deref(),
|
||||
options.server_jar.as_deref(),
|
||||
log,
|
||||
)?;
|
||||
}
|
||||
let found = artifacts::verify(&lock)?;
|
||||
let libraries = artifacts::client_libraries(&lock, &found.manifest)?;
|
||||
(found, libraries)
|
||||
}
|
||||
};
|
||||
let local = root.join(".local");
|
||||
let resources = local.join("horizon-client").join(&lock.version);
|
||||
mkdir(&resources)?;
|
||||
@@ -454,7 +468,6 @@ pub fn prepare(options: &Options, log: Log) -> Result<PathBuf, String> {
|
||||
} else {
|
||||
Value::Object(Vec::new())
|
||||
};
|
||||
let client_libraries = artifacts::client_libraries(&lock, &found.manifest)?;
|
||||
let run = Run {
|
||||
root: root.clone(),
|
||||
local,
|
||||
@@ -688,25 +701,9 @@ fn steps(
|
||||
// and every data-pack resource (worldgen, recipes, loot tables, tags), and
|
||||
// the vanilla pack's icon (`pack.png`) for the pack screen.
|
||||
(run.log)("Copying the client's assets and data");
|
||||
let mut count = 0usize;
|
||||
let mut client = open_zip(&run.client)?;
|
||||
let version = pyjson::loads(&zip_text(&mut client, "version.json")?)?;
|
||||
for name in zip_names(&client) {
|
||||
let wanted = name.starts_with("assets/") || name.starts_with("data/") || name == "pack.png";
|
||||
if !wanted || name.ends_with('/') {
|
||||
continue;
|
||||
}
|
||||
let relative = member_path(&name, "Invalid resource path")?;
|
||||
let data = zip_bytes(&mut client, &name)?;
|
||||
write_if_changed(&root.join(relative), &data)?;
|
||||
count += 1;
|
||||
}
|
||||
|
||||
// The JAR holds only gray 1x1 panorama placeholders and an empty Unifont
|
||||
// include, and none of the built-in packs. Import the indexed ones afterwards, including on reruns that just
|
||||
// extracted the JAR again. They are optional when preparing from
|
||||
// already-imported JARs.
|
||||
sounds::optional_assets(repo, minecraft, run.log);
|
||||
let mut indexed = sounds::Assets::load(repo, minecraft, run.log);
|
||||
let (version, count) = extract_client_resources(&run.client, root, indexed.as_mut().ok())?;
|
||||
sounds::optional_imports(indexed.as_mut().map_err(|e| e.as_str()), run.log);
|
||||
|
||||
// One file each, exported again when the exporter or the jar it reads changed.
|
||||
let single = |what: &str,
|
||||
@@ -940,6 +937,54 @@ fn steps(
|
||||
)
|
||||
}
|
||||
|
||||
/// Check existing JAR assets by their ZIP size/CRC without inflating every member again.
|
||||
/// Indexed panorama/font/language replacements have stronger SHA-1 checks and take precedence.
|
||||
fn extract_client_resources(
|
||||
jar: &Path,
|
||||
root: &Path,
|
||||
mut indexed: Option<&mut sounds::Assets>,
|
||||
) -> Result<(Value, usize), String> {
|
||||
let mut client = open_zip(jar)?;
|
||||
let version = pyjson::loads(&zip_text(&mut client, "version.json")?)?;
|
||||
let mut count = 0;
|
||||
for name in zip_names(&client) {
|
||||
if !(name.starts_with("assets/") || name.starts_with("data/") || name == "pack.png")
|
||||
|| name.ends_with('/')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let relative = member_path(&name, "Invalid resource path")?;
|
||||
count += 1;
|
||||
if let Some(assets) = &mut indexed {
|
||||
if assets.imported(&name)? {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let target = root.join(relative);
|
||||
let member = client.by_name(&name).map_err(|e| e.to_string())?;
|
||||
let (size, crc) = (member.size(), member.crc32());
|
||||
drop(member);
|
||||
if target.is_file() && fs::metadata(&target).map_err(|e| e.to_string())?.len() == size {
|
||||
let mut file = fs::File::open(&target).map_err(|e| e.to_string())?;
|
||||
let mut hash = crc32fast::Hasher::new();
|
||||
let mut buffer = [0; 16 * 1024];
|
||||
loop {
|
||||
let n = file.read(&mut buffer).map_err(|e| e.to_string())?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
hash.update(&buffer[..n]);
|
||||
}
|
||||
if hash.finalize() == crc {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
mkdir(target.parent().unwrap())?;
|
||||
write(&target, &zip_bytes(&mut client, &name)?)?;
|
||||
}
|
||||
Ok((version, count))
|
||||
}
|
||||
|
||||
fn datagen_reports_missing(root: &Path) -> bool {
|
||||
["items.json", "registries.json", "commands.json"]
|
||||
.iter()
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
use crate::artifacts::{self, Lock};
|
||||
use crate::pyjson::Value;
|
||||
use crate::{digest, read_json, Log};
|
||||
use crate::{digest, Log};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -18,8 +19,9 @@ fn launcher_assets(
|
||||
lock: &Lock,
|
||||
manifest: &Value,
|
||||
minecraft: &Path,
|
||||
cached_index: &Path,
|
||||
log: Log,
|
||||
) -> Result<(PathBuf, PathBuf), String> {
|
||||
) -> Result<(PathBuf, PathBuf, Vec<u8>), String> {
|
||||
let assets = minecraft.join("assets");
|
||||
let info = manifest
|
||||
.get("assetIndex")
|
||||
@@ -33,7 +35,10 @@ fn launcher_assets(
|
||||
if artifacts::safe_relative(id).is_none_or(|p| p.components().count() != 1) {
|
||||
return Err(format!("Unsafe asset index id {id:?}"));
|
||||
}
|
||||
let index = assets.join("indexes").join(format!("{id}.json"));
|
||||
let mut index = assets.join("indexes").join(format!("{id}.json"));
|
||||
if !index.is_file() && cached_index.is_file() {
|
||||
index = cached_index.to_path_buf();
|
||||
}
|
||||
if !index.is_file() {
|
||||
let version = manifest.get("id").and_then(Value::as_str).unwrap_or("");
|
||||
return Err(format!(
|
||||
@@ -42,7 +47,8 @@ fn launcher_assets(
|
||||
artifacts::launcher_hint(version)
|
||||
));
|
||||
}
|
||||
let checksum = digest(&index, "sha1")?;
|
||||
let bytes = fs::read(&index).map_err(|e| format!("{}: {e}", index.display()))?;
|
||||
let checksum = crate::hex(&<sha1::Sha1 as sha1::Digest>::digest(&bytes));
|
||||
if checksum != sha1 && !lock.asset_index_accepted(&checksum) {
|
||||
log(&format!(
|
||||
"{} is an asset index Horizon does not know yet (sha1 {checksum}); Mojang may have \
|
||||
@@ -50,7 +56,7 @@ fn launcher_assets(
|
||||
index.display()
|
||||
));
|
||||
}
|
||||
Ok((assets, index))
|
||||
Ok((assets, index, bytes))
|
||||
}
|
||||
|
||||
/// Where the launcher's asset store keeps the object with this SHA-1.
|
||||
@@ -61,24 +67,6 @@ fn object_path(assets: &Path, checksum: &str) -> Result<PathBuf, String> {
|
||||
Ok(assets.join("objects").join(&checksum[..2]).join(checksum))
|
||||
}
|
||||
|
||||
/// One verified object from the launcher's asset store (tools/lab.py `launcher_object`).
|
||||
fn launcher_object(assets: &Path, checksum: &str) -> Result<PathBuf, String> {
|
||||
let path = object_path(assets, checksum)?;
|
||||
if !path.is_file() {
|
||||
return Err(format!(
|
||||
"Missing asset object {}. Play the pinned version once in your launcher.",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
if digest(&path, "sha1")? != checksum {
|
||||
return Err(format!(
|
||||
"Corrupt asset object {}; let the launcher repair it",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
/// Whether the game plays this asset: sounds.json and everything under sounds/.
|
||||
fn is_sound(name: &str) -> bool {
|
||||
name == "minecraft/sounds.json" || name.starts_with("minecraft/sounds/")
|
||||
@@ -127,26 +115,56 @@ fn is_language(name: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Full preparation can run from cached JARs without an official launcher install.
|
||||
pub(crate) fn optional_assets(root: &Path, minecraft: Option<&Path>, log: Log) {
|
||||
if let Err(error) = panorama(root, minecraft, log) {
|
||||
log(&format!(
|
||||
"Title panorama not imported: {error}; run horizon-prepare panorama later"
|
||||
));
|
||||
}
|
||||
if let Err(error) = fonts(root, minecraft, log) {
|
||||
log(&format!(
|
||||
"Unifont glyphs not imported: {error}; run horizon-prepare fonts later"
|
||||
));
|
||||
}
|
||||
if let Err(error) = packs(root, minecraft, log) {
|
||||
log(&format!(
|
||||
"Programmer Art and High Contrast not imported: {error}; run horizon-prepare packs later"
|
||||
));
|
||||
}
|
||||
if let Err(error) = languages(root, minecraft, log) {
|
||||
log(&format!(
|
||||
"Languages not imported: {error}; run horizon-prepare languages later"
|
||||
));
|
||||
#[cfg(test)]
|
||||
fn optional_assets(root: &Path, minecraft: Option<&Path>, log: Log) {
|
||||
optional_imports(
|
||||
Assets::load(root, minecraft, log)
|
||||
.as_mut()
|
||||
.map_err(|e| e.as_str()),
|
||||
log,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn optional_imports(mut assets: Result<&mut Assets, &str>, log: Log) {
|
||||
for (wanted, label, required, failure, command) in [
|
||||
(
|
||||
is_panorama as fn(&str) -> bool,
|
||||
"Panorama",
|
||||
PANORAMA.as_slice(),
|
||||
"Title panorama",
|
||||
"panorama",
|
||||
),
|
||||
(
|
||||
is_font,
|
||||
"Font",
|
||||
UNIFONT.as_slice(),
|
||||
"Unifont glyphs",
|
||||
"fonts",
|
||||
),
|
||||
(
|
||||
is_built_in_pack,
|
||||
"Built-in pack",
|
||||
BUILT_IN_PACKS.as_slice(),
|
||||
"Programmer Art and High Contrast",
|
||||
"packs",
|
||||
),
|
||||
(
|
||||
is_language,
|
||||
"Language",
|
||||
LANGUAGES.as_slice(),
|
||||
"Languages",
|
||||
"languages",
|
||||
),
|
||||
] {
|
||||
let result = match &mut assets {
|
||||
Ok(assets) => assets.copy(wanted, label, required, log).map(|_| ()),
|
||||
Err(error) => Err(error.to_string()),
|
||||
};
|
||||
if let Err(error) = result {
|
||||
log(&format!(
|
||||
"{failure} not imported: {error}; run horizon-prepare {command} later"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,29 +225,98 @@ fn copy_assets(
|
||||
label: &str,
|
||||
required: &[&str],
|
||||
) -> Result<PathBuf, String> {
|
||||
let lock = Lock::read(root)?;
|
||||
let minecraft = artifacts::minecraft_dir(minecraft);
|
||||
let manifest = artifacts::import_manifest(&lock, &minecraft)?;
|
||||
let (store, index) = launcher_assets(&lock, &manifest, &minecraft, log)?;
|
||||
let id = manifest
|
||||
.get("id")
|
||||
.and_then(Value::as_str)
|
||||
.ok_or("The version JSON has no id")?;
|
||||
let target = root.join(".local/horizon-client").join(id);
|
||||
fs::create_dir_all(&target).map_err(|e| format!("{}: {e}", target.display()))?;
|
||||
fs::copy(&index, target.join("asset-index.json"))
|
||||
.map_err(|e| format!("{}: {e}", target.join("asset-index.json").display()))?;
|
||||
let objects = read_json(&index)?;
|
||||
let objects = objects
|
||||
.get("objects")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or_else(|| format!("{} has no objects", index.display()))?;
|
||||
Assets::load(root, minecraft, log)?.copy(wanted_asset, label, required, log)
|
||||
}
|
||||
|
||||
/// A preparation's index and verified destinations. Never persisted: a later invocation
|
||||
/// checks the bytes again, including when repairing a corrupt prepared file.
|
||||
pub(crate) struct Assets {
|
||||
store: PathBuf,
|
||||
target: PathBuf,
|
||||
objects: Vec<(String, Value)>,
|
||||
verified: HashSet<PathBuf>,
|
||||
}
|
||||
|
||||
impl Assets {
|
||||
pub(crate) fn load(root: &Path, minecraft: Option<&Path>, log: Log) -> Result<Self, String> {
|
||||
let lock = Lock::read(root)?;
|
||||
let minecraft = artifacts::minecraft_dir(minecraft);
|
||||
let manifest = artifacts::import_manifest(&lock, &minecraft)?;
|
||||
let target = root.join(".local/horizon-client").join(&lock.version);
|
||||
let (store, index, bytes) = launcher_assets(
|
||||
&lock,
|
||||
&manifest,
|
||||
&minecraft,
|
||||
&target.join("asset-index.json"),
|
||||
log,
|
||||
)?;
|
||||
let text = std::str::from_utf8(&bytes).map_err(|e| e.to_string())?;
|
||||
let objects = crate::pyjson::loads(text)?;
|
||||
let objects = objects
|
||||
.get("objects")
|
||||
.and_then(Value::as_object)
|
||||
.ok_or_else(|| format!("{} has no objects", index.display()))?
|
||||
.to_vec();
|
||||
fs::create_dir_all(&target).map_err(|e| e.to_string())?;
|
||||
crate::write_if_changed(&target.join("asset-index.json"), &bytes)?;
|
||||
Ok(Self {
|
||||
store,
|
||||
target,
|
||||
objects,
|
||||
verified: HashSet::new(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Preserve indexed replacements instead of overwriting them with JAR placeholders.
|
||||
pub(crate) fn imported(&mut self, name: &str) -> Result<bool, String> {
|
||||
let Some(name) = name.strip_prefix("assets/") else {
|
||||
return Ok(false);
|
||||
};
|
||||
if !(is_panorama(name) || is_font(name) || is_language(name)) {
|
||||
return Ok(false);
|
||||
}
|
||||
let Some((_, info)) = self.objects.iter().rev().find(|(n, _)| n == name) else {
|
||||
return Ok(false);
|
||||
};
|
||||
let Some(hash) = info.get("hash").and_then(Value::as_str) else {
|
||||
return Ok(false);
|
||||
};
|
||||
let destination = self.target.join("assets").join(name);
|
||||
if destination.is_file() && digest(&destination, "sha1")? == hash {
|
||||
self.verified.insert(destination);
|
||||
return Ok(true);
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn copy(
|
||||
&mut self,
|
||||
wanted_asset: fn(&str) -> bool,
|
||||
label: &str,
|
||||
required: &[&str],
|
||||
log: Log,
|
||||
) -> Result<PathBuf, String> {
|
||||
copy_indexed(self, wanted_asset, label, required, log)
|
||||
}
|
||||
}
|
||||
|
||||
fn copy_indexed(
|
||||
assets: &mut Assets,
|
||||
wanted_asset: fn(&str) -> bool,
|
||||
label: &str,
|
||||
required: &[&str],
|
||||
log: Log,
|
||||
) -> Result<PathBuf, String> {
|
||||
let objects = &assets.objects;
|
||||
// A repeated name keeps its first place and its last value, as a Python dict does.
|
||||
let mut wanted: Vec<(&str, &Value)> = Vec::new();
|
||||
let mut positions = HashMap::new();
|
||||
for (name, info) in objects.iter().filter(|(name, _)| wanted_asset(name)) {
|
||||
match wanted.iter_mut().find(|(n, _)| n == name) {
|
||||
Some(entry) => entry.1 = info,
|
||||
None => wanted.push((name, info)),
|
||||
if let Some(&position) = positions.get(name.as_str()) {
|
||||
wanted[position] = (name.as_str(), info);
|
||||
} else {
|
||||
positions.insert(name.as_str(), wanted.len());
|
||||
wanted.push((name, info));
|
||||
}
|
||||
}
|
||||
for name in required {
|
||||
@@ -251,21 +338,45 @@ fn copy_assets(
|
||||
.ok_or_else(|| format!("{name} has no size in the asset index"))?;
|
||||
let relative = artifacts::safe_relative(name)
|
||||
.ok_or_else(|| format!("Unsafe asset name {name:?} in the asset index"))?;
|
||||
let source = launcher_object(&store, hash)?;
|
||||
copies.push((source, target.join("assets").join(relative), hash));
|
||||
let source = object_path(&assets.store, hash)?;
|
||||
let destination = assets.target.join("assets").join(relative);
|
||||
let import = crate::files::Import::stage(
|
||||
&source,
|
||||
&destination,
|
||||
hash,
|
||||
"sha1",
|
||||
assets.verified.contains(&destination),
|
||||
)
|
||||
.map_err(|error| {
|
||||
if !source.is_file() {
|
||||
format!(
|
||||
"Missing asset object {}. Play the pinned version once in your launcher.",
|
||||
source.display()
|
||||
)
|
||||
} else if error.contains(" is not the pinned file:") {
|
||||
format!(
|
||||
"Corrupt asset object {}; let the launcher repair it: {error}",
|
||||
source.display()
|
||||
)
|
||||
} else {
|
||||
error
|
||||
}
|
||||
})?;
|
||||
copies.push((import, destination));
|
||||
total += size;
|
||||
}
|
||||
// Check the entire set before replacing any placeholders: a missing late face
|
||||
// must not leave a mixture of real textures and gray faces in either entry point.
|
||||
for (source, destination, hash) in copies {
|
||||
artifacts::import_copy(&source, &destination, hash, "sha1", "")?;
|
||||
for (import, destination) in copies {
|
||||
import.commit()?;
|
||||
assets.verified.insert(destination);
|
||||
}
|
||||
log(&format!(
|
||||
"{label} assets ready: {} files, {:.1} MB",
|
||||
wanted.len(),
|
||||
total as f64 / 1e6
|
||||
));
|
||||
Ok(target)
|
||||
Ok(assets.target.clone())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -680,6 +791,7 @@ mod tests {
|
||||
"minecraft/sounds.json is missing from the asset index"
|
||||
);
|
||||
fs::remove_file(&index).unwrap();
|
||||
fs::remove_file(f.root.join(".local/horizon-client/9.9/asset-index.json")).unwrap();
|
||||
let error = f.run().unwrap_err();
|
||||
assert!(
|
||||
error.starts_with("Missing ") && error.contains("play 9.9 once"),
|
||||
@@ -687,6 +799,120 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn late_corruption_discards_all_staged_replacements() {
|
||||
let f = Fixture::new("late-corruption");
|
||||
let target = f.root.join(".local/horizon-client/9.9/assets");
|
||||
for name in PANORAMA {
|
||||
let path = target.join(name);
|
||||
fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
fs::write(path, b"placeholder").unwrap();
|
||||
}
|
||||
fs::write(f.object(FIRST_FACE + 6), b"bad overlay").unwrap();
|
||||
assert!(panorama(&f.root, Some(&f.minecraft), &|_| {}).is_err());
|
||||
for name in PANORAMA {
|
||||
assert_eq!(fs::read(target.join(name)).unwrap(), b"placeholder");
|
||||
}
|
||||
assert_eq!(
|
||||
fs::read_dir(target.join("minecraft/textures/gui/title/background"))
|
||||
.unwrap()
|
||||
.count(),
|
||||
7
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_index_snapshot_serves_every_import_and_reruns_repair_corruption() {
|
||||
let f = Fixture::with_extras("snapshot", &PANORAMA, &[("pack.mcmeta", b"{}")]);
|
||||
let mut assets = Assets::load(&f.root, Some(&f.minecraft), &|_| {}).unwrap();
|
||||
fs::remove_file(f.minecraft.join("assets/indexes/7.json")).unwrap();
|
||||
let lines = std::cell::RefCell::new(Vec::new());
|
||||
optional_imports(Ok(&mut assets), &|line| {
|
||||
lines.borrow_mut().push(line.to_string())
|
||||
});
|
||||
assert_eq!(lines.borrow().len(), 4);
|
||||
assert!(lines
|
||||
.borrow()
|
||||
.iter()
|
||||
.all(|line| line.contains("assets ready")));
|
||||
assets
|
||||
.copy(is_sound, "Sound", &["minecraft/sounds.json"], &|_| {})
|
||||
.unwrap();
|
||||
let sound = assets
|
||||
.target
|
||||
.join("assets/minecraft/sounds/ambient/cave1.ogg");
|
||||
let time = fs::metadata(&sound).unwrap().modified().unwrap();
|
||||
fs::remove_file(f.object(1)).unwrap();
|
||||
f.run().unwrap(); // A verified destination works even without the source object/index.
|
||||
assert_eq!(fs::metadata(&sound).unwrap().modified().unwrap(), time);
|
||||
fs::write(&sound, b"corrupt").unwrap();
|
||||
assert!(f.run().is_err()); // Verification never carries over to another invocation.
|
||||
fs::write(f.object(1), &f.objects[1].1).unwrap();
|
||||
f.run().unwrap();
|
||||
assert_eq!(fs::read(sound).unwrap(), f.objects[1].1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jar_reruns_preserve_indexed_assets_and_repair_missing_or_corrupt_members() {
|
||||
use std::io::Write;
|
||||
let f = Fixture::with_extras(
|
||||
"extract",
|
||||
&PANORAMA,
|
||||
&[
|
||||
("pack.mcmeta", b"{}"),
|
||||
("minecraft/lang/en_us.json", b"{\"indexed\":true}"),
|
||||
],
|
||||
);
|
||||
optional_assets(&f.root, Some(&f.minecraft), &|_| {});
|
||||
let target = f.root.join(".local/horizon-client/9.9");
|
||||
let jar = f.root.join("client.jar");
|
||||
let mut zip = zip::ZipWriter::new(fs::File::create(&jar).unwrap());
|
||||
for (name, data) in [
|
||||
("version.json", "{\"world_version\": 1}"),
|
||||
(
|
||||
"assets/minecraft/textures/gui/title/background/panorama_0.png",
|
||||
"gray",
|
||||
),
|
||||
("assets/minecraft/font/include/unifont.json", "{}"),
|
||||
("assets/minecraft/lang/en_us.json", "{}"),
|
||||
("data/minecraft/test.json", "data"),
|
||||
("pack.png", "icon"),
|
||||
] {
|
||||
zip.start_file(name, zip::write::SimpleFileOptions::default())
|
||||
.unwrap();
|
||||
zip.write_all(data.as_bytes()).unwrap();
|
||||
}
|
||||
zip.finish().unwrap();
|
||||
let face = target.join("assets").join(PANORAMA[0]);
|
||||
let time = fs::metadata(&face).unwrap().modified().unwrap();
|
||||
// Preparing from cached JARs must also preserve full imports without the launcher.
|
||||
fs::remove_dir_all(f.minecraft.join("assets")).unwrap();
|
||||
for _ in 0..2 {
|
||||
let mut assets = Assets::load(&f.root, Some(&f.minecraft), &|_| {}).unwrap();
|
||||
let (_, count) =
|
||||
crate::extract_client_resources(&jar, &target, Some(&mut assets)).unwrap();
|
||||
assert_eq!(count, 5);
|
||||
optional_imports(Ok(&mut assets), &|_| {});
|
||||
assert_eq!(fs::read(&face).unwrap(), PANORAMA[0].as_bytes());
|
||||
assert_eq!(fs::metadata(&face).unwrap().modified().unwrap(), time);
|
||||
assert_eq!(
|
||||
fs::read(target.join("assets").join(UNIFONT[0])).unwrap(),
|
||||
f.objects[4].1
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read(target.join("assets/minecraft/lang/en_us.json")).unwrap(),
|
||||
b"{\"indexed\":true}"
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read(target.join("data/minecraft/test.json")).unwrap(),
|
||||
b"data"
|
||||
);
|
||||
assert_eq!(fs::read(target.join("pack.png")).unwrap(), b"icon");
|
||||
fs::write(target.join("data/minecraft/test.json"), b"oops").unwrap();
|
||||
fs::remove_file(target.join("pack.png")).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_paths_come_from_real_hashes() {
|
||||
let store = Path::new("assets");
|
||||
|
||||
@@ -40,7 +40,7 @@ The game logs into `HORIZON_HOME` and falls back to the player's own game folder
|
||||
|
||||
### Other machines
|
||||
|
||||
Harnesses can also run on the Mac mini and the ThinkPad (`tools/parity_hosts.json` describes them; its `default` list is empty, so pass `--hosts macmini,thinkpad` or set `PARITY_HOSTS`, after copying `shared-local/` to `~/code/horizon-parity/shared-local` on each host). The runner mirrors the worktree there with rsync (not `.git`, `.local`, `target` or ignored files) into `~/code/horizon-parity/remote/<host><path>`, whose `.local` links to the vanilla data in `~/code/horizon-parity/shared-local`, and starts `tools/parity.py --worker` over ssh. The worker builds the probes (about 80 s the first time) and runs what it is sent under the same tracer, admitting harnesses against its own free memory. One queue, longest first, feeds every machine, remote ones first: the Mac takes up to 14 harnesses, the desktop 3 and only those under 800 MB. Each pass comes back with the content hash of every file it depended on, so it is keyed on exactly what ran, and logs come back to `.local/parity-runner/logs/`; state, sharing and `gate.py` work as before. If a host can't be reached, or drops out, its harnesses run here.
|
||||
Harnesses can also run on the Mac mini, the ThinkPad and the desktop (`tools/parity_hosts.json` describes them; `desktop` uses its CI runner's environment and vanilla data, and refuses work, or stops it, while someone uses it: docs/release-flow.md, "The desktop's runner"; its `default` list is empty, so pass `--hosts macmini,thinkpad` or set `PARITY_HOSTS`, after copying `shared-local/` to `~/code/horizon-parity/shared-local` on each host). The runner mirrors the worktree there with rsync (not `.git`, `.local`, `target` or ignored files) into `~/code/horizon-parity/remote/<host><path>`, whose `.local` links to the vanilla data in `~/code/horizon-parity/shared-local`, and starts `tools/parity.py --worker` over ssh. The worker builds the probes (about 80 s the first time) and runs what it is sent under the same tracer, admitting harnesses against its own free memory. One queue, longest first, feeds every machine, remote ones first: the Mac takes up to 14 harnesses, the desktop 8. Each pass comes back with the content hash of every file it depended on, so it is keyed on exactly what ran, and logs come back to `.local/parity-runner/logs/`; state, sharing and `gate.py` work as before. If a host can't be reached, or drops out, its harnesses run here.
|
||||
|
||||
Harnesses a host can't run are listed in the file: `local_only` (`save_roundtrip` runs the game on a virtual screen) and each host's `exclude`. The Mac excludes nothing: vanilla's `Math.sin`, `pow`, `log` and the like don't round the same on an Apple silicon Mac as on Linux (HotSpot uses fdlibm there, Intel's stubs on x86-64), and Rust's float functions round like neither (they call the platform libm), so code that mirrors a vanilla `Math` call uses `horizon_core::jmath`, which computes what HotSpot computes on the host architecture. The ThinkPad helps too, gently: Linux, 2 harnesses at `nice 19`, since it hosts the Claude account pool; it finds ALSA through `~/code/horizon-parity/alsa-dev` like the desktop.
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# Resource preparation and filesystem work
|
||||
|
||||
The reported preparation timings put sounds at 20–29 seconds with little CPU use, versus
|
||||
0.9–1.4 seconds for fresh client asset extraction. Prefer fewer file opens, reads and writes
|
||||
over parallelizing decompression.
|
||||
|
||||
Preparation now shares one parsed asset index between panorama, font, pack and language imports.
|
||||
Its destination verification results live only for that preparation. A subsequent invocation
|
||||
checks bytes again, so it can repair corrupt resources. Existing valid destination files do not
|
||||
require the original asset objects to remain installed. A saved asset index also lets preparation
|
||||
preserve full imports when only cached Minecraft JARs remain.
|
||||
|
||||
New imports are staged beside their destination. On Linux, FICLONE is attempted first; other
|
||||
filesystems fall back to copying while hashing. Cloned copies are hashed before publication.
|
||||
macOS attempts clonefile with the same checked streaming fallback. A whole asset group is staged and
|
||||
verified before any replacement is published; corrupt late panorama faces leave placeholders
|
||||
alone. Temporary files are cleaned up on errors. This is not a transaction for rename failures
|
||||
or process termination during publication: a later run repairs incomplete groups.
|
||||
|
||||
Unchanged JAR resources are checked by the ZIP member's size and CRC, avoiding repeated
|
||||
decompression. Valid indexed replacements take precedence over JAR placeholders. Reusing checked
|
||||
Minecraft imports also passes the verified artifact/library results directly to the exporters.
|
||||
|
||||
## An immutable store across releases
|
||||
|
||||
The official launcher's SHA-1 object store already provides an immutable source for indexed
|
||||
assets. Independent filesystem clones let installed Horizon releases share physical blocks
|
||||
where supported, without sharing writable inodes. Ordinary copies remain the fallback.
|
||||
|
||||
A separate Horizon store could additionally share complete preparations on filesystems without
|
||||
cloning. Its key would need the pinned client/server hashes, the preparer's output version (or
|
||||
the legacy source/exporter fingerprint), and the actual asset-index digest: Mojang republishes
|
||||
translations without changing the Minecraft release. Two preparations with different optional
|
||||
asset availability must not claim the same complete snapshot.
|
||||
|
||||
Before adopting that store, separate immutable runtime resources from mutable exporter scratch,
|
||||
classes and logs. Publish snapshots through a temporary directory and atomic rename, give each
|
||||
release an explicit reference, and define locking, corruption repair, migration and garbage
|
||||
collection. Exporters must never receive a shared writable directory or hard-linked files.
|
||||
The existing launcher compatibility check should choose reuse; the store should only supply its
|
||||
bytes. Keep this separate from the open work on output-version compatibility (#1946/#1947).
|
||||
|
||||
For now, retain independent release directories and clone their resource files. This reduces
|
||||
copying where the filesystem supports it without introducing a second ownership/cleanup scheme.
|
||||
+27
-4
@@ -13,7 +13,7 @@ reopened; labels never start it):
|
||||
| Job | Runs on | What | Time |
|
||||
| --- | --- | --- | --- |
|
||||
| `verify` | GitHub `ubuntu-latest` | Public-tree check, Python tests, rustfmt, clippy with warnings denied, Rust tests. Dependencies and the workspace build come from a cache saved by main's runs | ~4 min cold, less warm |
|
||||
| `parity / parity` | The Mac mini's runner (`ludovics-mac-mini`, label `horizon-game`) | Only for a change to a harness, an oracle, a probe or the runner (or the `run-parity` label): the vanilla harnesses the change can affect (`tools/parity.py --changed <base>`). Other pull requests skip it: [parity-main](#parity-on-main) checks them on main | seconds when nothing is affected; minutes per affected harness |
|
||||
| `parity / parity` | A runner with the label `horizon-game`: the Mac mini's two, and the desktop's while nobody uses it (below) | Only for a change to a harness, an oracle, a probe or the runner (or the `run-parity` label): the vanilla harnesses the change can affect (`tools/parity.py --changed <base>`). Other pull requests skip it: [parity-main](#parity-on-main) checks them on main | seconds when nothing is affected; minutes per affected harness |
|
||||
|
||||
Pushes to main run `verify` only; the nightly audit covers main's harnesses.
|
||||
|
||||
@@ -28,10 +28,13 @@ The job is `.github/workflows/parity.yml`, a reusable workflow: `checks` calls i
|
||||
repository, `run-parity.yml` for a fork's pull request a maintainer labels `run-parity`.
|
||||
|
||||
Horizon never downloads the game, so harnesses that compare with vanilla run only where the maintainer's own
|
||||
copy is: the Mac mini. Its runner runs as the maintainer's account and keeps its checkout between runs
|
||||
(`clean: false`), so the probes build incrementally into `.local/parity-target` and earlier passes stand.
|
||||
copy is: the Mac mini and his Linux desktop. Their runners run as the maintainer's account and keep their checkout
|
||||
between runs (`clean: false`), so the probes build incrementally into `.local/parity-target` and earlier passes
|
||||
stand.
|
||||
|
||||
1. `tools/ci/runner-env.sh` puts the machine's Python 3.13 and the JDK `research-lock.json` pins on the PATH.
|
||||
1. `tools/ci/runner-env.sh` puts the machine's Python 3.13 and the JDK `research-lock.json` pins on the PATH
|
||||
(Homebrew and `java_home` on the Mac; on NixOS what `linux-runner.sh` pinned, else nixpkgs), and sccache when
|
||||
the machine has it.
|
||||
2. `tools/ci/vanilla-data.sh` links `.local/` to the runner's copy of the vanilla data, cloned once from
|
||||
`~/code/horizon-parity/shared-local` into `~/.actions-runners/horizon/_work/horizon/shared-local`, and
|
||||
prepares `.local/horizon-client` with the pull request's own `horizon-prepare` once per preparer version
|
||||
@@ -71,6 +74,26 @@ release's macOS build back. Each keeps its own checkout, `target/` and Rust inst
|
||||
`_work/horizon/shared-local` links to the first's, so they share the vanilla data, the preparations (one at a
|
||||
time, under a lock) and the parity passes and slots.
|
||||
|
||||
**The desktop's runner.** `ludodesktop-horizon` (labels `self-hosted`, `Linux`, `X64`, `ludodesktop`, and
|
||||
`horizon-game` once a full trial has passed there) runs on the maintainer's Linux desktop while nobody uses it: its
|
||||
screen locked, or untouched for 15 minutes (his rule, 2026-10-26). `tools/ci/linux-runner.sh install`, run there as
|
||||
him, registers it and installs two systemd user services: `horizon-runner` (the runner, in
|
||||
`~/.actions-runners/horizon`, nice 19, in `horizon-ci.slice` with CPU and I/O weight 20, half the threads (on all of
|
||||
them the CPU package reached 92–96 °C) and memory capped at two thirds of the RAM; `CARGO_BUILD_JOBS` and the harness slots at 8, after the machine froze under ~7 cold cargo
|
||||
builds on 2026-10-14; its own Rust install; the JDK, sccache and the build libraries from nixpkgs; its own
|
||||
`vscreen` so no game it starts reaches his screen) and `horizon-runner-pause` (`tools/ci/runner_pause.py`), the
|
||||
only thing that starts the runner. The watcher stops it at once on keyboard, mouse or gamepad input (read from
|
||||
`/dev/input`: only whether bytes came, never what), while an unlocked session has had input in the last 15 minutes,
|
||||
while the CPU package is at 90 °C or more, while a game runs (Steam, gamescope, Wine, Proton or Minecraft
|
||||
processes, fleet-load's own detection, or a process outside the CI slice using the GPU at 50 % or more), or while
|
||||
`~/.actions-runners/horizon/pause` exists, and starts it again 5 minutes after the last such sign. A job already
|
||||
under way is throttled to 2 threads at the lowest weight and the runner stops after it: freezing the job would make
|
||||
GitHub drop it as lost and the harnesses time out. Old pull requests' `runner-env.sh` know only the Mac: the
|
||||
runner's `.env` and `.path` give their jobs Python, the JDK and the vanilla data (`HORIZON_SHARED_SOURCE`) all the
|
||||
same. The nightly audit and parity-main stay on the Mac mini's runners: the audit compares with the previous night,
|
||||
so it stays on one platform, and a parity-main job slowed down on the desktop because he came back could time out,
|
||||
and its failures bisect and comment on merges.
|
||||
|
||||
## Merging
|
||||
|
||||
Pull requests merge with a merge commit. The orchestrator sessions review a pull request, then turn on
|
||||
|
||||
Generated
+2
@@ -2726,6 +2726,8 @@ dependencies = [
|
||||
name = "horizon-prepare"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"regex",
|
||||
"sha1",
|
||||
"sha2 0.10.9",
|
||||
|
||||
@@ -719,7 +719,7 @@ fn copy_dir(from: &Path, to: &Path) -> std::io::Result<()> {
|
||||
if entry.file_type()?.is_dir() {
|
||||
copy_dir(&entry.path(), &target)?;
|
||||
} else {
|
||||
fs::copy(entry.path(), target)?;
|
||||
horizon_prepare::clone_or_copy(&entry.path(), &target)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -604,6 +604,7 @@ public final class VanillaMobAiOracle {
|
||||
case "tame" -> { if (mob instanceof net.minecraft.world.entity.animal.equine.AbstractHorse horse) horse.setTamed(true); }
|
||||
case "strength" -> method(net.minecraft.world.entity.animal.equine.Llama.class, "setStrength", int.class)
|
||||
.invoke(mob, Integer.parseInt(v));
|
||||
case "dead" -> mob.setHealth(0.0F);
|
||||
case "leashed", "leashto" -> {
|
||||
// Leashed once every mob exists (below).
|
||||
}
|
||||
@@ -807,6 +808,12 @@ public final class VanillaMobAiOracle {
|
||||
for (BlockPos h : heartPositions) printHeart(t, level, h);
|
||||
for (String[] b : s.blocks) if (b[0].equals("chest")) printChest(t, s, level, b);
|
||||
for (String[] b : s.blocks) if (isHive(b)) printHive(t, level, b);
|
||||
if (s.name.startsWith("leash_death_")) {
|
||||
int leads = level.getEntitiesOfClass(ItemEntity.class, ENTS.get(0).getBoundingBox().inflate(32.0),
|
||||
item -> item.getItem().is(net.minecraft.world.item.Items.LEAD))
|
||||
.stream().mapToInt(item -> item.getItem().getCount()).sum();
|
||||
out.println(t + " leads " + leads);
|
||||
}
|
||||
for (String sound : SOUNDS) out.println(t + " sound " + sound);
|
||||
for (var w : watched.entrySet()) {
|
||||
BlockState now = level.getBlockState(w.getKey());
|
||||
@@ -1008,6 +1015,7 @@ public final class VanillaMobAiOracle {
|
||||
return;
|
||||
}
|
||||
Mob m = (Mob) e;
|
||||
sb.append("\tleashed ").append(((net.minecraft.world.entity.Leashable) m).isLeashed() ? 1 : 0);
|
||||
sb.append("\tp ").append(d(m.getX())).append(',').append(d(m.getY())).append(',').append(d(m.getZ()));
|
||||
Vec3 v = m.getDeltaMovement();
|
||||
sb.append("\tv ").append(d(v.x)).append(',').append(d(v.y)).append(',').append(d(v.z));
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
"""tools/ci/runner_pause.py: the Linux CI runner works only while nobody is at the screen or playing."""
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from tools.ci import runner_pause
|
||||
|
||||
|
||||
class Machine:
|
||||
"""A fake desktop: a clock, who is there, and the runner service. The watcher samples every 15 s."""
|
||||
|
||||
def __init__(self, signs):
|
||||
self.signs = signs # (from, until, reason): a sign of someone at the screen or playing
|
||||
self.clock = 0.0
|
||||
self.active = False
|
||||
self.job_until = None # the runner is in a job until then
|
||||
self.throttles = [] # (clock, on)
|
||||
self.calls = []
|
||||
|
||||
def reason(self, hot, keys):
|
||||
return next((reason for start, end, reason in self.signs if start <= self.clock < end), None)
|
||||
|
||||
def systemctl(self, *arguments):
|
||||
self.calls.append((self.clock, arguments))
|
||||
if arguments[1:] == (runner_pause.SERVICE,):
|
||||
self.active = {"start": True, "stop": False}.get(arguments[0], self.active)
|
||||
return mock.Mock(returncode=0 if arguments[:2] != ("is-active", "--quiet") or self.active else 3)
|
||||
|
||||
def busy(self):
|
||||
return self.job_until is not None and self.clock < self.job_until
|
||||
|
||||
def sleep(self, seconds):
|
||||
self.clock += seconds
|
||||
if self.clock > 2000:
|
||||
raise StopIteration
|
||||
|
||||
def run(self):
|
||||
with tempfile.TemporaryDirectory() as directory, \
|
||||
mock.patch.multiple(runner_pause, MANUAL=Path(directory, "pause"), STATE=Path(directory, "paused"),
|
||||
LOG=Path(directory, "pause.log"), INTERVAL=15, RESUME_AFTER=300,
|
||||
pause_reason=self.reason, systemctl=self.systemctl, runner_busy=self.busy,
|
||||
throttle=lambda on: self.throttles.append((self.clock, on))), \
|
||||
mock.patch.object(runner_pause.time, "monotonic", lambda: self.clock), \
|
||||
mock.patch.object(runner_pause.time, "sleep", self.sleep):
|
||||
try:
|
||||
runner_pause.main()
|
||||
except StopIteration: # the clock ran out
|
||||
pass
|
||||
|
||||
def first(self, verb, after=0):
|
||||
return next(clock for clock, arguments in self.calls
|
||||
if arguments == (verb, runner_pause.SERVICE) and clock >= after)
|
||||
|
||||
|
||||
class RunnerPauseTests(unittest.TestCase):
|
||||
def test_starts_only_after_nobody_was_there_for_resume_after(self):
|
||||
machine = Machine([(0, 600, "session 3 of ludovic at the screen (seat0)")])
|
||||
machine.run()
|
||||
self.assertEqual(machine.first("start"), 585 + 300) # the last sample that saw him
|
||||
|
||||
def test_a_game_stops_an_idle_runner_at_once(self):
|
||||
machine = Machine([(1000, 1300, "process 42: wine64-preloader game.exe")])
|
||||
machine.run()
|
||||
self.assertEqual(machine.first("start"), 300)
|
||||
self.assertEqual(machine.first("stop", after=300), 1005)
|
||||
self.assertEqual(machine.first("start", after=1005), 1290 + 300)
|
||||
|
||||
def test_a_job_under_way_is_throttled_then_stopped_when_it_ends(self):
|
||||
machine = Machine([(1000, 1300, "GPU busy: process 7 (game)")])
|
||||
machine.job_until = 1200
|
||||
machine.run()
|
||||
self.assertIn((1005, True), machine.throttles) # the game started: the job slows down at once,
|
||||
self.assertIn((1005, ("stop", "horizon-parity-worker-*.scope")), machine.calls) # other machines' work goes
|
||||
stop = machine.first("stop", after=300)
|
||||
self.assertGreaterEqual(stop, 1200) # and the runner stops once it ends, not before
|
||||
self.assertLess(stop, 1215)
|
||||
self.assertEqual(machine.throttles[-1], (1290 + 300, False))
|
||||
|
||||
def test_the_desktop_is_free_when_locked_or_untouched_for_15_minutes(self):
|
||||
cases = [ # (session, seconds since the last input, someone there)
|
||||
(("3", False), 30, True), (("3", True), 30, True), # any input pauses at once, even on the lock screen
|
||||
(("3", False), 120, True), (("3", False), 1000, False), # unlocked: free after 15 min untouched
|
||||
(("3", True), 120, False), (None, 120, False), # locked, or nobody logged in
|
||||
]
|
||||
for session, idle, there in cases:
|
||||
with self.subTest(session=session, idle=idle), \
|
||||
mock.patch.object(runner_pause, "seat_session", lambda: session):
|
||||
self.assertEqual(runner_pause.at_the_screen(idle) is not None, there)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Executable
+213
@@ -0,0 +1,213 @@
|
||||
#!/usr/bin/env bash
|
||||
# A Horizon CI runner (labels self-hosted, Linux, X64, horizon-game and the host's name) on a Linux machine of the
|
||||
# maintainer's (NixOS: ludodesktop, ludothinkpad), as a systemd user service of the account that holds his
|
||||
# Minecraft files, like the Mac mini's runners (docs/release-flow.md). Run it on that machine, as that user:
|
||||
#
|
||||
# bash tools/ci/linux-runner.sh install # register (gh login), install, start; again to update the scripts
|
||||
# bash tools/ci/linux-runner.sh status # the services, the runner's state, the pause watcher's last lines
|
||||
# bash tools/ci/linux-runner.sh uninstall # stop and unregister
|
||||
#
|
||||
# Everything lives in ~/.actions-runners/horizon (never in ~/code): the runner, its own rustup and cargo homes,
|
||||
# the work folder, and copies of this script and runner_pause.py taken at install time (a pull request's checkout
|
||||
# never runs as the service). horizon-runner-pause.service (runner_pause.py) starts the runner only while nobody
|
||||
# uses the machine (screen locked or untouched for 15 min, no game), and stops it otherwise. The runner runs nice,
|
||||
# in horizon-ci.slice (low CPU and I/O weight, memory capped), on its own virtual screen: vscreen (a headless sway)
|
||||
# where it is installed, else Xvfb from nixpkgs with Mesa's Vulkan drivers.
|
||||
# HORIZON_SHARED_SOURCE: the imported vanilla data (default ~/horizon-local/shared-local, else
|
||||
# ~/code/horizon/.local); RUNNER_JOBS: cargo jobs and harnesses at once (default a third of the threads, at most 8:
|
||||
# ludodesktop froze under ~7 cold cargo builds on 2026-10-14, and it is the maintainer's own machine).
|
||||
set -euo pipefail
|
||||
repo=ludovic111/horizon
|
||||
dir=$HOME/.actions-runners/horizon
|
||||
units=${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user
|
||||
version=2.338.0
|
||||
sha=af4b794c1bc41d73d40535e3fe092a39f9679cd8d965954c2aca25a05ca41d32
|
||||
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
# Nix packages the jobs need, kept alive by GC roots in $dir/nix. nix-build prints the store path; the root's name
|
||||
# gets the output's suffix (alsa-dev-dev for alsa-lib.dev), so it is not read back from the link.
|
||||
nix_out() { nix-build '<nixpkgs>' -A "$1" -o "$dir/nix/$2" | tail -1; }
|
||||
|
||||
# The runner is a .NET program: on NixOS its native libraries (libstdc++, ICU, OpenSSL) come from nix-ld.
|
||||
export LD_LIBRARY_PATH=/run/current-system/sw/share/nix-ld/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
# NixOS has no /bin/bash: the runner's scripts (again after each of its self-updates) get a portable one.
|
||||
fix_shebangs() { sed -i '1s|^#!/bin/bash|#!/usr/bin/env bash|' "$dir"/*.sh "$dir"/bin/*.sh; }
|
||||
|
||||
# Other machines' parity runs can send harnesses here (tools/parity_hosts.json "desktop": parity.py --worker over
|
||||
# ssh, in horizon-ci.slice). Their vanilla data is the runner checkout's: parity-host/shared-local links to its
|
||||
# .local links, so it follows the preparation of the runner's last job.
|
||||
parity_host_links() {
|
||||
local checkout=$dir/_work/horizon/horizon/.local shared=$dir/parity-host/shared-local entry
|
||||
[ -d "$checkout" ] || return 0
|
||||
mkdir -p "$shared"
|
||||
for entry in "$checkout"/*; do
|
||||
if [ -L "$entry" ]; then ln -sfn "$entry" "$shared/$(basename "$entry")"; fi
|
||||
done
|
||||
}
|
||||
|
||||
display_env() {
|
||||
# The jobs' screen. Never the maintainer's: the user manager hands every service his DISPLAY and WAYLAND_DISPLAY.
|
||||
if command -v vscreen > /dev/null; then
|
||||
VSCREEN=ci-horizon vscreen env
|
||||
else
|
||||
echo "unset WAYLAND_DISPLAY; export DISPLAY=:$(cat "$dir/display")"
|
||||
fi
|
||||
}
|
||||
|
||||
install() {
|
||||
local name=${RUNNER_NAME:-$(hostname)-horizon} threads jobs
|
||||
threads=$(nproc)
|
||||
jobs=${RUNNER_JOBS:-$(( threads / 3 > 8 ? 8 : threads / 3 > 1 ? threads / 3 : 1 ))}
|
||||
local source=${HORIZON_SHARED_SOURCE:-}
|
||||
if [ -z "$source" ]; then
|
||||
for candidate in "$HOME/horizon-local/shared-local" "$HOME/code/horizon/.local"; do
|
||||
[ -d "$candidate/minecraft" ] && { source=$candidate; break; }
|
||||
done
|
||||
fi
|
||||
[ -n "$source" ] && [ -d "$source/minecraft" ] || { echo "no imported Minecraft (HORIZON_SHARED_SOURCE)"; exit 1; }
|
||||
mkdir -p "$dir/nix" "$units"
|
||||
cp "$here/linux-runner.sh" "$here/runner_pause.py" "$dir/"
|
||||
|
||||
if [ ! -f "$dir/.runner" ]; then
|
||||
local cache=$HOME/.cache/gha-runner/actions-runner-linux-x64-$version.tar.gz
|
||||
if ! echo "$sha $cache" | sha256sum -c --quiet - > /dev/null 2>&1; then
|
||||
mkdir -p "$(dirname "$cache")"
|
||||
curl -fsSL -o "$cache" "https://github.com/actions/runner/releases/download/v$version/actions-runner-linux-x64-$version.tar.gz"
|
||||
echo "$sha $cache" | sha256sum -c --quiet -
|
||||
fi
|
||||
tar xzf "$cache" -C "$dir"
|
||||
fix_shebangs
|
||||
gh api -X POST "repos/$repo/actions/runners/registration-token" --jq .token |
|
||||
(cd "$dir" && bash ./config.sh --unattended --replace --url "https://github.com/$repo" --token "$(cat)" \
|
||||
--name "$name" --labels "${RUNNER_LABELS:-horizon-game,$(hostname)}" --work _work > /dev/null)
|
||||
fi
|
||||
|
||||
# Libraries for building (pkg-config) and running (dlopen) the game, the JDK pinned by research-lock.json, sccache.
|
||||
local alsa udev java
|
||||
alsa=$(nix_out alsa-lib.dev alsa-dev)
|
||||
udev=$(nix_out systemd.dev systemd-dev)
|
||||
java=$(nix_out "jdk$(sed -n 's/.*"java_major": *\([0-9]*\).*/\1/p' "$here/../../research-lock.json" | head -1)_headless" jdk)/lib/openjdk
|
||||
nix_out sccache sccache > /dev/null # on the PATH below: runner-env.sh hands it to cargo
|
||||
local libs=/run/opengl-driver/lib:/run/current-system/sw/share/nix-ld/lib
|
||||
if ! command -v vscreen > /dev/null; then
|
||||
local mesa x
|
||||
mesa=$(nix_out mesa mesa)
|
||||
x=$(nix_out xvfb-run xvfb-run)
|
||||
for lib in libx11 libxcursor libxrandr libxi libxext libxinerama libxrender libxxf86vm libxcb libxkbcommon \
|
||||
vulkan-loader libGL; do
|
||||
libs=$libs:$(nix_out "$lib" "$lib")/lib
|
||||
done
|
||||
libs=$mesa/lib:$libs
|
||||
echo "VK_DRIVER_FILES=$mesa/share/vulkan/icd.d/intel_icd.x86_64.json:$mesa/share/vulkan/icd.d/lvp_icd.x86_64.json" \
|
||||
> "$dir/.env.display"
|
||||
echo "$x/bin" > "$dir/.path.display"
|
||||
fi
|
||||
cat > "$dir/.env" <<EOF
|
||||
LANG=C.UTF-8
|
||||
RUSTUP_HOME=$dir/rustup
|
||||
CARGO_HOME=$dir/cargo
|
||||
CARGO_BUILD_JOBS=$jobs
|
||||
PARITY_MACHINE_JOBS=$jobs
|
||||
PARITY_LOCAL_JOBS=$jobs
|
||||
JAVA_HOME=$java
|
||||
HORIZON_SHARED_SOURCE=$source
|
||||
HORIZON_NO_AUDIO=1
|
||||
HORIZON_NO_HEARTBEAT=1
|
||||
HORIZON_TELEMETRY_URL=off
|
||||
HORIZON_LAUNCHER_NO_SELF_UPDATE=1
|
||||
PKG_CONFIG_PATH=$alsa/lib/pkgconfig:$udev/lib/pkgconfig
|
||||
C_INCLUDE_PATH=$udev/include
|
||||
LD_LIBRARY_PATH=$libs
|
||||
NIX_LD=/run/current-system/sw/share/nix-ld/lib/ld.so
|
||||
NIX_LD_LIBRARY_PATH=/run/current-system/sw/share/nix-ld/lib
|
||||
EOF
|
||||
if [ -f "$dir/.env.display" ]; then cat "$dir/.env.display" >> "$dir/.env"; else echo "VSCREEN=ci-horizon" >> "$dir/.env"; fi
|
||||
echo "$dir/cargo/bin:$(cat "$dir/.path.display" 2>/dev/null || true)${dir}/nix/sccache/bin:$java/bin:$HOME/.local/bin:/run/wrappers/bin:/etc/profiles/per-user/$USER/bin:/run/current-system/sw/bin" \
|
||||
| sed 's/::/:/g' > "$dir/.path"
|
||||
|
||||
cat > "$units/horizon-ci.slice" <<EOF
|
||||
[Unit]
|
||||
Description=Horizon CI: the runner's jobs and parity workers sent from other machines
|
||||
[Slice]
|
||||
CPUWeight=20
|
||||
IOWeight=20
|
||||
CPUQuota=$(( threads * 50 ))%
|
||||
MemoryHigh=$(( $(awk '/MemTotal/ {print int($2 / 1048576)}' /proc/meminfo) / 2 ))G
|
||||
MemoryMax=$(( $(awk '/MemTotal/ {print int($2 / 1048576)}' /proc/meminfo) * 2 / 3 ))G
|
||||
EOF
|
||||
cat > "$units/horizon-runner.service" <<EOF
|
||||
[Unit]
|
||||
Description=GitHub Actions runner for $repo (parity), started and stopped by horizon-runner-pause
|
||||
After=network-online.target
|
||||
[Service]
|
||||
Slice=horizon-ci.slice
|
||||
WorkingDirectory=$dir
|
||||
ExecStart=/usr/bin/env bash $dir/linux-runner.sh run
|
||||
Nice=19
|
||||
# runsvc.sh hands SIGTERM to the runner, which stops after cancelling its job; then the rest (Xvfb) goes.
|
||||
KillMode=mixed
|
||||
KillSignal=SIGTERM
|
||||
TimeoutStopSec=5min
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
EOF
|
||||
cat > "$units/horizon-runner-pause.service" <<EOF
|
||||
[Unit]
|
||||
Description=Runs the Horizon CI runner only while nobody uses the machine or plays on it
|
||||
[Service]
|
||||
ExecStart=$(command -v python3) $dir/runner_pause.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
# User services run without a login session (after a reboot): lingering, once.
|
||||
if [ "$(loginctl show-user "$USER" -p Linger --value 2>/dev/null)" != yes ]; then
|
||||
sudo -n loginctl enable-linger "$USER" || echo "Run once: sudo loginctl enable-linger $USER"
|
||||
fi
|
||||
systemctl --user daemon-reload
|
||||
# Only the watcher starts the runner (never the boot itself): it decides whether anyone is at the screen.
|
||||
systemctl --user enable horizon-runner-pause.service > /dev/null
|
||||
# The runner reads .env when it starts: stop it, unless it is in a job (that would cancel the job); the watcher
|
||||
# starts it again when it may run.
|
||||
if pgrep -f "$dir/bin/Runner.Worker" > /dev/null; then echo "In a job: stop horizon-runner.service after it"
|
||||
else systemctl --user stop horizon-runner.service; rm -f "$dir/paused"; fi
|
||||
systemctl --user restart horizon-runner-pause.service
|
||||
status
|
||||
}
|
||||
|
||||
run() {
|
||||
cd "$dir"
|
||||
fix_shebangs
|
||||
parity_host_links
|
||||
if command -v vscreen > /dev/null; then
|
||||
eval "$(display_env)"
|
||||
else
|
||||
# Xvfb on the first free display from :90, for this service's lifetime.
|
||||
local n=90
|
||||
while [ -e "/tmp/.X$n-lock" ]; do n=$((n + 1)); done
|
||||
echo "$n" > "$dir/display"
|
||||
Xvfb ":$n" -screen 0 1280x720x24 -nolisten tcp &
|
||||
eval "$(display_env)"
|
||||
fi
|
||||
exec bash ./bin/runsvc.sh
|
||||
}
|
||||
|
||||
status() {
|
||||
systemctl --user --no-pager list-units 'horizon-runner*' 'vscreen-ci-horizon*'
|
||||
[ -e "$dir/paused" ] && echo "paused: $(cat "$dir/paused")"
|
||||
tail -5 "$dir/pause.log" 2>/dev/null || true
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
systemctl --user disable --now horizon-runner-pause.service horizon-runner.service 2>/dev/null || true
|
||||
gh api -X POST "repos/$repo/actions/runners/remove-token" --jq .token |
|
||||
(cd "$dir" && bash ./config.sh remove --token "$(cat)")
|
||||
rm -f "$units/horizon-runner.service" "$units/horizon-runner-pause.service" "$units/horizon-ci.slice"
|
||||
systemctl --user daemon-reload
|
||||
}
|
||||
|
||||
case ${1:-} in
|
||||
install|run|status|uninstall) "$1" ;;
|
||||
*) sed -n '2,10p' "$0"; exit 2 ;;
|
||||
esac
|
||||
+29
-3
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# The tools the vanilla harnesses need, on the self-hosted Mac mini runner (label horizon-game): its service
|
||||
# starts with a bare PATH. Python 3.13 and the JDK pinned by research-lock.json come from the machine, never
|
||||
# from a download. Writes them to $GITHUB_PATH and $GITHUB_ENV for the next steps.
|
||||
# The tools the vanilla harnesses need, on a self-hosted runner (label horizon-game): the Mac mini's, whose service
|
||||
# starts with a bare PATH, and the Linux ones (tools/ci/linux-runner.sh, NixOS). Python 3.13 and the JDK pinned by
|
||||
# research-lock.json come from the machine, never from a download. Writes them to $GITHUB_PATH and $GITHUB_ENV for
|
||||
# the next steps.
|
||||
set -euo pipefail
|
||||
java_major=$(sed -n 's/.*"java_major": *\([0-9]*\).*/\1/p' research-lock.json | head -1)
|
||||
bin="$RUNNER_TEMP/horizon-bin"
|
||||
@@ -17,5 +18,30 @@ if [ "$(uname)" = Darwin ]; then
|
||||
if [ -x /opt/homebrew/bin/sccache ]; then
|
||||
{ echo "RUSTC_WRAPPER=/opt/homebrew/bin/sccache"; echo "CARGO_INCREMENTAL=0"; } >> "$GITHUB_ENV"
|
||||
fi
|
||||
else
|
||||
python=$(command -v python3.13 || true)
|
||||
[ -n "$python" ] || { echo "::error::no python3.13 on this runner"; exit 1; }
|
||||
ln -sfn "$python" "$bin/python3"
|
||||
ln -sfn "$python" "$bin/python"
|
||||
# The JDK: the runner's JAVA_HOME (linux-runner.sh pins one), else the java on PATH, else nixpkgs' jdk<major>.
|
||||
major_of() { "$1/bin/java" -version 2>&1 | sed -n 's/.*version "\([0-9]*\).*/\1/p' | head -1; }
|
||||
java_home=${JAVA_HOME:-}
|
||||
if [ -z "$java_home" ] || [ "$(major_of "$java_home")" != "$java_major" ]; then
|
||||
java_home=""
|
||||
if command -v java > /dev/null; then
|
||||
candidate=$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")
|
||||
[ "$(major_of "$candidate")" = "$java_major" ] && java_home=$candidate
|
||||
fi
|
||||
fi
|
||||
if [ -z "$java_home" ] && command -v nix-build > /dev/null; then
|
||||
out=$(nix-build '<nixpkgs>' --no-out-link -A "jdk${java_major}_headless" 2>/dev/null || true)
|
||||
[ -n "$out" ] && java_home=$out/lib/openjdk
|
||||
fi
|
||||
[ -n "$java_home" ] || { echo "::error::no JDK $java_major on this runner"; exit 1; }
|
||||
{ echo "$bin"; echo "$java_home/bin"; } >> "$GITHUB_PATH"
|
||||
echo "JAVA_HOME=$java_home" >> "$GITHUB_ENV"
|
||||
if sccache=$(command -v sccache); then
|
||||
{ echo "RUSTC_WRAPPER=$sccache"; echo "CARGO_INCREMENTAL=0"; } >> "$GITHUB_ENV"
|
||||
fi
|
||||
fi
|
||||
echo "HORIZON_NO_AUDIO=1" >> "$GITHUB_ENV"
|
||||
|
||||
Executable
+266
@@ -0,0 +1,266 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Pauses the Horizon CI runner (tools/ci/linux-runner.sh) while the maintainer uses this machine or plays on it.
|
||||
|
||||
The runner works while nobody uses the machine: its screen locked, or untouched for IDLE_AFTER seconds (900).
|
||||
It pauses when any of these holds:
|
||||
- keyboard, mouse or gamepad input in the last INPUT_PAUSE seconds (60), or an unlocked session on seat0 with
|
||||
input in the last IDLE_AFTER seconds;
|
||||
- the CPU package at TEMP_LIMIT °C (90) or more (the median of 5 readings);
|
||||
- fleet-load says a game runs (~/fleet/load: Steam, gamescope, Wine or Proton processes);
|
||||
- a process of his matches GAME below (the same, plus Minecraft and a Horizon game he started himself);
|
||||
- a process outside horizon-ci.slice keeps the GPU busy (nvidia-smi: SM use >= GPU_BUSY %, default 50, in two
|
||||
samples in a row; the browser, Discord and the compositor stay under 20 %);
|
||||
- ~/.actions-runners/horizon/pause exists (pause by hand: `touch` it; `rm` it to let the watcher decide).
|
||||
|
||||
Paused, the runner takes no new job: while it is idle its service is stopped, so GitHub sends the jobs to the
|
||||
Mac mini, and the parity workers other machines started here stop (their harnesses go back to those machines). A
|
||||
job already running is throttled, not stopped: horizon-ci.slice drops to CPU weight 1, I/O weight 1 and a quota of
|
||||
THROTTLE_CPUS threads, and the service stops once the job ends. Freezing it (SIGSTOP or the cgroup freezer)
|
||||
would stop the runner's heartbeat, so GitHub would drop the job as lost, and the harnesses' wall-clock timeouts
|
||||
would fail runs that were only waiting. The runner comes back RESUME_AFTER seconds after the last of these signs.
|
||||
Every change is written to ~/.actions-runners/horizon/pause.log.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
DIR = Path.home() / ".actions-runners" / "horizon"
|
||||
SERVICE, SLICE = "horizon-runner.service", "horizon-ci.slice"
|
||||
MANUAL, STATE, LOG = DIR / "pause", DIR / "paused", DIR / "pause.log"
|
||||
GAME = re.compile(r"(SteamLaunch|gamescope|wine64-preloader|wineserver|wine-preloader|\.exe(\s|$)|proton\b"
|
||||
r"|net\.minecraft\.client\.main\.Main|minecraft-launcher|prismlauncher)", re.I)
|
||||
GPU_BUSY = int(os.environ.get("GPU_BUSY", 50))
|
||||
INTERVAL = int(os.environ.get("INTERVAL", 15))
|
||||
RESUME_AFTER = int(os.environ.get("RESUME_AFTER", 300))
|
||||
THROTTLE_CPUS = int(os.environ.get("THROTTLE_CPUS", 2))
|
||||
# Working, the slice gets half the threads: on all of them ludodesktop's CPU sits at 92 °C through a cargo build.
|
||||
NORMAL_CPUS = int(os.environ.get("NORMAL_CPUS", max(1, (os.cpu_count() or 2) // 2)))
|
||||
INPUT_PAUSE = int(os.environ.get("INPUT_PAUSE", 60))
|
||||
IDLE_AFTER = int(os.environ.get("IDLE_AFTER", 900))
|
||||
TEMP_LIMIT = int(os.environ.get("TEMP_LIMIT", 90))
|
||||
|
||||
|
||||
def log(text):
|
||||
with LOG.open("a") as handle:
|
||||
handle.write(f"{time.strftime('%Y-%m-%dT%H:%M:%S')} {text}\n")
|
||||
|
||||
|
||||
def systemctl(*arguments):
|
||||
return subprocess.run(["systemctl", "--user", *arguments], capture_output=True, text=True)
|
||||
|
||||
|
||||
def ci_process(pid):
|
||||
"""A process of the runner's slice (its jobs, the parity workers other machines start here)."""
|
||||
try:
|
||||
return SLICE in Path(f"/proc/{pid}/cgroup").read_text()
|
||||
except OSError:
|
||||
return True # gone
|
||||
|
||||
|
||||
class Input:
|
||||
"""Keyboard, mouse and gamepad activity, from /dev/input (the input group): only whether bytes came, never what."""
|
||||
|
||||
def __init__(self):
|
||||
self.devices = {} # path -> file descriptor
|
||||
self.last = 0.0 # the boot (the monotonic clock's zero on Linux) counts as input
|
||||
|
||||
def poll(self):
|
||||
try:
|
||||
text = Path("/proc/bus/input/devices").read_text()
|
||||
except OSError:
|
||||
text = ""
|
||||
wanted = {f"/dev/input/{handler}" for block in text.split("\n\n") for line in block.splitlines()
|
||||
if line.startswith("H: Handlers=") and re.search(r"\b(kbd|mouse\d*|js\d*)\b", line)
|
||||
for handler in line.split("=", 1)[1].split() if handler.startswith("event")}
|
||||
for path in set(self.devices) - wanted:
|
||||
os.close(self.devices.pop(path))
|
||||
for path in wanted - set(self.devices):
|
||||
try:
|
||||
self.devices[path] = os.open(path, os.O_RDONLY | os.O_NONBLOCK)
|
||||
except OSError:
|
||||
pass
|
||||
for path, descriptor in list(self.devices.items()):
|
||||
try:
|
||||
while os.read(descriptor, 4096):
|
||||
self.last = time.monotonic()
|
||||
except BlockingIOError:
|
||||
pass
|
||||
except OSError: # unplugged
|
||||
os.close(self.devices.pop(path))
|
||||
return time.monotonic() - self.last
|
||||
|
||||
|
||||
def seat_session():
|
||||
"""The graphical session on seat0 and whether its screen is locked, or None."""
|
||||
sessions = subprocess.run(["loginctl", "list-sessions", "--no-legend"], capture_output=True, text=True).stdout
|
||||
for line in sessions.splitlines():
|
||||
fields = line.split()
|
||||
if "seat0" in fields:
|
||||
locked = subprocess.run(["loginctl", "show-session", fields[0], "-p", "LockedHint", "--value"],
|
||||
capture_output=True, text=True).stdout.strip() == "yes"
|
||||
return fields[0], locked
|
||||
return None
|
||||
|
||||
|
||||
def at_the_screen(input_idle):
|
||||
"""Someone is at the machine: input in the last INPUT_PAUSE seconds, or an unlocked session with input in the last
|
||||
IDLE_AFTER seconds. A locked screen, or one nobody touched for IDLE_AFTER, leaves the machine to CI."""
|
||||
if input_idle < INPUT_PAUSE:
|
||||
return f"input {input_idle:.0f} s ago"
|
||||
session = seat_session()
|
||||
if session and not session[1] and input_idle < IDLE_AFTER:
|
||||
return f"session {session[0]} unlocked, input {input_idle:.0f} s ago"
|
||||
return None
|
||||
|
||||
|
||||
def too_hot():
|
||||
"""The CPU package at TEMP_LIMIT °C or more (coretemp or k10temp), as the median of 5 readings over 2 s: under
|
||||
load it jumps for a second at a time (to 96 °C on ludodesktop at a median of 68 °C), which is no reason to stop."""
|
||||
for monitor in Path("/sys/class/hwmon").glob("hwmon*"):
|
||||
try:
|
||||
if (monitor / "name").read_text().strip() not in ("coretemp", "k10temp"):
|
||||
continue
|
||||
readings = []
|
||||
for _ in range(5):
|
||||
readings.append(int((monitor / "temp1_input").read_text()) / 1000)
|
||||
time.sleep(0.5)
|
||||
except (OSError, ValueError):
|
||||
continue
|
||||
celsius = sorted(readings)[2]
|
||||
return f"CPU at {celsius:.0f} °C" if celsius >= TEMP_LIMIT else None
|
||||
return None
|
||||
|
||||
|
||||
def fleet_load_gaming():
|
||||
status = Path(os.environ.get("XDG_RUNTIME_DIR", f"/run/user/{os.getuid()}")) / "fleet-load" / "status.json"
|
||||
try:
|
||||
if time.time() - status.stat().st_mtime > 120:
|
||||
return None
|
||||
return "fleet-load: playing a game" if json.loads(status.read_text())["human"]["gaming"] else None
|
||||
except (OSError, ValueError, KeyError, TypeError):
|
||||
return None
|
||||
|
||||
|
||||
def game_process():
|
||||
uid = os.getuid()
|
||||
for entry in Path("/proc").iterdir():
|
||||
if not entry.name.isdigit():
|
||||
continue
|
||||
try:
|
||||
if entry.stat().st_uid != uid:
|
||||
continue
|
||||
command = (entry / "cmdline").read_bytes().replace(b"\0", b" ").decode(errors="replace")
|
||||
except OSError:
|
||||
continue
|
||||
# A Horizon game counts when he started it (its parent is his launcher), not when a harness or agent did.
|
||||
if GAME.search(command) or (" --offscreen" not in command and "/horizon-launcher/" in command
|
||||
and "horizon-client" in command.split(" ")[0]):
|
||||
if not ci_process(int(entry.name)):
|
||||
return f"process {entry.name}: {command[:120]}"
|
||||
return None
|
||||
|
||||
|
||||
def gpu_users():
|
||||
"""Processes outside the CI slice using the GPU's shader cores, as {pid: SM %}."""
|
||||
try:
|
||||
# Two samples: the first one nvidia-smi prints has no utilisation yet.
|
||||
output = subprocess.run(["nvidia-smi", "pmon", "-c", "2", "-s", "u"], capture_output=True, text=True,
|
||||
timeout=20).stdout
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
return {}
|
||||
users = {}
|
||||
for line in output.splitlines():
|
||||
fields = line.split()
|
||||
if line.startswith("#") or len(fields) < 4 or not fields[1].isdigit() or not fields[3].isdigit():
|
||||
continue
|
||||
if not ci_process(int(fields[1])):
|
||||
users[int(fields[1])] = max(users.get(int(fields[1]), 0), int(fields[3]))
|
||||
return users
|
||||
|
||||
|
||||
def runner_busy():
|
||||
"""The runner is in a job: a Runner.Worker runs in its service."""
|
||||
group = systemctl("show", "-p", "ControlGroup", "--value", SERVICE).stdout.strip()
|
||||
try:
|
||||
pids = Path(f"/sys/fs/cgroup{group}/cgroup.procs").read_text().split() if group else []
|
||||
except OSError:
|
||||
return False
|
||||
for pid in pids:
|
||||
try:
|
||||
if Path(f"/proc/{pid}/comm").read_text().strip() == "Runner.Worker":
|
||||
return True
|
||||
except OSError:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def throttle(on):
|
||||
if on:
|
||||
systemctl("set-property", "--runtime", SLICE, "CPUWeight=1", "IOWeight=1", f"CPUQuota={THROTTLE_CPUS * 100}%")
|
||||
else:
|
||||
systemctl("set-property", "--runtime", SLICE, "CPUWeight=20", "IOWeight=20", f"CPUQuota={NORMAL_CPUS * 100}%")
|
||||
|
||||
|
||||
def pause_reason(hot, keys):
|
||||
"""Why the runner may not work now, or None. hot: the GPU users seen busy at the last sample (updated);
|
||||
keys: the Input watcher."""
|
||||
if MANUAL.exists():
|
||||
return f"paused by hand ({MANUAL})"
|
||||
reason = at_the_screen(keys.poll()) or too_hot() or fleet_load_gaming() or game_process()
|
||||
if reason:
|
||||
return reason
|
||||
busy = {pid for pid, sm in gpu_users().items() if sm >= GPU_BUSY}
|
||||
twice = sorted(busy & set(hot))
|
||||
hot.clear()
|
||||
hot.update(dict.fromkeys(busy))
|
||||
if twice:
|
||||
try:
|
||||
name = Path(f"/proc/{twice[0]}/comm").read_text().strip()
|
||||
except OSError:
|
||||
name = "?"
|
||||
return f"GPU busy: process {twice[0]} ({name})"
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
hot, keys = {}, Input()
|
||||
# The boot counts as a sign: the runner starts RESUME_AFTER seconds after it at the earliest, which leaves time
|
||||
# to log in after switching the machine on. Restarting this watcher later changes nothing for a running job.
|
||||
last_sign = 0.0
|
||||
paused = None
|
||||
while True:
|
||||
reason = pause_reason(hot, keys)
|
||||
now = time.monotonic()
|
||||
if reason:
|
||||
last_sign = now
|
||||
active = systemctl("is-active", "--quiet", SERVICE).returncode == 0
|
||||
if reason or now - last_sign < RESUME_AFTER:
|
||||
if paused is not True:
|
||||
paused = True
|
||||
STATE.write_text((reason or "starting") + "\n")
|
||||
throttle(True)
|
||||
# Parity workers other machines started here (tools/parity_hosts.json): they stop, and those
|
||||
# machines run the harnesses themselves.
|
||||
systemctl("stop", "horizon-parity-worker-*.scope")
|
||||
log(f"pause: {reason or 'waiting ' + str(RESUME_AFTER) + ' s after starting'}"
|
||||
+ (f"; a job is running: throttled to {THROTTLE_CPUS} threads, stops after it" if active else ""))
|
||||
if active and not runner_busy():
|
||||
systemctl("stop", SERVICE)
|
||||
log("runner stopped")
|
||||
else:
|
||||
if paused is not False:
|
||||
paused = False
|
||||
STATE.unlink(missing_ok=True)
|
||||
throttle(False)
|
||||
log(f"resume: nobody at the screen and no game for {RESUME_AFTER} s")
|
||||
if not active:
|
||||
systemctl("start", SERVICE)
|
||||
log("runner started")
|
||||
time.sleep(INTERVAL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# The vanilla data for this checkout on the self-hosted runner. Horizon never downloads the game: the runner
|
||||
# holds the maintainer's own copy, imported and decompiled once (HORIZON_SHARED_SOURCE, default
|
||||
# ~/code/horizon-parity/shared-local). It is cloned once into the runner's work folder ($RUNNER_WORKSPACE/
|
||||
# shared-local; APFS clones, so no second copy of the bytes), and .local/ links to it as in a parity worktree.
|
||||
# ~/code/horizon-parity/shared-local; tools/ci/linux-runner.sh sets it on Linux). It is cloned once into the runner's
|
||||
# work folder ($RUNNER_WORKSPACE/shared-local; APFS clones, or reflinks where the file system has them, so no second
|
||||
# copy of the bytes), and .local/ links to it as in a parity worktree.
|
||||
# .local/horizon-client and the exporter outputs beside it, what horizon-prepare makes, are prepared by this
|
||||
# checkout's own preparer once per preparer version (its sources, the exporters and research-lock.json), so a
|
||||
# change to the preparer is checked with what it prepares; the four newest preparations are kept.
|
||||
@@ -31,7 +32,8 @@ for entry in "$shared"/*; do
|
||||
done
|
||||
|
||||
# HORIZON_PREPARE_KEY: the same key, computed where the Git history is (tools/pr_ready.py on another machine).
|
||||
key=${HORIZON_PREPARE_KEY:-$(git ls-files -s crates/horizon-prepare mods/horizon/src/test/java research-lock.json | shasum -a 256 | cut -c1-16)}
|
||||
sha256() { if command -v shasum > /dev/null; then shasum -a 256; else sha256sum; fi; }
|
||||
key=${HORIZON_PREPARE_KEY:-$(git ls-files -s crates/horizon-prepare mods/horizon/src/test/java research-lock.json | sha256 | cut -c1-16)}
|
||||
prepared="$shared/prepared/$key"
|
||||
# Two runners share the vanilla data (~/.actions-runners/horizon-2/_work/horizon/shared-local links to the first
|
||||
# one's): one preparation at a time. A lock older than 30 minutes belongs to a job that died.
|
||||
|
||||
+135
-7
@@ -52,9 +52,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
- grindstone: a grindstone opens on the guest's screen; the enchanted sword the guest shift-clicks in
|
||||
shows the server's result, and the guest takes it with only its curse left and the
|
||||
experience orbs the server awards (#868);
|
||||
- anvil: an anvil opens on the guest's screen; the guest repairs a sword with iron ingots and
|
||||
renames it (ServerboundRenameItemPacket), takes it for the server's level cost, and the
|
||||
server has the repaired, renamed sword (#868);
|
||||
- anvil: each player repairs and renames a sword (ServerboundRenameItemPacket), takes it for
|
||||
the server's level cost, and the server has the repaired, renamed sword (#868);
|
||||
both players hear exactly one anvil sound for each result (#1907);
|
||||
- enchanting: an enchanting table opens on the guest's screen with the server's offers for the
|
||||
sword the guest puts in; the guest clicks the first offer and the server enchants the
|
||||
sword for a level and a lapis, and counts it in the guest's enchant_item stat (#868);
|
||||
@@ -250,6 +250,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
- falling: an item and a falling block the host summons high up fall smoothly on the guest, a
|
||||
little further every tick between the server's updates (every 20 ticks), as their own
|
||||
client tick moves them (they used to hang, then jump down once a second, #1568).
|
||||
- instant_digging: an instant survival break leaves no repeated stone hit sounds or stale server dig (#1908).
|
||||
- replant: flowers and crops replanted after a short harvest click stay planted for both players;
|
||||
the server forgets the completed instant break (#1880).
|
||||
|
||||
Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of
|
||||
both sides go to --out (host-*.png, guest-*.png).
|
||||
@@ -1620,6 +1623,12 @@ def check_grindstone(host, guest, out):
|
||||
|
||||
|
||||
def check_anvil(host, guest, out):
|
||||
# AnvilMenu.onTake emits one level event to everyone, including the user.
|
||||
# Exercise both the in-frame host and a remote user (both remote with --server-thread).
|
||||
return {actor.name: check_anvil_user(actor, (host, guest), out) for actor in (guest, host)}
|
||||
|
||||
|
||||
def check_anvil_user(guest, listeners, out):
|
||||
guest('command', command='gamemode survival')
|
||||
guest('command', command='clear @s')
|
||||
guest('command', command='xp set @s 5 levels')
|
||||
@@ -1638,8 +1647,12 @@ def check_anvil(host, guest, out):
|
||||
menu = guest.raw('menu')
|
||||
offered = (menu['info']['anvil_cost'], station_slots(guest).get(650))
|
||||
guest.shot(out, 'anvil-rename')
|
||||
sounds = ('minecraft:block.anvil.use', 'minecraft:block.anvil.destroy')
|
||||
before = {g.name: sum(heard(g, s) for s in sounds) for g in listeners}
|
||||
guest.raw('click-slot', 650, 'shift')
|
||||
guest.wait(10)
|
||||
guest.wait(20)
|
||||
sound_counts = {g.name: sum(heard(g, s) for s in sounds) - before[g.name] for g in listeners}
|
||||
assert sound_counts == {g.name: 1 for g in listeners}, f'anvil sounds: {sound_counts}'
|
||||
left = station_slots(guest)
|
||||
close_station(guest, at)
|
||||
sword = server_reply(guest, 'data get entity @s Inventory[{id:"minecraft:iron_sword"}].components',
|
||||
@@ -1653,7 +1666,7 @@ def check_anvil(host, guest, out):
|
||||
want = {'offered': (4, ('minecraft:iron_sword', 1)), 'left': {}, 'name': True, 'damage': True,
|
||||
'levels': 1, 'ingots': 0}
|
||||
assert seen == want, f'the anvil on the guest: {seen} ({sword!r})'
|
||||
return seen
|
||||
return {**seen, 'heard': sound_counts}
|
||||
|
||||
|
||||
def check_smithing(host, guest, out):
|
||||
@@ -3762,17 +3775,21 @@ def check_frames(host, guest, out):
|
||||
# Within a survival player's 3 blocks of reach: a frame on a wall, an armor stand beside it.
|
||||
player('command', command=f'fill {x - 2} {y} {z + 1} {x + 2} {y + 2} {z + 2} minecraft:air')
|
||||
player('command', command=f'fill {x - 2} {y} {z + 3} {x + 2} {y + 2} {z + 3} minecraft:stone')
|
||||
player('command', command=f'summon minecraft:item_frame {x + 0.5} {y + 1.5} {z + 2.97} '
|
||||
frame_kind = 'item_frame' if label == 'host' else 'glow_item_frame'
|
||||
player('command', command=f'summon minecraft:{frame_kind} {x + 0.5} {y + 1.5} {z + 2.97} '
|
||||
f'{{block_pos:[I;{x},{y + 1},{z + 2}],Facing:2b}}')
|
||||
player('command', command=f'summon minecraft:armor_stand {x - 1.5} {y} {z + 1.5}')
|
||||
player('command', command='clear @s')
|
||||
player('command', command='item replace entity @s weapon.mainhand with minecraft:diamond')
|
||||
frame_name = f'{label} framed diamond'
|
||||
player('command', command='item replace entity @s weapon.mainhand with '
|
||||
f"minecraft:diamond[minecraft:custom_name='{frame_name}']")
|
||||
player.wait(30)
|
||||
try:
|
||||
frame = [o for o in player('status')['objects'] if o['kind'].endswith('item_frame')
|
||||
and o['position'] == [x, y + 1, z + 2]]
|
||||
assert frame, f'the {label} sees no item frame at {[x, y + 1, z + 2]}'
|
||||
player.raw('look-at', f'{x + 0.5:.2f}', f'{y + 1.5:.2f}', f'{z + 2.95:.2f}')
|
||||
assert frame_name not in (player('status').get('name_tags') or []), 'empty frame name visible'
|
||||
player.raw('mouse', 'right', 'click')
|
||||
player.wait(10)
|
||||
player.raw('mouse', 'right', 'click')
|
||||
@@ -3780,6 +3797,15 @@ def check_frames(host, guest, out):
|
||||
frame = [o for o in player('status')['objects'] if o['id'] == frame[0]['id']][0]
|
||||
assert frame['item'] == 'minecraft:diamond', f'the {label}\'s frame holds {frame["item"]}'
|
||||
assert frame['rotation'] == 1, f'the {label}\'s frame turned to {frame["rotation"]}'
|
||||
assert frame_name in (player('status').get('name_tags') or []), \
|
||||
f"the {label}'s targeted frame has no item name"
|
||||
player.shot(out, f'{label}-framed-item-name')
|
||||
player.raw('key', 'f1', 'tap')
|
||||
player.wait(2)
|
||||
assert frame_name not in (player('status').get('name_tags') or []), 'F1 left the frame name visible'
|
||||
player.raw('key', 'f1', 'tap')
|
||||
player.raw('look-at', f'{x + 2:.2f}', f'{y + 1.5:.2f}', f'{z + 2.95:.2f}')
|
||||
assert frame_name not in (player('status').get('name_tags') or []), 'untargeted frame name visible'
|
||||
theirs = [o for o in other('status')['objects'] if o['kind'].endswith('item_frame')
|
||||
and o['position'] == [x, y + 1, z + 2]]
|
||||
assert theirs and theirs[0]['item'] == 'minecraft:diamond' and theirs[0]['rotation'] == 1, \
|
||||
@@ -5396,6 +5422,42 @@ CHECKS += ['digging']
|
||||
CHECK_FNS.update(digging=check_digging)
|
||||
|
||||
|
||||
def check_instant_digging(host, guest, out):
|
||||
"""#1908: an instant survival START has no STOP. ServerPlayerGameMode.tick
|
||||
forgets a dig once its block is air; it must neither hit air nor break a replacement.
|
||||
Exercise the in-frame host and network guest (both are clients with --server-thread).
|
||||
"""
|
||||
result = {}
|
||||
for label, player in (('host', host), ('guest', guest)):
|
||||
x, y, z = (int(v // 1) for v in pos_of(player))
|
||||
cell = (x, y + 1, z + 2)
|
||||
player('command', command='gamemode survival')
|
||||
player('command', command='clear @s')
|
||||
host('command', command=f'fill {x - 1} {y} {z + 1} {x + 1} {y + 3} {z + 4} minecraft:air')
|
||||
host('command', command=f'setblock {x} {y} {z + 2} minecraft:sand')
|
||||
host('command', command=f'setblock {cell[0]} {cell[1]} {cell[2]} minecraft:dead_bush')
|
||||
player.wait(10)
|
||||
before = heard(player, 'minecraft:block.stone.hit')
|
||||
player.raw('look-at', x + 0.5, y + 1.4, z + 2.5)
|
||||
player.raw('mouse', 'left', 'click')
|
||||
player.wait(20)
|
||||
broken = host.raw('block', *cell).get('block')
|
||||
hits = heard(player, 'minecraft:block.stone.hit') - before
|
||||
host('command', command=f'setblock {cell[0]} {cell[1]} {cell[2]} minecraft:dead_bush')
|
||||
player.wait(20)
|
||||
replacement = host.raw('block', *cell).get('block')
|
||||
result[label] = {'broken': broken, 'stone_hits': hits, 'replacement': replacement}
|
||||
assert broken == 'minecraft:air', f'{label}: the bush did not break: {result}'
|
||||
assert hits == 0, f'{label}: hitting air after an instant break: {result}'
|
||||
assert replacement == 'minecraft:dead_bush', f'{label}: the server kept digging: {result}'
|
||||
host('command', command=f'setblock {cell[0]} {cell[1]} {cell[2]} minecraft:air')
|
||||
return result
|
||||
|
||||
|
||||
CHECKS += ['instant_digging']
|
||||
CHECK_FNS.update(instant_digging=check_instant_digging)
|
||||
|
||||
|
||||
def check_vehicles(host, guest, out):
|
||||
"""The host and the guest each (#1551):
|
||||
- in creative, break a block and have it put back: the server's dig ends with the break
|
||||
@@ -6486,5 +6548,71 @@ CHECKS += ['critical-hits']
|
||||
CHECK_FNS['critical-hits'] = check_critical_hits
|
||||
|
||||
|
||||
def check_replant(host, guest, out):
|
||||
"""Instant breaks leave no server dig that can destroy a replacement (#1880).
|
||||
|
||||
ServerPlayerGameMode.handleBlockBreakAction's insta-mine branch finishes on
|
||||
START; MultiPlayerGameMode sends no STOP or ABORT when attack is released.
|
||||
Exercise actual flower placement and seed planting after a short click.
|
||||
"""
|
||||
spots = apart(host, guest)
|
||||
seen = {}
|
||||
host('command', command='gamerule random_tick_speed 0')
|
||||
try:
|
||||
for label, player in (('host', host), ('guest', guest)):
|
||||
x, y, z = spots[label]
|
||||
cell = (x, y, z + 2)
|
||||
|
||||
def observe(block):
|
||||
# The integrated host is itself a client: wait for both views.
|
||||
for _ in range(40):
|
||||
blocks = [g.raw('block', *cell).get('block') for g in (host, guest)]
|
||||
if blocks == [f'minecraft:{block}'] * 2:
|
||||
return blocks
|
||||
host.wait(2)
|
||||
raise AssertionError(f'{label} expected {block} on both clients: {blocks}')
|
||||
|
||||
for mode, block, item, soil in (
|
||||
('survival', 'dandelion', 'dandelion', 'dirt'),
|
||||
('survival', 'wheat', 'wheat_seeds', 'farmland[moisture=7]'),
|
||||
('survival', 'carrots', 'carrot', 'farmland[moisture=7]'),
|
||||
('creative', 'dandelion', 'dandelion', 'dirt'),
|
||||
):
|
||||
player('command', command=f'gamemode {mode}')
|
||||
player('command', command='clear @s')
|
||||
player('command', command=f'item replace entity @s weapon.mainhand with minecraft:{item} 8')
|
||||
player('command', command=f'setblock {x} {y - 1} {z + 2} minecraft:{soil}')
|
||||
player('command', command=f'setblock {x} {y} {z + 2} minecraft:{block}')
|
||||
player.wait(5)
|
||||
observe(block)
|
||||
# Flowers' narrow outlines have a position-dependent offset.
|
||||
for dx in (0.0, -0.2, 0.2):
|
||||
player.raw('look-at', x + 0.5 + dx, y + (0.3 if block == 'dandelion' else 0.1), z + 2.5)
|
||||
target = player('looking_at').get('block') or {}
|
||||
if target.get('pos') == list(cell):
|
||||
break
|
||||
assert target.get('pos') == list(cell), f'{label} does not aim at {block}: {target}'
|
||||
player.raw('mouse', 'left', 'click')
|
||||
player.wait(5)
|
||||
observe('air')
|
||||
# Keep aiming at the supporting soil and use the held flower/seeds.
|
||||
player.raw('mouse', 'right', 'click')
|
||||
player.wait(3)
|
||||
observe(block)
|
||||
player.wait(20) # past the stale dig's five-tick destroy delay
|
||||
key = f'{label} {mode} {block}'
|
||||
seen[key] = [g.raw('block', *cell).get('block') for g in (host, guest)]
|
||||
player.shot(out, f'replant-{mode}-{block}')
|
||||
assert seen[key] == [f'minecraft:{block}'] * 2, f'{key}: {seen}'
|
||||
player('command', command=f'setblock {x} {y} {z + 2} minecraft:air')
|
||||
finally:
|
||||
host('command', command='gamerule random_tick_speed 3')
|
||||
return seen
|
||||
|
||||
|
||||
CHECKS += ['replant']
|
||||
CHECK_FNS['replant'] = check_replant
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -11,6 +11,15 @@
|
||||
"jobs": 14,
|
||||
"exclude": {}
|
||||
},
|
||||
"desktop": {
|
||||
"ssh": "desktop",
|
||||
"root": ".actions-runners/horizon/parity-host",
|
||||
"shell": "systemd-run --user --scope --quiet --slice=horizon-ci.slice --unit=horizon-parity-worker-$$ bash -c",
|
||||
"setup": "test ! -e ~/.actions-runners/horizon/paused && set -a && . ~/.actions-runners/horizon/.env && set +a && export PATH=$(cat ~/.actions-runners/horizon/.path) && eval \"$(vscreen env)\"",
|
||||
"jobs": 8,
|
||||
"nice": 19,
|
||||
"note": "ludodesktop, the maintainer's own machine: only while nobody uses it (tools/ci/runner_pause.py: screen locked or untouched for 15 min, no game; a paused desktop refuses workers and stops the running ones, whose harnesses then run here); 8 jobs at most, in the CI runner's environment and slice"
|
||||
},
|
||||
"thinkpad": {
|
||||
"ssh": "thinkpad",
|
||||
"root": "code/horizon-parity",
|
||||
|
||||
@@ -191,6 +191,16 @@ def scenarios():
|
||||
'mob minecraft:wandering_trader 0.5 -60 0.5 0 104 persistent',
|
||||
'mob minecraft:trader_llama 3.5 -60 1.5 0 105 persistent leashto=0 strength=2',
|
||||
'mob minecraft:trader_llama 3.5 -60 -1.5 0 106 persistent leashto=0 strength=4'])
|
||||
# Death must detach immediately and drop exactly one lead throughout the corpse animation.
|
||||
add('leash_death_trader_llama', 10, [
|
||||
'player 14.5 -60 0.5',
|
||||
'mob minecraft:wandering_trader 0.5 -60 0.5 0 104 persistent',
|
||||
'mob minecraft:trader_llama 3.5 -60 1.5 0 105 persistent leashto=0 strength=2 dead',
|
||||
])
|
||||
add('leash_death_player_llama', 10, [
|
||||
'player 0.5 -60 0.5',
|
||||
'mob minecraft:llama 3.5 -60 0.5 0 101 persistent leashed strength=3 dead',
|
||||
])
|
||||
# Copper golems sorting chests (TransportItemsBetweenContainers): from a copper chest to a chest,
|
||||
# skipping a chest without the carried item, queueing at a chest another golem has open, a double
|
||||
# chest, a blocked copper chest, a part-full chest, and idling with nothing to carry.
|
||||
@@ -358,6 +368,9 @@ def parse(path):
|
||||
if parts[1] == 'hive':
|
||||
cur.setdefault('hives', {}).setdefault(t, []).append(parts[2])
|
||||
continue
|
||||
if parts[1] == 'leads':
|
||||
cur.setdefault('leads', {}).setdefault(t, []).append(parts[2])
|
||||
continue
|
||||
if parts[1] == 'chest':
|
||||
cur.setdefault('chests', {}).setdefault(t, []).append(parts[2])
|
||||
continue
|
||||
@@ -455,7 +468,7 @@ def compare(vanilla, rust, fields=None):
|
||||
clean = False
|
||||
break
|
||||
# Sounds, watched block changes, chest contents and hives: first differing tick.
|
||||
for kind in ('sounds', 'blocks', 'chests', 'hives'):
|
||||
for kind in ('sounds', 'blocks', 'chests', 'hives', 'leads'):
|
||||
va, ra = v.get(kind, {}), r.get(kind, {})
|
||||
for t in sorted(set(va) | set(ra)):
|
||||
if va.get(t, []) != ra.get(t, []):
|
||||
|
||||
Reference in New Issue
Block a user