diff --git a/common/src/block.rs b/common/src/block.rs index b0118ca..31f8ee0 100644 --- a/common/src/block.rs +++ b/common/src/block.rs @@ -41,7 +41,10 @@ pub struct BlockMap(HashMap); #[derive(SystemParam)] pub struct Blocks<'w, 's> { map: Res<'w, BlockMap>, - definition_collection: Res<'w, BlockDefinitionCollection>, + // NOTE: `Option` is used because systems using this parameter might run + // before block definitions are loaded, since they might not have + // a concept of when gameplay is started, for example. + definition_collection: Option>, _definition_assets: Res<'w, Assets>, blocks: Query<'w, 's, &'static Block>, commands: Commands<'w, 's>, @@ -65,7 +68,11 @@ impl Blocks<'_, '_> { pos: BlockPos, id: Identifier, ) -> Result { - if self.definition_collection.get(&id).is_none() { + let definitions = self + .definition_collection + .as_deref() + .expect("attempted to spawn block before definitions are loaded"); + if definitions.get(&id).is_none() { return Err(SpawnBlockError::UnknownBlockId(id)); } if let Some(existing) = self.get(pos) {