Fix `placement` system crashing ...

... due to block definitions not being loaded yet
(noticeable on web builds)
main
copygirl 6 days ago
parent 0cc65bf300
commit ddf01160c3
  1. 11
      common/src/block.rs

@ -41,7 +41,10 @@ pub struct BlockMap(HashMap<BlockPos, Entity>);
#[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<Res<'w, BlockDefinitionCollection>>,
_definition_assets: Res<'w, Assets<BlockDefinition>>,
blocks: Query<'w, 's, &'static Block>,
commands: Commands<'w, 's>,
@ -65,7 +68,11 @@ impl Blocks<'_, '_> {
pos: BlockPos,
id: Identifier<Block>,
) -> Result<EntityCommands, SpawnBlockError> {
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) {

Loading…
Cancel
Save