Skip to content

Commit

Permalink
Merge pull request '1.21.1 Migration' (#50) from 1.21.1migration into…
Browse files Browse the repository at this point in the history
… main

Reviewed-on: https://codeberg.org/DM-Earth/rimecraft/pulls/50
Reviewed-by: C191239 <[email protected]>
  • Loading branch information
C191239 committed Aug 25, 2024
2 parents 4d0afe9 + 8c62764 commit 16eed59
Show file tree
Hide file tree
Showing 17 changed files with 1,024 additions and 605 deletions.
8 changes: 6 additions & 2 deletions crates/core/block-entity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ rimecraft-global-cx = { path = "../global-cx" }
rimecraft-registry = { path = "../registry" }
rimecraft-block = { path = "../block" }
rimecraft-voxel-math = { path = "../../util/voxel-math" }
rimecraft-downcast = { path = "../../util/downcast" }
typeid = "1.0"
ahash = "0.8"
serde = "1.0"
erased-serde = "0.4"
rimecraft-serde-update = { path = "../../util/serde-update", features = ["erased"] }
rimecraft-serde-update = { path = "../../util/serde-update", features = [
"erased",
] }
component = { path = "../component", package = "rimecraft-component" }
bitflags = "2.6"

[features]

Expand Down
50 changes: 50 additions & 0 deletions crates/core/block-entity/src/components_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::fmt::Debug;

use ahash::AHashSet;
use component::{map::ComponentMap, ComponentType, RawErasedComponentType};
use rimecraft_global_cx::ProvideIdTy;

/// Access to components of a block entity.
pub struct ComponentsAccess<'env, 'a, Cx>
where
Cx: ProvideIdTy,
{
pub(crate) set: &'env mut AHashSet<RawErasedComponentType<'a, Cx>>,
pub(crate) map: &'env ComponentMap<'a, Cx>,
}

impl<'a, Cx> ComponentsAccess<'_, 'a, Cx>
where
Cx: ProvideIdTy,
{
/// Gets a component of the given type.
///
/// # Safety
///
/// This function could not guarantee lifetime of type `T` is sound.
/// The type `T`'s lifetime parameters should not overlap lifetime `'a`.
pub unsafe fn get<T>(&mut self, ty: &ComponentType<'a, T>) -> Option<&T> {
self.set.insert(RawErasedComponentType::from(ty));
self.map.get(ty)
}

/// Reborrow this access.
pub fn reborrow(&mut self) -> ComponentsAccess<'_, 'a, Cx> {
ComponentsAccess {
set: self.set,
map: self.map,
}
}
}

impl<Cx> Debug for ComponentsAccess<'_, '_, Cx>
where
Cx: ProvideIdTy<Id: Debug> + Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ComponentsAccess")
.field("set", &self.set)
.field("map", &self.map)
.finish()
}
}
229 changes: 0 additions & 229 deletions crates/core/block-entity/src/deser_nbt.rs

This file was deleted.

Loading

0 comments on commit 16eed59

Please sign in to comment.