Skip to content

Commit

Permalink
YES
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Oct 3, 2023
1 parent 2c37802 commit 8b94afd
Show file tree
Hide file tree
Showing 38 changed files with 360 additions and 2,016 deletions.
14 changes: 14 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rimecraft-primitives = { path = "../primitives", features = [
"serde",
"edcode",
] }
rimecraft-caches = { path = "../util/caches", features = ["arc"] }
rimecraft-collections = { path = "../util/collections", features = [
"id_list",
"packed_array",
] }
rimecraft-edcode = { path = "../util/edcode", features = ["uuid"] }
rimecraft-event = { path = "../util/event" }
rimecraft-freezer = { path = "../util/freezer" }
rimecraft-nbt-ext = { path = "../util/nbt_ext" }
chrono = { version = "0.4", features = ["serde"] }
tracing = "0.1"
tracing-subscriber = "0.3"
Expand All @@ -29,3 +42,4 @@ dashmap = "5.4"
bimap = "0.6"
thiserror = "1.0"
rsa = "0.9"
enumn = "0.1"
12 changes: 6 additions & 6 deletions core/src/block/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ impl BlockEntity {
self.be_type
}

fn read_nbt(&mut self, nbt: &crate::nbt::NbtCompound) {
fn read_nbt(&mut self, nbt: &rimecraft_nbt_ext::Compound) {
self.data.read(nbt)
}

fn write_nbt(&self, nbt: &mut crate::nbt::NbtCompound) {
fn write_nbt(&self, nbt: &mut rimecraft_nbt_ext::Compound) {
self.data.write(nbt)
}
}

pub trait Data: std::any::Any + Send + Sync + 'static {
fn read(&mut self, nbt: &crate::nbt::NbtCompound);
fn read(&mut self, nbt: &rimecraft_nbt_ext::Compound);

fn write(&self, nbt: &mut crate::nbt::NbtCompound);
fn write(&self, nbt: &mut rimecraft_nbt_ext::Compound);
}

#[derive(Clone, Copy, Eq)]
pub struct Type {
id: usize,
blocks: crate::Ref<'static, Vec<super::Block>>,
blocks: rimecraft_primitives::Ref<'static, Vec<super::Block>>,
}

impl Type {
Expand All @@ -77,7 +77,7 @@ impl crate::registry::Registration for Type {
self.id = id
}

fn raw_id(&self) -> usize {
fn index_of(&self) -> usize {
self.id
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/block/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ impl Events {
/// The required `item` can be `None` for some events
/// so that all items will be affected by this callback.
pub fn register(&mut self, item: Option<super::Block>, callback: Callback) {
self.0.push((item.map(|e| e.raw_id()), callback));
self.0.push((item.map(|e| e.index_of()), callback));
}

pub fn block_item_map(&self, state: &super::BlockState) -> crate::item::ItemStack {
let id = state.block().raw_id();
let id = state.block().index_of();

self.0
.iter()
Expand All @@ -30,7 +30,7 @@ impl Events {
}

pub fn is_air(&self, state: &super::BlockState) -> bool {
let id = state.block().raw_id();
let id = state.block().index_of();

self.0
.iter()
Expand All @@ -42,7 +42,7 @@ impl Events {
}

pub fn has_random_ticks(&self, state: &super::BlockState) -> bool {
let id = state.block().raw_id();
let id = state.block().index_of();

self.0
.iter()
Expand Down
21 changes: 10 additions & 11 deletions core/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ mod event;

use std::{hash::Hash, ops::Deref};

use crate::{
prelude::*,
registry::{Registration, RegistryAccess},
};
use crate::registry::{Registration, RegistryAccess};

pub use event::*;

use once_cell::sync::Lazy;
use rimecraft_collections::IdList;
use rimecraft_freezer::Freezer;

//TODO: Build and freeze STATE_IDS

/// An `ID <-> BlockState` list.
pub static STATE_IDS: Lazy<crate::util::Freezer<crate::collections::IdList<SharedBlockState>>> =
once_cell::sync::Lazy::new(|| crate::util::Freezer::new(crate::collections::IdList::new()));
pub static STATE_IDS: Lazy<Freezer<IdList<SharedBlockState>>> =
once_cell::sync::Lazy::new(|| Freezer::new(IdList::new()));

/// Represents a block.
#[derive(Clone, Copy)]
pub struct Block {
id: usize,
pub states: crate::util::Ref<'static, crate::state::States<BlockState>>,
pub states: rimecraft_primitives::Ref<'static, crate::state::States<BlockState>>,
}

impl Block {
Expand All @@ -47,7 +46,7 @@ impl Block {
pub fn default_state(&self) -> SharedBlockState {
crate::state::Shared {
entries: self.states,
value: crate::Ref(self.states.0.default_state()),
value: rimecraft_primitives::Ref(self.states.0.default_state()),
}
}
}
Expand All @@ -61,7 +60,7 @@ impl Registration for Block {
.for_each(|state| state.block.store(id, std::sync::atomic::Ordering::Relaxed))
}

fn raw_id(&self) -> usize {
fn index_of(&self) -> usize {
self.id
}
}
Expand All @@ -84,7 +83,7 @@ impl serde::Serialize for Block {
S: serde::Serializer,
{
crate::registry::BLOCK
.get_from_raw(self.raw_id())
.get_from_raw(self.index_of())
.unwrap()
.key()
.value()
Expand All @@ -97,7 +96,7 @@ impl<'de> serde::Deserialize<'de> for Block {
where
D: serde::Deserializer<'de>,
{
let id = Id::deserialize(deserializer)?;
let id = rimecraft_primitives::Id::deserialize(deserializer)?;
Ok(crate::registry::BLOCK.get_from_id(&id).map_or_else(
|| {
tracing::debug!("Tried to load invalid block: {id}");
Expand Down
Loading

0 comments on commit 8b94afd

Please sign in to comment.