mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-13 19:08:41 -06:00
wip item system
This commit is contained in:
parent
c746c19068
commit
cbefcffb93
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -1026,6 +1026,7 @@ dependencies = [
|
|||
"hashbrown 0.14.2",
|
||||
"nohash-hasher",
|
||||
"num_enum",
|
||||
"nz",
|
||||
"postcard",
|
||||
"rand",
|
||||
"rand_xoshiro",
|
||||
|
@ -1325,6 +1326,12 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nz"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28ba9cab725a7d7ece4bbf38968a1717ed73abf0516f7ff90a4127d016bebd51"
|
||||
|
||||
[[package]]
|
||||
name = "objc-sys"
|
||||
version = "0.3.1"
|
||||
|
|
|
@ -20,6 +20,7 @@ hashbrown = { version = "0.14", features = ["serde"] }
|
|||
nohash-hasher = "0.2"
|
||||
#bytemuck = { version = "1.14", features = ["derive"] }
|
||||
static_assertions = "1.1"
|
||||
nz = "0.3"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use strum::EnumIter;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use crate::item::Item;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, Debug, EnumIter)]
|
||||
#[repr(u8)]
|
||||
|
@ -50,82 +51,95 @@ impl Block {
|
|||
render: RenderType::None,
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: false,
|
||||
drops: None,
|
||||
},
|
||||
Self::Marker => BlockDescriptor {
|
||||
name: "marker",
|
||||
render: RenderType::None,
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: false,
|
||||
drops: None,
|
||||
},
|
||||
Self::Stone => BlockDescriptor {
|
||||
name: "stone",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Stone)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
Self::Stone => BlockDescriptor {
|
||||
name: "stone",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Stone)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Dirt => BlockDescriptor {
|
||||
name: "dirt",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Dirt)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
Self::Dirt => BlockDescriptor {
|
||||
name: "dirt",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Dirt)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Grass => BlockDescriptor {
|
||||
name: "grass",
|
||||
Self::Grass => BlockDescriptor {
|
||||
name: "grass",
|
||||
render: RenderType::SolidBlock(CubeTexture::top_sides_bottom(
|
||||
BlockTexture::GrassTop,
|
||||
BlockTexture::GrassSide,
|
||||
BlockTexture::GrassTop,
|
||||
BlockTexture::GrassSide,
|
||||
BlockTexture::Dirt
|
||||
)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Sand => BlockDescriptor {
|
||||
name: "sand",
|
||||
Self::Sand => BlockDescriptor {
|
||||
name: "sand",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Sand)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Cobblestone => BlockDescriptor {
|
||||
name: "cobblestone",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Cobblestone)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::TallGrass => BlockDescriptor {
|
||||
name: "tall grass",
|
||||
render: RenderType::CrossShape(CrossTexture::all(BlockTexture::TallGrass)),
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Planks => BlockDescriptor {
|
||||
name: "planks",
|
||||
Self::Planks => BlockDescriptor {
|
||||
name: "planks",
|
||||
render: RenderType::SolidBlock(CubeTexture::all(BlockTexture::Planks)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Torch => BlockDescriptor {
|
||||
name: "torch",
|
||||
render: RenderType::CrossShape(CrossTexture::all(BlockTexture::Torch)),
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Wood => BlockDescriptor {
|
||||
name: "leaf",
|
||||
render: RenderType::SolidBlock(CubeTexture::horizontal_vertical(BlockTexture::Wood, BlockTexture::WoodTop)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Leaf => BlockDescriptor {
|
||||
name: "leaf",
|
||||
render: RenderType::BinaryTransparency(CubeTexture::all(BlockTexture::Leaf)),
|
||||
collision: CollisionType::Solid,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
Self::Water => BlockDescriptor {
|
||||
name: "water",
|
||||
render: RenderType::BinaryTransparency(CubeTexture::all(BlockTexture::WaterSolid)),
|
||||
collision: CollisionType::None,
|
||||
raycast_collision: true,
|
||||
drops: None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -137,12 +151,8 @@ pub struct BlockDescriptor {
|
|||
pub render: RenderType,
|
||||
pub collision: CollisionType,
|
||||
pub raycast_collision: bool,
|
||||
pub drops: Option<Item>,
|
||||
}
|
||||
// impl BlockDescriptor {
|
||||
// pub fn of(block: Block) -> Self {
|
||||
// block.descriptor()
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct CubeTexture {
|
||||
|
|
66
kubi-shared/src/item.rs
Normal file
66
kubi-shared/src/item.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
use std::num::NonZeroU8;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use strum::EnumIter;
|
||||
use crate::block::Block;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum ItemUsage {
|
||||
AsBlock(Block)
|
||||
}
|
||||
|
||||
pub struct ItemDescriptor {
|
||||
pub name: &'static str,
|
||||
pub usage: Option<ItemUsage>,
|
||||
pub stack_size: NonZeroU8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Hash, Debug, EnumIter, TryFromPrimitive)]
|
||||
#[repr(u8)]
|
||||
pub enum Item {
|
||||
TestItem,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
#[inline]
|
||||
pub const fn descriptor(self) -> ItemDescriptor {
|
||||
match self {
|
||||
Self::TestItem => ItemDescriptor {
|
||||
name: "Test Item",
|
||||
usage: None,
|
||||
stack_size: nz::u8!(32),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct ItemCollection(Option<(Item, NonZeroU8)>);
|
||||
|
||||
impl ItemCollection {
|
||||
pub const fn new(item: Item, amount: NonZeroU8) -> Self {
|
||||
Self(Some((item, amount)))
|
||||
}
|
||||
|
||||
pub const fn new_single(item: Item) -> Self {
|
||||
Self(Some((item, nz::u8!(1))))
|
||||
}
|
||||
|
||||
pub const fn new_empty() -> Self {
|
||||
Self(None)
|
||||
}
|
||||
|
||||
pub const fn with_amount(&self, amount: NonZeroU8) -> Self {
|
||||
Self(match self.0 {
|
||||
Some((item, _)) => Some((item, amount)),
|
||||
None => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Add items from another slot, copying them\
|
||||
/// Returns the leftover items
|
||||
pub fn add(&mut self, from: &Self) -> Self {
|
||||
let Some((item, count)) = from.0 else { return Self::new_empty() };
|
||||
todo!() //TODO finish item slot system
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
pub mod block;
|
||||
pub mod item;
|
||||
pub mod networking;
|
||||
pub mod worldgen;
|
||||
pub mod chunk;
|
||||
|
|
Loading…
Reference in a new issue