Spawn structure mobs and apply structure spawn overrides
Structure pieces now spawn their entities: the swamp hut's witch and black cat, the monument's three elder guardians, end city sentry shulkers and the elytra item frame, mansion evokers, vindicators and allays, ocean ruin drowned, and mineshaft chest minecarts with their loot rolled in. Chunks keep their structure references (saved as structures.References), so structures_at answers advancement location predicates, and natural spawning uses structure spawn_overrides (guardians in monuments, witches in huts, fortress mobs on nether bricks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,9 @@ pub struct Chunk {
|
||||
pub saved: Option<Arc<crate::save::ChunkExtras>>,
|
||||
/// Entities read from a save (vanilla entity NBT), spawned on arrival.
|
||||
pub entities: Vec<horizon_world::nbt::Tag>,
|
||||
/// Structure starts reaching into this chunk (`structures.References`):
|
||||
/// structure id and the start's chunk.
|
||||
pub structure_refs: Vec<(Arc<str>, (i32, i32))>,
|
||||
}
|
||||
impl Chunk {
|
||||
pub fn empty(x: i32, z: i32) -> Self {
|
||||
@@ -119,6 +122,7 @@ impl Chunk {
|
||||
lit: false,
|
||||
fresh: false,
|
||||
block_entities: Vec::new(),
|
||||
structure_refs: Vec::new(),
|
||||
postprocess: Vec::new(),
|
||||
saved: None,
|
||||
entities: Vec::new(),
|
||||
|
||||
@@ -628,6 +628,9 @@ struct Game<'a> {
|
||||
stats_ui: stats_screen::StatsUi,
|
||||
adv_ui: advancements_screen::AdvUi,
|
||||
camera_type: perspective::CameraType,
|
||||
/// Structure `spawn_overrides`: structure -> category -> (piece only, spawns).
|
||||
spawn_overrides:
|
||||
HashMap<String, HashMap<String, (bool, Vec<horizon_client::biome::SpawnEntry>)>>,
|
||||
/// The local player as a model (third person, the inventory).
|
||||
player_model: Option<Mob>,
|
||||
}
|
||||
@@ -7673,6 +7676,7 @@ pub fn run() -> Result<()> {
|
||||
stats_ui: Default::default(),
|
||||
adv_ui: Default::default(),
|
||||
camera_type: Default::default(),
|
||||
spawn_overrides: HashMap::new(),
|
||||
player_model: None,
|
||||
};
|
||||
game.ui.vanilla_root = vanilla_root;
|
||||
|
||||
@@ -1882,7 +1882,7 @@ impl Game<'_> {
|
||||
Ok(distance)
|
||||
}
|
||||
/// The structures of a `worldgen/structure` tag, nested tags expanded.
|
||||
fn structure_tag(&self, tag: &str) -> Vec<String> {
|
||||
pub(super) fn structure_tag(&self, tag: &str) -> Vec<String> {
|
||||
let mut out = Vec::new();
|
||||
let mut pending = vec![tag.to_owned()];
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
|
||||
@@ -441,8 +441,12 @@ impl Game<'_> {
|
||||
break;
|
||||
};
|
||||
let biome = self.res.biomes.get(chunk.biome(x, y, z)).clone();
|
||||
let Some(list) = biome.spawns.get(category).cloned() else {
|
||||
break;
|
||||
let list = match self.structure_spawns(category, [x, y, z]) {
|
||||
Some(list) => list,
|
||||
None => match biome.spawns.get(category).cloned() {
|
||||
Some(list) => list,
|
||||
None => break,
|
||||
},
|
||||
};
|
||||
let list: Vec<_> = list
|
||||
.into_iter()
|
||||
|
||||
@@ -222,6 +222,19 @@ impl Game<'_> {
|
||||
m.position.z.floor() as i32,
|
||||
);
|
||||
horizon_client::mobs::spawning::finalize(&mut m, &facts);
|
||||
// Cat.finalizeSpawn: black in #cats_spawn_as_black.
|
||||
if m.species() == horizon_client::mobs::Species::Cat {
|
||||
let p = [
|
||||
m.position.x.floor() as i32,
|
||||
m.position.y.floor() as i32,
|
||||
m.position.z.floor() as i32,
|
||||
];
|
||||
let black = self.structure_tag("minecraft:cats_spawn_as_black");
|
||||
if self.structures_at(p).iter().any(|s| black.contains(s)) {
|
||||
m.extra.variant = 10;
|
||||
m.persistent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.remember(m.id, uuid, tag);
|
||||
self.mobs.push(m);
|
||||
|
||||
@@ -1,9 +1,121 @@
|
||||
//! Which structures contain a position (`StructureManager.getStructureWithPieceAt`).
|
||||
//! Which structures contain a position (`StructureManager.getStructureAt`
|
||||
//! and `getStructureWithPieceAt`), from the chunk's structure references and
|
||||
//! the generator's cached starts.
|
||||
use super::Game;
|
||||
|
||||
impl Game<'_> {
|
||||
/// Structures reaching `pos`: (id, inside a piece). `getStructureAt`
|
||||
/// tests the start's whole box, `getStructureWithPieceAt` a piece's.
|
||||
fn structures_reaching(&self, pos: [i32; 3]) -> Vec<(String, bool)> {
|
||||
let Some(chunk) = self.world.chunks.get(&(pos[0] >> 4, pos[2] >> 4)) else {
|
||||
return Vec::new();
|
||||
};
|
||||
if chunk.structure_refs.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let Some(locator) = self.end.locator() else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut out: Vec<(String, bool)> = Vec::new();
|
||||
for (id, (sx, sz)) in &chunk.structure_refs {
|
||||
for start in locator.starts_at(*sx, *sz) {
|
||||
if *start.name != **id || !start.bounding_box.is_inside(pos) {
|
||||
continue;
|
||||
}
|
||||
let piece = start.pieces.iter().any(|p| p.bounding_box().is_inside(pos));
|
||||
match out.iter_mut().find(|(n, _)| *n == start.name) {
|
||||
Some(e) => e.1 |= piece,
|
||||
None => out.push((start.name.clone(), piece)),
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
/// The structures with a piece containing `pos`.
|
||||
pub(super) fn structures_at(&self, _pos: [i32; 3]) -> Vec<String> {
|
||||
Vec::new()
|
||||
pub(super) fn structures_at(&self, pos: [i32; 3]) -> Vec<String> {
|
||||
self.structures_reaching(pos)
|
||||
.into_iter()
|
||||
.filter(|(_, piece)| *piece)
|
||||
.map(|(n, _)| n)
|
||||
.collect()
|
||||
}
|
||||
/// `ChunkGenerator.getMobsAt` / `NaturalSpawner.mobsAt`: a structure's
|
||||
/// `spawn_overrides` for the category replace the biome's list where its
|
||||
/// box (or piece) holds `pos`; fortress spawns on nether bricks.
|
||||
pub(super) fn structure_spawns(
|
||||
&mut self,
|
||||
category: &str,
|
||||
pos: [i32; 3],
|
||||
) -> Option<Vec<horizon_client::biome::SpawnEntry>> {
|
||||
let reaching = self.structures_reaching(pos);
|
||||
if reaching.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let below = self.world.block(pos[0], pos[1] - 1, pos[2]);
|
||||
let bricks = &*self.res.facts.get(below).name == "minecraft:nether_bricks";
|
||||
for (id, piece) in &reaching {
|
||||
let Some(o) = self.spawn_override(id, category) else {
|
||||
continue;
|
||||
};
|
||||
if !o.0 || *piece {
|
||||
return Some(o.1);
|
||||
}
|
||||
}
|
||||
if category == "monster"
|
||||
&& bricks
|
||||
&& reaching.iter().any(|(n, _)| n == "minecraft:fortress")
|
||||
{
|
||||
return self
|
||||
.spawn_override("minecraft:fortress", "monster")
|
||||
.map(|o| o.1);
|
||||
}
|
||||
None
|
||||
}
|
||||
/// A structure's override for a category: (piece-only, spawns).
|
||||
fn spawn_override(
|
||||
&mut self,
|
||||
structure: &str,
|
||||
category: &str,
|
||||
) -> Option<(bool, Vec<horizon_client::biome::SpawnEntry>)> {
|
||||
if !self.spawn_overrides.contains_key(structure) {
|
||||
let (ns, path) = structure
|
||||
.split_once(':')
|
||||
.unwrap_or(("minecraft", structure));
|
||||
let file = self
|
||||
.options
|
||||
.resources
|
||||
.join(format!("data/{ns}/worldgen/structure/{path}.json"));
|
||||
let v: serde_json::Value = std::fs::read(file)
|
||||
.ok()
|
||||
.and_then(|b| serde_json::from_slice(&b).ok())
|
||||
.unwrap_or_default();
|
||||
let mut map = std::collections::HashMap::new();
|
||||
for (cat, o) in v["spawn_overrides"].as_object().into_iter().flatten() {
|
||||
let piece = o["bounding_box"].as_str() == Some("piece");
|
||||
let spawns = o["spawns"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|e| {
|
||||
let count = &e["count"];
|
||||
horizon_client::biome::SpawnEntry {
|
||||
entity: e["type"].as_str().unwrap_or_default().to_owned(),
|
||||
weight: e["weight"].as_u64().unwrap_or(1) as u32,
|
||||
min: count["min_inclusive"]
|
||||
.as_u64()
|
||||
.or_else(|| e["minCount"].as_u64())
|
||||
.unwrap_or(1) as u32,
|
||||
max: count["max_inclusive"]
|
||||
.as_u64()
|
||||
.or_else(|| e["maxCount"].as_u64())
|
||||
.unwrap_or(1) as u32,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
map.insert(cat.clone(), (piece, spawns));
|
||||
}
|
||||
self.spawn_overrides.insert(structure.to_owned(), map);
|
||||
}
|
||||
self.spawn_overrides.get(structure)?.get(category).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,6 +710,21 @@ pub fn encode_with(
|
||||
("starts", Tag::Compound(Compound::new())),
|
||||
])
|
||||
});
|
||||
if !chunk.structure_refs.is_empty()
|
||||
&& let Some(Tag::Compound(s)) = map.get_mut(&"structures".into())
|
||||
{
|
||||
let mut refs: std::collections::BTreeMap<&str, Vec<i64>> = Default::default();
|
||||
for (id, (x, z)) in &chunk.structure_refs {
|
||||
refs.entry(id)
|
||||
.or_default()
|
||||
.push(i64::from(*x as u32) | i64::from(*z) << 32);
|
||||
}
|
||||
let refs: Compound = refs
|
||||
.into_iter()
|
||||
.map(|(id, v)| (id.into(), Tag::LongArray(v)))
|
||||
.collect();
|
||||
s.insert("References".into(), Tag::Compound(refs));
|
||||
}
|
||||
map.entry("PostProcessing".into())
|
||||
.or_insert_with(|| Tag::List(vec![Tag::List(Vec::new()); SECTIONS]));
|
||||
}
|
||||
@@ -766,6 +781,19 @@ pub fn decode_with(
|
||||
return None;
|
||||
}
|
||||
let mut chunk = Chunk::empty(*x, *z);
|
||||
// structures.References: structure id -> packed start chunk positions.
|
||||
if let Some(Tag::Compound(refs)) = tag.get("structures").and_then(|s| s.get("References")) {
|
||||
for (id, v) in refs {
|
||||
if let Tag::LongArray(starts) = v {
|
||||
let id: Arc<str> = Arc::from(id.to_string_lossy());
|
||||
for &p in starts {
|
||||
chunk
|
||||
.structure_refs
|
||||
.push((id.clone(), (p as i32, (p >> 32) as i32)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let air = registry.default_state("minecraft:air")?.0 as u16;
|
||||
let mut cache: HashMap<String, u16> = HashMap::new();
|
||||
let mut biome_data = (*chunk.biomes).clone();
|
||||
|
||||
@@ -71,3 +71,49 @@ pub fn block_entities(
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Chest minecarts placed with a loot table (mineshafts): the table rolled
|
||||
/// into `Items` as `unpackLootTable` would on first open.
|
||||
pub fn unpack_entity_loot(
|
||||
chunk: &ProtoChunk,
|
||||
mut nbt: horizon_world::nbt::Compound,
|
||||
loot: Option<&LootData>,
|
||||
) -> horizon_world::nbt::Compound {
|
||||
let (Some(table), Some(loot)) = (
|
||||
match nbt.get(&JavaString::from("LootTable")) {
|
||||
Some(Tag::String(s)) => Some(s.to_string_lossy()),
|
||||
_ => None,
|
||||
},
|
||||
loot,
|
||||
) else {
|
||||
return nbt;
|
||||
};
|
||||
let seed = match nbt.get(&JavaString::from("LootTableSeed")) {
|
||||
Some(Tag::Long(seed)) => *seed,
|
||||
_ => 0,
|
||||
};
|
||||
let pos = match nbt.get(&JavaString::from("Pos")) {
|
||||
Some(Tag::List(p)) => std::array::from_fn(|i| match p.get(i) {
|
||||
Some(Tag::Double(b)) => f64::from_bits(*b).floor() as i32,
|
||||
_ => 0,
|
||||
}),
|
||||
_ => [0; 3],
|
||||
};
|
||||
let biome = chunk.biome_at(pos[0], pos[1], pos[2]);
|
||||
let slots: Vec<Option<ItemStack>> = loot
|
||||
.fill(&table, seed, 27, Some(biome))
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
s.map(|s| ItemStack {
|
||||
item: Arc::from(s.item.as_str()),
|
||||
count: s.count.max(0) as u32,
|
||||
damage: s.damage.max(0) as u32,
|
||||
extra: None,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
nbt.remove(&JavaString::from("LootTable"));
|
||||
nbt.remove(&JavaString::from("LootTableSeed"));
|
||||
nbt.insert("Items".into(), crate::save::encode_items(&slots));
|
||||
nbt
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ pub struct VanillaTerrain {
|
||||
biome_map: Vec<u16>,
|
||||
/// Loot tables for generated containers.
|
||||
loot: Option<Arc<horizon_world::loot::LootData>>,
|
||||
/// A worker for structure queries from the game thread.
|
||||
query: std::sync::Mutex<Option<GeneratorWorker>>,
|
||||
}
|
||||
/// A proto chunk, or the position of one whose generation failed.
|
||||
enum VanillaProto {
|
||||
@@ -66,8 +68,19 @@ impl VanillaTerrain {
|
||||
generator,
|
||||
biome_map,
|
||||
loot,
|
||||
query: std::sync::Mutex::new(None),
|
||||
})
|
||||
}
|
||||
/// The structure starts owned by a chunk (cached by the generator).
|
||||
pub fn starts_at(
|
||||
&self,
|
||||
x: i32,
|
||||
z: i32,
|
||||
) -> Vec<Arc<horizon_world::worldgen::structure::start::StructureStart>> {
|
||||
let mut worker = self.query.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let worker = worker.get_or_insert_with(|| self.generator.worker());
|
||||
worker.structure_starts(ChunkPos::new(x, z))
|
||||
}
|
||||
/// `/locate structure`: the nearest start of one of `names` within
|
||||
/// `radius` placement sectors of block `from`.
|
||||
pub fn locate(
|
||||
@@ -200,8 +213,17 @@ impl ChunkGenerator for VanillaTerrain {
|
||||
}
|
||||
out.biomes = Arc::new(biomes);
|
||||
out.block_entities = crate::structure_blocks::block_entities(&chunk, self.loot.as_deref());
|
||||
out.entities = std::mem::take(&mut chunk.entities)
|
||||
out.structure_refs = chunk
|
||||
.structures()
|
||||
.into_iter()
|
||||
.map(|(id, start, _, _)| (Arc::from(id), (start.x, start.z)))
|
||||
.collect();
|
||||
let entities = std::mem::take(&mut chunk.entities);
|
||||
out.entities = entities
|
||||
.into_iter()
|
||||
.map(|nbt| {
|
||||
crate::structure_blocks::unpack_entity_loot(&chunk, nbt, self.loot.as_deref())
|
||||
})
|
||||
.map(horizon_world::nbt::Tag::Compound)
|
||||
.collect();
|
||||
for s in &mut out.sections {
|
||||
|
||||
@@ -5,6 +5,7 @@ use super::{
|
||||
legacy::{LegacyPiece, PieceContext, Result, TemplateHandler, TemplatePiece, offset},
|
||||
processor::ProcessorList,
|
||||
};
|
||||
use crate::nbt::{Compound, Tag};
|
||||
use horizon_core::{geometry::Direction, random::RandomSource};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -413,9 +414,31 @@ impl LegacyPiece for EndCityPiece {
|
||||
return Ok(());
|
||||
};
|
||||
for (marker, pos) in markers {
|
||||
// Sentry shulkers and elytra item frames are entities, which
|
||||
// generation does not produce yet.
|
||||
if marker.starts_with("Chest") {
|
||||
if marker.starts_with("Sentry") {
|
||||
c.world.entity(super::legacy::spawn_nbt(
|
||||
"minecraft:shulker",
|
||||
pos,
|
||||
false,
|
||||
false,
|
||||
))?;
|
||||
} else if marker.starts_with("Elytra") {
|
||||
// An item frame on the marker, facing the rotated south.
|
||||
let facing = self.0.rotation.rotate_direction(Direction::South);
|
||||
let mut nbt = super::legacy::spawn_nbt("minecraft:item_frame", pos, false, false);
|
||||
nbt.insert("block_pos".into(), Tag::IntArray(pos.to_vec()));
|
||||
let data = match facing {
|
||||
Direction::North => 2,
|
||||
Direction::South => 3,
|
||||
Direction::West => 4,
|
||||
_ => 5,
|
||||
};
|
||||
nbt.insert("Facing".into(), Tag::Byte(data));
|
||||
let mut item = Compound::new();
|
||||
item.insert("id".into(), Tag::String("minecraft:elytra".into()));
|
||||
item.insert("count".into(), Tag::Int(1));
|
||||
nbt.insert("Item".into(), Tag::Compound(item));
|
||||
c.world.entity(nbt)?;
|
||||
} else if marker.starts_with("Chest") {
|
||||
let chest = offset(pos, Direction::Down, 1);
|
||||
if c.chunk_box.is_inside(chest) {
|
||||
c.loot_table(
|
||||
|
||||
@@ -50,6 +50,8 @@ pub trait PieceWorld {
|
||||
fn min_y(&mut self) -> Result<i32>;
|
||||
fn max_y(&mut self) -> Result<i32>;
|
||||
fn block_entity(&mut self, pos: [i32; 3], nbt: Compound) -> Result<()>;
|
||||
/// `addFreshEntity`: an entity from its NBT (absolute `Pos`).
|
||||
fn entity(&mut self, nbt: Compound) -> Result<()>;
|
||||
fn post_process(&mut self, pos: [i32; 3]) -> Result<()>;
|
||||
/// WorldGenLevel.getSeed.
|
||||
fn seed(&mut self) -> Result<i64>;
|
||||
@@ -96,6 +98,9 @@ impl<W: FeatureWorld + PlacementContext> PieceWorld for W {
|
||||
fn max_y(&mut self) -> Result<i32> {
|
||||
PlacementContext::max_y(self)
|
||||
}
|
||||
fn entity(&mut self, nbt: Compound) -> Result<()> {
|
||||
self.add_entity(nbt)
|
||||
}
|
||||
fn block_entity(&mut self, pos: [i32; 3], nbt: Compound) -> Result<()> {
|
||||
self.set_block_entity(pos, nbt)
|
||||
}
|
||||
@@ -715,6 +720,33 @@ pub fn counter_clockwise(d: Direction) -> Direction {
|
||||
|
||||
/// TemplateStructurePiece: one template with fixed settings; data markers
|
||||
/// are handed to the owning structure.
|
||||
/// NBT for an entity a structure piece spawns at the block centre of `pos`
|
||||
/// (y at the block's floor): `finalize` asks the game for `finalizeSpawn`
|
||||
/// (STRUCTURE), `persistent` sets `PersistenceRequired`.
|
||||
pub fn spawn_nbt(id: &str, pos: [i32; 3], finalize: bool, persistent: bool) -> Compound {
|
||||
let mut nbt = Compound::new();
|
||||
nbt.insert("id".into(), Tag::String(id.into()));
|
||||
let p = [
|
||||
f64::from(pos[0]) + 0.5,
|
||||
f64::from(pos[1]),
|
||||
f64::from(pos[2]) + 0.5,
|
||||
];
|
||||
nbt.insert(
|
||||
"Pos".into(),
|
||||
Tag::List(p.iter().map(|v| Tag::Double(v.to_bits())).collect()),
|
||||
);
|
||||
nbt.insert(
|
||||
"Rotation".into(),
|
||||
Tag::List(vec![Tag::Float(0f32.to_bits()), Tag::Float(0f32.to_bits())]),
|
||||
);
|
||||
if persistent {
|
||||
nbt.insert("PersistenceRequired".into(), Tag::Byte(1));
|
||||
}
|
||||
if finalize {
|
||||
nbt.insert("horizon:finalize".into(), Tag::Byte(1));
|
||||
}
|
||||
nbt
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct TemplatePiece {
|
||||
pub type_name: &'static str,
|
||||
|
||||
@@ -939,9 +939,14 @@ pub fn post_process(piece: &TemplatePiece, c: &mut PieceContext<'_>) -> Result<(
|
||||
let state = c.state_with("chest", &[("facing", direction_name(facing))]);
|
||||
create_chest(c, pos, "minecraft:chests/woodland_mansion", Some(state))?;
|
||||
} else if matches!(marker.as_str(), "Mage" | "Warrior" | "Group of Allays") {
|
||||
// Mobs are not spawned; the marker is cleared as after a spawn.
|
||||
if marker == "Group of Allays" {
|
||||
c.world.level_int(3)?;
|
||||
let (id, count) = match marker.as_str() {
|
||||
"Mage" => ("minecraft:evoker", 1),
|
||||
"Warrior" => ("minecraft:vindicator", 1),
|
||||
_ => ("minecraft:allay", c.world.level_int(3)? + 1),
|
||||
};
|
||||
for _ in 0..count {
|
||||
c.world
|
||||
.entity(super::legacy::spawn_nbt(id, pos, true, true))?;
|
||||
}
|
||||
c.world.set(pos, c.state("air"), 2)?;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use super::{
|
||||
BoundingBox,
|
||||
legacy::{LegacyPiece, PieceContext, PieceFrame, Result, solid_render},
|
||||
};
|
||||
use crate::nbt::Tag;
|
||||
use crate::worldgen::biome::BiomeId;
|
||||
use horizon_core::{geometry::Direction, random::RandomSource};
|
||||
use std::{
|
||||
@@ -612,9 +613,24 @@ impl MineshaftPiece {
|
||||
};
|
||||
let rail = c.state_with("rail", &[("shape", shape)]);
|
||||
self.frame.place(c, rail, x, y, z)?;
|
||||
// The chest minecart entity (loot table seed drawn here) is not
|
||||
// stored: worldgen output carries no entities.
|
||||
c.random.long();
|
||||
// A chest minecart with the mineshaft loot table.
|
||||
let seed = c.random.long();
|
||||
let mut nbt = super::legacy::spawn_nbt("minecraft:chest_minecart", pos, false, false);
|
||||
let p = [
|
||||
f64::from(pos[0]) + 0.5,
|
||||
f64::from(pos[1]) + 0.5,
|
||||
f64::from(pos[2]) + 0.5,
|
||||
];
|
||||
nbt.insert(
|
||||
"Pos".into(),
|
||||
Tag::List(p.iter().map(|v| Tag::Double(v.to_bits())).collect()),
|
||||
);
|
||||
nbt.insert(
|
||||
"LootTable".into(),
|
||||
Tag::String("minecraft:chests/abandoned_mineshaft".into()),
|
||||
);
|
||||
nbt.insert("LootTableSeed".into(), Tag::Long(seed));
|
||||
c.world.entity(nbt)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -342,6 +342,19 @@ struct W<'x, 'c> {
|
||||
water: BlockStateId,
|
||||
}
|
||||
impl W<'_, '_> {
|
||||
/// OceanMonumentPiece.spawnElder.
|
||||
fn elder(&mut self, x: i32, y: i32, z: i32) -> Result<()> {
|
||||
let pos = self.f.world_pos(x, y, z);
|
||||
if self.c.chunk_box.is_inside(pos) {
|
||||
self.c.world.entity(super::legacy::spawn_nbt(
|
||||
"minecraft:elder_guardian",
|
||||
pos,
|
||||
true,
|
||||
false,
|
||||
))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn bx(
|
||||
&mut self,
|
||||
@@ -1191,7 +1204,7 @@ fn room(w: &mut W<'_, '_>, p: &Palette, child: &Child, rooms: &[Room]) -> Result
|
||||
w.bx(8, 0, 10, 8, 2, 10, l)?;
|
||||
w.bx(6, -1, 7, 7, -1, 8, k)?;
|
||||
w.water(6, -1, 3, 7, -1, 4)?;
|
||||
// spawnElder: entities are not created.
|
||||
w.elder(6, 1, 6)?;
|
||||
}
|
||||
Kind::Simple(design) => {
|
||||
if upper {
|
||||
@@ -1395,6 +1408,7 @@ fn room(w: &mut W<'_, '_>, p: &Palette, child: &Child, rooms: &[Room]) -> Result
|
||||
w.put(l, 13, 7, 20)?;
|
||||
w.bx(6, 0, 21, 7, 4, 21, l)?;
|
||||
w.bx(15, 0, 21, 16, 4, 21, l)?;
|
||||
w.elder(11, 2, 16)?;
|
||||
}
|
||||
Kind::Wing(_) => {
|
||||
w.bx(9, 3, 18, 13, 3, 20, l)?;
|
||||
@@ -1420,6 +1434,7 @@ fn room(w: &mut W<'_, '_>, p: &Palette, child: &Child, rooms: &[Room]) -> Result
|
||||
}
|
||||
w.bx(8, 3, 8, 8, 3, 13, k)?;
|
||||
w.bx(14, 3, 8, 14, 3, 13, k)?;
|
||||
w.elder(11, 5, 13)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -338,7 +338,12 @@ pub fn post_process(piece: &TemplatePiece, c: &mut PieceContext<'_>) -> Result<(
|
||||
};
|
||||
c.loot_table(pos, "minecraft:chest", table)?;
|
||||
} else if marker == "drowned" {
|
||||
// The drowned entity is not created; its marker block is cleared.
|
||||
c.world.entity(super::legacy::spawn_nbt(
|
||||
"minecraft:drowned",
|
||||
pos,
|
||||
true,
|
||||
true,
|
||||
))?;
|
||||
let sea = 63;
|
||||
let state = if pos[1] > sea {
|
||||
c.state("air")
|
||||
|
||||
@@ -493,6 +493,14 @@ impl LegacyPiece for SwampHutPiece {
|
||||
f.fill_column_down(c, log, x, -1, z)?;
|
||||
}
|
||||
}
|
||||
// The witch, then spawnCat, both at (2, 2, 5).
|
||||
let pos = f.world_pos(2, 2, 5);
|
||||
if c.chunk_box.is_inside(pos) {
|
||||
for id in ["minecraft:witch", "minecraft:cat"] {
|
||||
c.world
|
||||
.entity(super::legacy::spawn_nbt(id, pos, true, true))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user