@@ -73,6 +73,42 @@ jobs:
|
||||
run: |
|
||||
cargo +stable test --workspace --lib --bins --tests --features horizon-client/mods,horizon-mods/pack
|
||||
cargo +stable test --workspace --doc --features horizon-client/mods,horizon-mods/pack
|
||||
# The launcher is its own workspace (launcher/Cargo.toml), so verify's cargo runs never build it. A pull request that
|
||||
# changes it or a crate it builds is checked here, and so is every push to main: two pull requests can each pass
|
||||
# alone and break it together (#2059 and the registry ratings did, 2026-10-26).
|
||||
launcher:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Does this pull request change the launcher or a crate it builds?
|
||||
if: github.event_name == 'pull_request'
|
||||
id: launcher
|
||||
env:
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
run: python3 tools/ci/rust_changes.py --launcher "$BASE_SHA" "$HEAD_SHA" >> "$GITHUB_OUTPUT"
|
||||
- name: Install Rust and the headers GPUI links against
|
||||
if: steps.launcher.outputs.required != 'false'
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install -y --no-install-recommends libxkbcommon-x11-dev libwayland-dev \
|
||||
libx11-xcb-dev libfontconfig-dev libvulkan-dev libasound2-dev libudev-dev
|
||||
rustup toolchain install stable --profile minimal --component rustfmt --component clippy
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
if: steps.launcher.outputs.required != 'false'
|
||||
with:
|
||||
workspaces: launcher
|
||||
shared-key: launcher
|
||||
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||
- name: Check the launcher's formatting, lint and tests
|
||||
if: steps.launcher.outputs.required != 'false'
|
||||
working-directory: launcher
|
||||
run: |
|
||||
cargo +stable fmt --check
|
||||
cargo +stable clippy --all-targets --locked -- -D warnings
|
||||
cargo +stable test --locked --lib
|
||||
# Most pull requests leave the harnesses to parity-main, which runs them on main a batch of merges at a time
|
||||
# (.github/workflows/parity-main.yml; releases wait for it). A pull request still runs them itself when it changes
|
||||
# a harness, an oracle, a probe or the runner, or carries the run-parity label (run-parity.yml, when it is added).
|
||||
|
||||
@@ -2593,38 +2593,7 @@ impl Game<'_> {
|
||||
/// `PoiTypes`: the point of interest type of a block state.
|
||||
fn poi_type(&self, state: horizon_world::registry::BlockStateId) -> Option<&'static str> {
|
||||
let s = self.pack.assets.registry.state(state)?;
|
||||
let name = s.name.strip_prefix("minecraft:")?;
|
||||
Some(match name {
|
||||
"blast_furnace" => "minecraft:armorer",
|
||||
"smoker" => "minecraft:butcher",
|
||||
"cartography_table" => "minecraft:cartographer",
|
||||
"brewing_stand" => "minecraft:cleric",
|
||||
"composter" => "minecraft:farmer",
|
||||
"barrel" => "minecraft:fisherman",
|
||||
"fletching_table" => "minecraft:fletcher",
|
||||
"cauldron" | "lava_cauldron" | "water_cauldron" | "powder_snow_cauldron" => {
|
||||
"minecraft:leatherworker"
|
||||
}
|
||||
"lectern" => "minecraft:librarian",
|
||||
"stonecutter" => "minecraft:mason",
|
||||
"loom" => "minecraft:shepherd",
|
||||
"smithing_table" => "minecraft:toolsmith",
|
||||
"grindstone" => "minecraft:weaponsmith",
|
||||
"bell" => "minecraft:meeting",
|
||||
"beehive" => "minecraft:beehive",
|
||||
"bee_nest" => "minecraft:bee_nest",
|
||||
"nether_portal" => "minecraft:nether_portal",
|
||||
"lodestone" => "minecraft:lodestone",
|
||||
"test_instance_block" => "minecraft:test_instance",
|
||||
n if n.ends_with("_bed") => {
|
||||
if s.properties.get("part").map(String::as_str) != Some("head") {
|
||||
return None;
|
||||
}
|
||||
"minecraft:home"
|
||||
}
|
||||
n if n.ends_with("lightning_rod") => "minecraft:lightning_rod",
|
||||
_ => return None,
|
||||
})
|
||||
horizon_client::save::poi_type(s).map(|(kind, _)| kind)
|
||||
}
|
||||
/// `LocateCommand.locatePoi`: `PoiManager.findClosestWithType` within
|
||||
/// 256 blocks of the source, over the loaded chunks.
|
||||
|
||||
@@ -49,26 +49,12 @@ impl Game<'_> {
|
||||
let mut tracker = Tracker::default();
|
||||
for &t in &targets {
|
||||
let h = holder(self.target_name(t));
|
||||
// ServerRecipeBook.addRecipes/removeRecipes count recipe book
|
||||
// displays (a transmute recipe has one per material count).
|
||||
let mut n = 0;
|
||||
// ServerPlayer.awardRecipes / resetRecipes: the displays changed.
|
||||
let index = &self.res.stations().recipe_index;
|
||||
n += if give {
|
||||
let (count, unlocked) = self.level.recipe_book.add_recipes(index, &recipes);
|
||||
self.recipe_unlocked(&unlocked);
|
||||
count as i32
|
||||
} else {
|
||||
let removed = self.level.recipe_book.remove_recipes(index, &recipes);
|
||||
let count = removed.len() as i32;
|
||||
// A network player's client drops them from its book.
|
||||
if self.lan_acting.is_some() && !removed.is_empty() {
|
||||
self.guest_packets.push(C::RecipeBookRemove(
|
||||
horizon_protocol::packets::recipes::RecipeBookRemove { ids: removed },
|
||||
));
|
||||
}
|
||||
count
|
||||
};
|
||||
// ServerPlayer.awardRecipes / resetRecipes on the target's own
|
||||
// ServerRecipeBook: a guest's is swapped in for the call, and the
|
||||
// packets go to its client.
|
||||
let n = self
|
||||
.for_player(t, |g| g.change_recipes(give, &recipes))
|
||||
.unwrap_or(0);
|
||||
tracker.track(&h, n);
|
||||
}
|
||||
let verb = if give { "give" } else { "take" };
|
||||
@@ -92,6 +78,27 @@ impl Game<'_> {
|
||||
Ok(total)
|
||||
}
|
||||
|
||||
/// ServerRecipeBook.addRecipes/removeRecipes for the player in place: how
|
||||
/// many recipe book displays changed (a transmute recipe has one per
|
||||
/// material count).
|
||||
fn change_recipes(&mut self, give: bool, recipes: &[String]) -> i32 {
|
||||
let index = &self.res.stations().recipe_index;
|
||||
if give {
|
||||
let (count, unlocked) = self.level.recipe_book.add_recipes(index, recipes);
|
||||
self.recipe_unlocked(&unlocked);
|
||||
return count as i32;
|
||||
}
|
||||
let removed = self.level.recipe_book.remove_recipes(index, recipes);
|
||||
let count = removed.len() as i32;
|
||||
// A network player's client drops them from its book.
|
||||
if self.lan_acting.is_some() && !removed.is_empty() {
|
||||
self.guest_packets.push(C::RecipeBookRemove(
|
||||
horizon_protocol::packets::recipes::RecipeBookRemove { ids: removed },
|
||||
));
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
// ---- /damage ----------------------------------------------------------------
|
||||
|
||||
fn damage_kind(ty: &str) -> DamageKind {
|
||||
|
||||
@@ -247,6 +247,44 @@ pub struct SaveTables {
|
||||
block_entity: Vec<bool>,
|
||||
heightmaps: crate::assets::Properties,
|
||||
air: u32,
|
||||
/// The POI type and its max tickets of each state (`PoiTypes`).
|
||||
poi: Vec<Option<(&'static str, i32)>>,
|
||||
}
|
||||
/// `PoiTypes.register`: the POI type of a block state and its max tickets.
|
||||
pub fn poi_type(state: &horizon_world::chunk::BlockState) -> Option<(&'static str, i32)> {
|
||||
let name = state.name.strip_prefix("minecraft:")?;
|
||||
Some(match name {
|
||||
"blast_furnace" => ("minecraft:armorer", 1),
|
||||
"smoker" => ("minecraft:butcher", 1),
|
||||
"cartography_table" => ("minecraft:cartographer", 1),
|
||||
"brewing_stand" => ("minecraft:cleric", 1),
|
||||
"composter" => ("minecraft:farmer", 1),
|
||||
"barrel" => ("minecraft:fisherman", 1),
|
||||
"fletching_table" => ("minecraft:fletcher", 1),
|
||||
"cauldron" | "lava_cauldron" | "water_cauldron" | "powder_snow_cauldron" => {
|
||||
("minecraft:leatherworker", 1)
|
||||
}
|
||||
"lectern" => ("minecraft:librarian", 1),
|
||||
"stonecutter" => ("minecraft:mason", 1),
|
||||
"loom" => ("minecraft:shepherd", 1),
|
||||
"smithing_table" => ("minecraft:toolsmith", 1),
|
||||
"grindstone" => ("minecraft:weaponsmith", 1),
|
||||
"bell" => ("minecraft:meeting", 32),
|
||||
"beehive" => ("minecraft:beehive", 0),
|
||||
"bee_nest" => ("minecraft:bee_nest", 0),
|
||||
"nether_portal" => ("minecraft:nether_portal", 0),
|
||||
"lodestone" => ("minecraft:lodestone", 0),
|
||||
"test_instance_block" => ("minecraft:test_instance", 0),
|
||||
// PoiTypes.BEDS is the sixteen colours: no straw bed.
|
||||
bed if bed.ends_with("_bed") && bed != "straw_bed" => {
|
||||
if state.properties.get("part").map(String::as_str) != Some("head") {
|
||||
return None;
|
||||
}
|
||||
("minecraft:home", 1)
|
||||
}
|
||||
rod if rod.ends_with("lightning_rod") => ("minecraft:lightning_rod", 0),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
impl SaveTables {
|
||||
pub fn new(assets: &crate::assets::Assets) -> Self {
|
||||
@@ -275,6 +313,9 @@ impl SaveTables {
|
||||
block_entity: Vec::new(),
|
||||
heightmaps: assets.properties.clone(),
|
||||
air: registry.default_state("minecraft:air").map_or(0, |s| s.0),
|
||||
poi: (0..registry.len())
|
||||
.map(|id| registry.state(BlockStateId(id as u32)).and_then(poi_type))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
/// Tables with only the heightmaps' state facts, for tests.
|
||||
@@ -287,6 +328,7 @@ impl SaveTables {
|
||||
block_entity: Vec::new(),
|
||||
heightmaps,
|
||||
air: 0,
|
||||
poi: Vec::new(),
|
||||
}
|
||||
}
|
||||
/// Which states carry a block entity (`BlockFacts`), to drop entries for
|
||||
@@ -813,6 +855,103 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain
|
||||
Some((pos, entity))
|
||||
}
|
||||
|
||||
/// The chunk's points of interest as `PoiManager` saves them: each section
|
||||
/// with POI blocks, valid, with a record per block at its max tickets (a
|
||||
/// freshly made world). None when the chunk has none.
|
||||
pub fn encode_poi(chunk: &Chunk, tables: &SaveTables) -> Option<NamedTag> {
|
||||
let kind = |v: u32| tables.poi.get(v as usize).copied().flatten();
|
||||
let mut sections = Compound::new();
|
||||
let mut states = [0u32; 4096];
|
||||
for (si, section) in chunk.sections.iter().enumerate() {
|
||||
if !section.blocks.maybe_has(|v| kind(v).is_some()) {
|
||||
continue;
|
||||
}
|
||||
section.unpack(&mut states);
|
||||
let y = (MIN_Y >> 4) + si as i32;
|
||||
let records: Vec<Tag> = states
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, &v)| {
|
||||
let (id, tickets) = kind(v)?;
|
||||
let i = i as i32;
|
||||
let pos = [
|
||||
chunk.x * 16 + (i & 15),
|
||||
y * 16 + (i >> 8),
|
||||
chunk.z * 16 + ((i >> 4) & 15),
|
||||
];
|
||||
let mut record = vec![("pos", Tag::IntArray(pos.to_vec())), ("type", string(id))];
|
||||
// PoiRecord.CODEC: free_tickets defaults to 0 and is then left out.
|
||||
if tickets != 0 {
|
||||
record.push(("free_tickets", Tag::Int(tickets)));
|
||||
}
|
||||
Some(Tag::compound(record))
|
||||
})
|
||||
.collect();
|
||||
if !records.is_empty() {
|
||||
sections.insert(
|
||||
y.to_string().as_str().into(),
|
||||
Tag::compound([("Valid", Tag::Byte(1)), ("Records", Tag::List(records))]),
|
||||
);
|
||||
}
|
||||
}
|
||||
(!sections.is_empty()).then(|| poi_root(sections))
|
||||
}
|
||||
/// A record's `free_tickets` from the POI file the chunk had, while the same
|
||||
/// POI is still there: a bed or job site a villager claimed stays claimed.
|
||||
fn keep_claims(saved: &mut NamedTag, old: &NamedTag) {
|
||||
let key = |r: &Tag| match (r.get("pos"), text(r.get("type"))) {
|
||||
(Some(Tag::IntArray(pos)), Some(kind)) => Some((pos.clone(), kind)),
|
||||
_ => None,
|
||||
};
|
||||
let mut claims = HashMap::new();
|
||||
if let Some(Tag::Compound(sections)) = old.tag.get("Sections") {
|
||||
for section in sections.values() {
|
||||
if let Some(Tag::List(records)) = section.get("Records") {
|
||||
for r in records {
|
||||
if let Some(k) = key(r) {
|
||||
claims.insert(k, number(r.get("free_tickets")).unwrap_or(0) as i32);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let Tag::Compound(root) = &mut saved.tag else {
|
||||
return;
|
||||
};
|
||||
let Some(Tag::Compound(sections)) = root.get_mut(&"Sections".into()) else {
|
||||
return;
|
||||
};
|
||||
for section in sections.values_mut() {
|
||||
let Tag::Compound(section) = section else {
|
||||
continue;
|
||||
};
|
||||
let Some(Tag::List(records)) = section.get_mut(&"Records".into()) else {
|
||||
continue;
|
||||
};
|
||||
for r in records {
|
||||
let Some(&tickets) = key(r).and_then(|k| claims.get(&k)) else {
|
||||
continue;
|
||||
};
|
||||
if let Tag::Compound(r) = r {
|
||||
if tickets == 0 {
|
||||
r.remove(&"free_tickets".into());
|
||||
} else {
|
||||
r.insert("free_tickets".into(), Tag::Int(tickets));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fn poi_root(sections: Compound) -> NamedTag {
|
||||
NamedTag {
|
||||
name: "".into(),
|
||||
tag: Tag::compound([
|
||||
("DataVersion", Tag::Int(DATA_VERSION)),
|
||||
("Sections", Tag::Compound(sections)),
|
||||
]),
|
||||
}
|
||||
}
|
||||
|
||||
/// What a dimension's saved chunks depend on: skylight and the build height
|
||||
/// (`DimensionType.minY` and `height`). `Chunk` always holds the Overworld's
|
||||
/// sections; a level saves only the ones inside its own height.
|
||||
@@ -1726,6 +1865,9 @@ enum Record {
|
||||
Tag(Arc<NamedTag>),
|
||||
/// A chunk to encode on the writer thread.
|
||||
Chunk(Arc<Chunk>, Arc<Encoding>),
|
||||
/// A chunk's points of interest, made on the writer thread against the
|
||||
/// saved ones (`resolve_poi`).
|
||||
Poi(Arc<Chunk>, Arc<SaveTables>),
|
||||
Delete,
|
||||
}
|
||||
/// What encoding a chunk needs, captured when it is queued.
|
||||
@@ -1746,14 +1888,86 @@ impl Record {
|
||||
e.tables.as_deref(),
|
||||
e.shape,
|
||||
))),
|
||||
Record::Poi(c, t) => encode_poi(c, t).map(Arc::new),
|
||||
Record::Delete => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
/// A queued POI record as it is written: claims kept from the saved one, and
|
||||
/// a chunk that lost its last POI gets an empty one, as vanilla trusts a
|
||||
/// saved section. None when the chunk never had any.
|
||||
fn resolve_poi(
|
||||
root: &Path,
|
||||
cache: &RegionCache,
|
||||
(x, z): (i32, i32),
|
||||
record: &Record,
|
||||
) -> Option<Record> {
|
||||
let Record::Poi(chunk, tables) = record else {
|
||||
return Some(record.clone());
|
||||
};
|
||||
let old = read_region_record(root, cache, "poi", x, z).unwrap_or_else(|e| {
|
||||
log::warn!("Horizon: could not read the poi record of chunk {x} {z}: {e}");
|
||||
None
|
||||
});
|
||||
let tag = match (encode_poi(chunk, tables), old) {
|
||||
(Some(mut tag), Some(old)) => {
|
||||
keep_claims(&mut tag, &old);
|
||||
tag
|
||||
}
|
||||
(Some(tag), None) => tag,
|
||||
(None, Some(_)) => poi_root(Compound::new()),
|
||||
(None, None) => return None,
|
||||
};
|
||||
Some(Record::Tag(Arc::new(tag)))
|
||||
}
|
||||
fn read_region_record(
|
||||
root: &Path,
|
||||
cache: &RegionCache,
|
||||
folder: &str,
|
||||
x: i32,
|
||||
z: i32,
|
||||
) -> Result<Option<NamedTag>> {
|
||||
let key = (x >> 5, z >> 5);
|
||||
let path = region_path(root, folder, key.0, key.1);
|
||||
let Some(region) = cached_region(cache, key, &path, false)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
let record = region
|
||||
.lock()
|
||||
.map_err(|_| "region file poisoned")?
|
||||
.read(ChunkPos::new(x, z))?;
|
||||
Ok(match record {
|
||||
Some(r) => Some(r.nbt(Limits::default())?),
|
||||
None => None,
|
||||
})
|
||||
}
|
||||
/// Chunk and entity records waiting for the writer thread, by (entities?,
|
||||
/// x, z): reads see them before the region files do.
|
||||
type PendingWrites = Mutex<HashMap<(bool, i32, i32), (u64, Record)>>;
|
||||
type WriteBatch = (bool, Vec<((i32, i32), Record, u64)>);
|
||||
type PendingWrites = Mutex<HashMap<(Folder, i32, i32), (u64, Record)>>;
|
||||
type WriteBatch = (Folder, Vec<((i32, i32), Record, u64)>);
|
||||
/// The region folders of a dimension.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
enum Folder {
|
||||
Region,
|
||||
Entities,
|
||||
Poi,
|
||||
}
|
||||
impl Folder {
|
||||
fn of(name: &str) -> Self {
|
||||
match name {
|
||||
"entities" => Self::Entities,
|
||||
"poi" => Self::Poi,
|
||||
_ => Self::Region,
|
||||
}
|
||||
}
|
||||
fn name(self) -> &'static str {
|
||||
match self {
|
||||
Self::Region => "region",
|
||||
Self::Entities => "entities",
|
||||
Self::Poi => "poi",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The background thread that encodes chunks and writes them into the region files, in
|
||||
/// submission order.
|
||||
@@ -1775,6 +1989,7 @@ pub struct SaveDir {
|
||||
pub root: PathBuf,
|
||||
regions: Arc<RegionCache>,
|
||||
entity_regions: Arc<RegionCache>,
|
||||
poi_regions: Arc<RegionCache>,
|
||||
pending: Arc<PendingWrites>,
|
||||
sequence: AtomicU64,
|
||||
writer: Mutex<Option<Writer>>,
|
||||
@@ -1791,6 +2006,7 @@ impl SaveDir {
|
||||
root,
|
||||
regions: Default::default(),
|
||||
entity_regions: Default::default(),
|
||||
poi_regions: Default::default(),
|
||||
pending: Default::default(),
|
||||
sequence: AtomicU64::new(0),
|
||||
writer: Mutex::new(None),
|
||||
@@ -1807,21 +2023,17 @@ impl SaveDir {
|
||||
.pending
|
||||
.lock()
|
||||
.ok()?
|
||||
.get(&(folder != "region", x, z))
|
||||
.get(&(Folder::of(folder), x, z))
|
||||
.map(|(_, r)| r.clone());
|
||||
if let Some(record) = pending {
|
||||
return record.tag().map(|t| (*t).clone());
|
||||
}
|
||||
let key = (x >> 5, z >> 5);
|
||||
let cache = if folder == "region" {
|
||||
&self.regions
|
||||
} else {
|
||||
&self.entity_regions
|
||||
let cache = match Folder::of(folder) {
|
||||
Folder::Region => &self.regions,
|
||||
Folder::Entities => &self.entity_regions,
|
||||
Folder::Poi => &self.poi_regions,
|
||||
};
|
||||
let path = self.region_path(folder, key.0, key.1);
|
||||
let region = cached_region(cache, key, &path, false).ok()??;
|
||||
let record = region.lock().ok()?.read(ChunkPos::new(x, z)).ok()??;
|
||||
record.nbt(Limits::default()).ok()
|
||||
read_region_record(&self.root, cache, folder, x, z).ok()?
|
||||
}
|
||||
pub fn load(&self, x: i32, z: i32, registry: &BlockRegistry, biomes: &Biomes) -> Option<Chunk> {
|
||||
let root = self.read_record("region", x, z)?;
|
||||
@@ -1881,16 +2093,16 @@ impl SaveDir {
|
||||
.into_iter()
|
||||
.map(|(k, t)| (k, t.map_or(Record::Delete, |t| Record::Tag(Arc::new(t)))))
|
||||
.collect();
|
||||
self.queue(folder != "region", records, wait)
|
||||
self.queue(Folder::of(folder), records, wait)
|
||||
}
|
||||
fn queue(&self, entities: bool, records: Vec<((i32, i32), Record)>, wait: bool) -> Result<()> {
|
||||
fn queue(&self, folder: Folder, records: Vec<((i32, i32), Record)>, wait: bool) -> Result<()> {
|
||||
if !records.is_empty() {
|
||||
let mut batch = Vec::with_capacity(records.len());
|
||||
{
|
||||
let mut pending = self.pending.lock().map_err(|_| "pending writes poisoned")?;
|
||||
for (key, record) in records {
|
||||
let seq = self.sequence.fetch_add(1, Ordering::Relaxed);
|
||||
pending.insert((entities, key.0, key.1), (seq, record.clone()));
|
||||
pending.insert((folder, key.0, key.1), (seq, record.clone()));
|
||||
batch.push((key, record, seq));
|
||||
}
|
||||
}
|
||||
@@ -1901,7 +2113,7 @@ impl SaveDir {
|
||||
.map_err(|_| "writer poisoned")? += 1;
|
||||
let mut writer = self.writer.lock().map_err(|_| "writer poisoned")?;
|
||||
let writer = writer.get_or_insert_with(|| self.start_writer());
|
||||
if writer.send.send((entities, batch)).is_err() {
|
||||
if writer.send.send((folder, batch)).is_err() {
|
||||
*self
|
||||
.outstanding
|
||||
.error
|
||||
@@ -1924,30 +2136,36 @@ impl SaveDir {
|
||||
fn start_writer(&self) -> Writer {
|
||||
let (send, receive) = mpsc::channel::<WriteBatch>();
|
||||
let root = self.root.clone();
|
||||
let (regions, entity_regions) = (self.regions.clone(), self.entity_regions.clone());
|
||||
let (regions, entity_regions, poi_regions) = (
|
||||
self.regions.clone(),
|
||||
self.entity_regions.clone(),
|
||||
self.poi_regions.clone(),
|
||||
);
|
||||
let pending = self.pending.clone();
|
||||
let outstanding = self.outstanding.clone();
|
||||
let thread = std::thread::Builder::new()
|
||||
.name("horizon-region-writer".into())
|
||||
.spawn(move || {
|
||||
for (entities, batch) in receive {
|
||||
let (folder, cache) = if entities {
|
||||
("entities", &entity_regions)
|
||||
} else {
|
||||
("region", ®ions)
|
||||
for (kind, batch) in receive {
|
||||
let cache = match kind {
|
||||
Folder::Region => ®ions,
|
||||
Folder::Entities => &entity_regions,
|
||||
Folder::Poi => &poi_regions,
|
||||
};
|
||||
let folder = kind.name();
|
||||
// IOWorker.pendingWrites: a chunk queued again since is
|
||||
// written once, by its newest batch.
|
||||
let newest = |k: &(i32, i32), seq: u64| {
|
||||
pending.lock().map_or(true, |p| {
|
||||
p.get(&(entities, k.0, k.1)).is_none_or(|p| p.0 <= seq)
|
||||
p.get(&(kind, k.0, k.1)).is_none_or(|p| p.0 <= seq)
|
||||
})
|
||||
};
|
||||
let records: Vec<_> = batch
|
||||
let resolved: Vec<_> = batch
|
||||
.iter()
|
||||
.filter(|(k, _, seq)| newest(k, *seq))
|
||||
.map(|(k, r, _)| (*k, r))
|
||||
.filter_map(|(k, r, _)| Some((*k, resolve_poi(&root, cache, *k, r)?)))
|
||||
.collect();
|
||||
let records: Vec<_> = resolved.iter().map(|(k, r)| (*k, r)).collect();
|
||||
let result = write_region_records(&root, cache, folder, &records);
|
||||
if let Err(e) = &result {
|
||||
let message = format!("failed to write {folder} files: {e}");
|
||||
@@ -1959,11 +2177,8 @@ impl SaveDir {
|
||||
&& let Ok(mut pending) = pending.lock()
|
||||
{
|
||||
for (k, _, seq) in &batch {
|
||||
if pending
|
||||
.get(&(entities, k.0, k.1))
|
||||
.is_some_and(|p| p.0 == *seq)
|
||||
{
|
||||
pending.remove(&(entities, k.0, k.1));
|
||||
if pending.get(&(kind, k.0, k.1)).is_some_and(|p| p.0 == *seq) {
|
||||
pending.remove(&(kind, k.0, k.1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2032,8 +2247,19 @@ impl SaveDir {
|
||||
})
|
||||
.collect();
|
||||
self.write_records("region", records, true)?;
|
||||
self.save_poi(chunks, true)?;
|
||||
Ok(chunks.len())
|
||||
}
|
||||
fn save_poi(&self, chunks: &[Arc<Chunk>], wait: bool) -> Result<()> {
|
||||
let Some(tables) = self.tables.get() else {
|
||||
return Ok(());
|
||||
};
|
||||
let records = chunks
|
||||
.iter()
|
||||
.map(|c| ((c.x, c.z), Record::Poi(c.clone(), tables.clone())))
|
||||
.collect();
|
||||
self.queue(Folder::Poi, records, wait)
|
||||
}
|
||||
/// `save` on the writer thread: returns before the files are written;
|
||||
/// loads see the chunks meanwhile.
|
||||
pub fn save_later(
|
||||
@@ -2052,7 +2278,8 @@ impl SaveDir {
|
||||
.iter()
|
||||
.map(|c| ((c.x, c.z), Record::Chunk(c.clone(), encoding.clone())))
|
||||
.collect();
|
||||
self.queue(false, records, false)?;
|
||||
self.queue(Folder::Region, records, false)?;
|
||||
self.save_poi(chunks, false)?;
|
||||
Ok(chunks.len())
|
||||
}
|
||||
/// Write the entity chunks (`EntityStorage`): an empty list deletes it.
|
||||
@@ -3497,7 +3724,7 @@ impl SaveDir {
|
||||
.pending
|
||||
.lock()
|
||||
.ok()?
|
||||
.get(&(false, x, z))
|
||||
.get(&(Folder::Region, x, z))
|
||||
.map(|(_, record)| record.clone());
|
||||
let root = if let Some(record) = pending {
|
||||
record.tag().map(|tag| (*tag).clone())?
|
||||
@@ -3607,6 +3834,134 @@ impl<G: ChunkGenerator> ChunkGenerator for Persistent<G> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn points_of_interest_save_as_poi_sections() {
|
||||
let Some(root) = std::env::var_os("HORIZON_TEST_RESOURCES") else {
|
||||
return;
|
||||
};
|
||||
let assets = crate::assets::Assets::load(&PathBuf::from(root)).expect("assets");
|
||||
let tables = SaveTables::new(&assets);
|
||||
let state = |name: &str, props: &[(&str, &str)]| {
|
||||
let mut s = assets
|
||||
.registry
|
||||
.state(assets.registry.default_state(name).unwrap())
|
||||
.unwrap()
|
||||
.clone();
|
||||
for (k, v) in props {
|
||||
s.properties.insert((*k).into(), (*v).into());
|
||||
}
|
||||
assets.registry.id(&s).unwrap().0
|
||||
};
|
||||
let mut chunk = Chunk::empty(2, -1);
|
||||
chunk.set(1, 70, 1, state("minecraft:red_bed", &[("part", "head")]));
|
||||
chunk.set(1, 70, 2, state("minecraft:red_bed", &[("part", "foot")]));
|
||||
chunk.set(5, 71, 5, state("minecraft:bell", &[]));
|
||||
chunk.set(6, 71, 5, state("minecraft:stone", &[]));
|
||||
chunk.set(9, 70, 9, state("minecraft:straw_bed", &[("part", "head")]));
|
||||
assert!(encode_poi(&Chunk::empty(0, 0), &tables).is_none());
|
||||
let saved = encode_poi(&chunk, &tables).expect("records");
|
||||
let Some(Tag::Compound(sections)) = saved.tag.get("Sections") else {
|
||||
panic!("no sections");
|
||||
};
|
||||
assert_eq!(sections.len(), 1);
|
||||
let section = §ions[&"4".into()];
|
||||
assert_eq!(section.get("Valid"), Some(&Tag::Byte(1)));
|
||||
let Some(Tag::List(records)) = section.get("Records") else {
|
||||
panic!("no records");
|
||||
};
|
||||
let records: Vec<_> = records
|
||||
.iter()
|
||||
.map(|r| {
|
||||
(
|
||||
text(r.get("type")).unwrap(),
|
||||
r.get("pos").cloned(),
|
||||
number(r.get("free_tickets")),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
records,
|
||||
[
|
||||
(
|
||||
"minecraft:home".into(),
|
||||
Some(Tag::IntArray(vec![33, 70, -15])),
|
||||
Some(1)
|
||||
),
|
||||
(
|
||||
"minecraft:meeting".into(),
|
||||
Some(Tag::IntArray(vec![37, 71, -11])),
|
||||
Some(32)
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_chunk_that_loses_its_last_poi_saves_empty_sections() {
|
||||
let Some(root) = std::env::var_os("HORIZON_TEST_RESOURCES") else {
|
||||
return;
|
||||
};
|
||||
let root = PathBuf::from(root);
|
||||
let assets = crate::assets::Assets::load(&root).expect("assets");
|
||||
let biomes = Arc::new(Biomes::load(&root).expect("biomes"));
|
||||
let bell = assets.registry.default_state("minecraft:bell").unwrap().0;
|
||||
let dir = std::env::temp_dir().join(format!("horizon-poi-save-{}", std::process::id()));
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
let save = SaveDir::new(dir.clone());
|
||||
let _ = save.tables.set(Arc::new(SaveTables::new(&assets)));
|
||||
let mut chunk = Chunk::empty(0, 0);
|
||||
chunk.set(5, 71, 5, bell);
|
||||
let sections = |save: &SaveDir| match save.read_record("poi", 0, 0)?.tag.get("Sections") {
|
||||
Some(Tag::Compound(s)) => Some(s.len()),
|
||||
_ => None,
|
||||
};
|
||||
save.save_later(&[Arc::new(chunk.clone())], assets.registry, &biomes)
|
||||
.unwrap();
|
||||
save.flush().unwrap();
|
||||
assert_eq!(sections(&save), Some(1));
|
||||
chunk.set(5, 71, 5, 0);
|
||||
save.save_later(&[Arc::new(chunk)], assets.registry, &biomes)
|
||||
.unwrap();
|
||||
save.flush().unwrap();
|
||||
assert_eq!(sections(&SaveDir::new(dir.clone())), Some(0));
|
||||
let _ = fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saved_poi_records_keep_their_claims() {
|
||||
let record = |pos: [i32; 3], kind: &str, tickets: Option<i32>| {
|
||||
let mut r = vec![("pos", Tag::IntArray(pos.to_vec())), ("type", string(kind))];
|
||||
if let Some(t) = tickets {
|
||||
r.push(("free_tickets", Tag::Int(t)));
|
||||
}
|
||||
Tag::compound(r)
|
||||
};
|
||||
let poi = |records: Vec<Tag>| {
|
||||
let mut sections = Compound::new();
|
||||
sections.insert(
|
||||
"4".into(),
|
||||
Tag::compound([("Valid", Tag::Byte(1)), ("Records", Tag::List(records))]),
|
||||
);
|
||||
poi_root(sections)
|
||||
};
|
||||
let old = poi(vec![
|
||||
record([1, 70, 1], "minecraft:home", None),
|
||||
record([5, 71, 5], "minecraft:meeting", Some(30)),
|
||||
]);
|
||||
let mut saved = poi(vec![
|
||||
record([1, 70, 1], "minecraft:home", Some(1)),
|
||||
record([5, 71, 5], "minecraft:meeting", Some(32)),
|
||||
record([9, 71, 9], "minecraft:home", Some(1)),
|
||||
]);
|
||||
keep_claims(&mut saved, &old);
|
||||
let expected = poi(vec![
|
||||
record([1, 70, 1], "minecraft:home", None),
|
||||
record([5, 71, 5], "minecraft:meeting", Some(30)),
|
||||
record([9, 71, 9], "minecraft:home", Some(1)),
|
||||
]);
|
||||
assert_eq!(saved.tag, expected.tag);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unopened_rolled_containers_save_their_loot_table() {
|
||||
let Some(root) = std::env::var_os("HORIZON_TEST_RESOURCES") else {
|
||||
|
||||
@@ -4,7 +4,7 @@ import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tools.ci.rust_changes import changed_paths, needs_rust
|
||||
from tools.ci.rust_changes import changed_paths, needs_launcher, needs_rust
|
||||
|
||||
|
||||
class RustChangesTests(unittest.TestCase):
|
||||
@@ -21,6 +21,17 @@ class RustChangesTests(unittest.TestCase):
|
||||
with self.subTest(path=path):
|
||||
self.assertTrue(needs_rust(["README.md", path]))
|
||||
|
||||
def test_launcher_checks_follow_the_crates_it_builds(self):
|
||||
for path in ["crates/horizon-client/src/game.rs", "launcher/links.json", "launcher/docs/a.md",
|
||||
"launcher/README.md", "website/src/index.html", "tools/pr_ready.py"]:
|
||||
with self.subTest(path=path):
|
||||
self.assertFalse(needs_launcher([path]))
|
||||
for path in ["launcher/src/main.rs", "launcher/Cargo.lock", "crates/horizon-port-pack/src/net.rs",
|
||||
"crates/horizon-theme/src/lib.rs", "Cargo.toml", "Cargo.lock",
|
||||
".github/workflows/ci.yml"]:
|
||||
with self.subTest(path=path):
|
||||
self.assertTrue(needs_launcher(["README.md", path]))
|
||||
|
||||
def test_moving_source_into_docs_still_requires_rust(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
def git(*args):
|
||||
|
||||
@@ -1,14 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Keep verify's Rust steps for any change beyond documentation."""
|
||||
"""Keep verify's Rust steps for any change beyond documentation.
|
||||
|
||||
--launcher: whether the change is built into the launcher, its own workspace (release_train.LAUNCHER_PATHS).
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# The repository root, appended so a script run finds `tools` without shadowing anything already importable.
|
||||
sys.path.append(str(Path(__file__).resolve().parents[2]))
|
||||
from tools import release_train # noqa: E402
|
||||
|
||||
# The root workspace's manifest and toolchain files: the launcher's path crates inherit from them.
|
||||
ROOT_RUST = {"Cargo.toml", "Cargo.lock", "rust-toolchain.toml", "rustfmt.toml", "clippy.toml"}
|
||||
# The check itself: a change to it runs it.
|
||||
LAUNCHER_CHECK = {".github/workflows/ci.yml", "tools/ci/rust_changes.py", "tools/release_train.py"}
|
||||
|
||||
|
||||
def needs_rust(paths):
|
||||
return any(not (path.startswith("docs/") or path.endswith(".md")) for path in paths)
|
||||
|
||||
|
||||
def needs_launcher(paths):
|
||||
return any(path in ROOT_RUST or path in LAUNCHER_CHECK or (
|
||||
path.startswith(tuple(release_train.LAUNCHER_PATHS))
|
||||
and not path.startswith(tuple(release_train.LAUNCHER_IGNORED))
|
||||
and not path.endswith(".md")
|
||||
) for path in paths)
|
||||
|
||||
|
||||
def changed_paths(base, head):
|
||||
# Renames must include deletions too: moving source into docs still affects Rust.
|
||||
output = subprocess.check_output([
|
||||
@@ -21,5 +43,7 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("base")
|
||||
parser.add_argument("head")
|
||||
parser.add_argument("--launcher", action="store_true", help="answer for the launcher instead")
|
||||
args = parser.parse_args()
|
||||
print(f"required={str(needs_rust(changed_paths(args.base, args.head))).lower()}")
|
||||
needs = needs_launcher if args.launcher else needs_rust
|
||||
print(f"required={str(needs(changed_paths(args.base, args.head))).lower()}")
|
||||
|
||||
@@ -91,6 +91,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
places a log in the inventory's crafting grid (the server places it).
|
||||
- recipe_removal: the host and guest each forget all and individual recipes while the book
|
||||
is open; it stays empty when reopened, and a later grant appears (#1495).
|
||||
- recipe_targets: `/recipe give|take <other player>` changes that player's book, the host's
|
||||
for the guest and (server thread) the guest's for the host; their open book shows it.
|
||||
- feedback: the guest's command feedback names the guest and shows the numbers, and the host (an
|
||||
operator) is told of it as `[Guest: ...]`.
|
||||
- clicks: with real mouse presses (not click-slot, which skips the screen's press and drag
|
||||
@@ -6232,6 +6234,62 @@ CHECKS += ['recipe_removal']
|
||||
CHECK_FNS.update(recipe_removal=check_recipe_removal)
|
||||
|
||||
|
||||
def check_recipe_targets(host, guest, out):
|
||||
"""RecipeCommand gives and takes the recipes of each target's own ServerRecipeBook: a
|
||||
`/recipe give|take <other player>` changes that player's book and reaches their client,
|
||||
not the book of the player who typed it. An in-frame host isn't one of the players a guest's
|
||||
command can name (`command_players` lists the guests), so the guest gives the host a recipe
|
||||
only when the host is a client of its server thread."""
|
||||
host_name = host.raw('lan', 'status').get('host', 'Player')
|
||||
books = {}
|
||||
for game in (host, guest):
|
||||
back_to_game(game)
|
||||
game('command', command='clear @s')
|
||||
game('command', command='recipe take @s *')
|
||||
host.wait(20)
|
||||
for game in (host, guest):
|
||||
game.raw('key', 'e', 'tap')
|
||||
game.wait(5)
|
||||
book = game('screen').get('recipe_book')
|
||||
assert book, f'{game.name}: the inventory has no recipe book'
|
||||
if len(book['targets']) == 1:
|
||||
game.raw('click-at', *centre(book['targets'][0]))
|
||||
game.wait(5)
|
||||
|
||||
def known():
|
||||
return {game.name: game('screen')['recipe_book']['known'] for game in (host, guest)}
|
||||
|
||||
try:
|
||||
books['empty'] = known()
|
||||
assert books['empty'] == {host.name: 0, guest.name: 0}, books
|
||||
host('command', command=f'recipe give {GUEST_NAME} minecraft:oak_planks')
|
||||
host('command', command=f'recipe give {GUEST_NAME} minecraft:stick')
|
||||
host.wait(20)
|
||||
books['host gives guest'] = known()
|
||||
if SERVER_THREAD:
|
||||
guest('command', command=f'recipe give {host_name} minecraft:stick')
|
||||
guest.wait(20)
|
||||
books['guest gives host'] = known()
|
||||
host('command', command=f'recipe take {GUEST_NAME} minecraft:stick')
|
||||
host.wait(20)
|
||||
books['host takes from guest'] = known()
|
||||
host.shot(out, 'recipe-targets-host')
|
||||
guest.shot(out, 'recipe-targets-guest')
|
||||
by_guest = int(SERVER_THREAD)
|
||||
expected = {'empty': (0, 0), 'host gives guest': (0, 2), 'guest gives host': (by_guest, 2),
|
||||
'host takes from guest': (by_guest, 1)}
|
||||
for step, (in_host, in_guest) in expected.items():
|
||||
assert books[step] == {host.name: in_host, guest.name: in_guest}, (step, books)
|
||||
finally:
|
||||
back_to_game(host)
|
||||
back_to_game(guest)
|
||||
return books
|
||||
|
||||
|
||||
CHECKS += ['recipe_targets']
|
||||
CHECK_FNS.update(recipe_targets=check_recipe_targets)
|
||||
|
||||
|
||||
def check_shulker_bullets(host, guest, out):
|
||||
"""ShulkerAttackGoal's bullets reach ClientPacketListener.handleAddEntity, then the existing
|
||||
projectile renderer and interpolation, with distinct ids from the server's entity counter."""
|
||||
|
||||
Reference in New Issue
Block a user