pub struct DropTable<I: ItemType> { /* private fields */ }Expand description
Mapping from voxel byte IDs to item drop definitions.
Each entry associates a voxel byte value (the u8 returned by
crate::voxel::VoxelType::to_byte) with an item type and a drop-count
range [min, max]. Runtime entries may also carry a chance, and a voxel may
have multiple entries. When a matching voxel is broken,
spawn_drops_system queries this table and selects counts/chance outcomes
using deterministic pseudo-random values seeded from the voxel’s world
position. If min == max the count is always fixed.
DropTable is initialized empty; register entries before the first
crate::world::VoxelBroken message is processed. It is available as a
Bevy Resource after DropsPlugin is added.
§Examples
use voxel_framework::items::{DropTable, DefaultItem};
let mut table = DropTable::<DefaultItem>::new();
// Voxel byte 1 drops 1–3 rock fragments.
table.register(1, DefaultItem::RockFragment, 1, 3);
// Voxel byte 2 always drops exactly 1 iron ore.
table.register(2, DefaultItem::IronOre, 1, 1);
// Voxel byte 3 can produce multiple runtime entries.
table.add_entry(3, voxel_framework::items::DropTableEntry::new(DefaultItem::Cobblestone, 1, 1));
table.add_entry(3, voxel_framework::items::DropTableEntry::with_chance(DefaultItem::Coal, 1, 2, 0.25));Implementations§
Source§impl<I: ItemType> DropTable<I>
impl<I: ItemType> DropTable<I>
Sourcepub fn register(&mut self, voxel_byte: u8, item: I, min: u32, max: u32)
pub fn register(&mut self, voxel_byte: u8, item: I, min: u32, max: u32)
Registers a drop for the given voxel byte.
When a voxel with voxel_byte is broken, between min and max items
(inclusive) of item will be dropped. If min == max the count is
always fixed.
This replaces any previous runtime entries for the voxel byte, preserving
the historical one-entry behavior of DropTable::register. Use
DropTable::add_entry when a voxel should produce multiple drops.
Sourcepub fn register_with_chance(
&mut self,
voxel_byte: u8,
item: I,
min: u32,
max: u32,
chance: f32,
)
pub fn register_with_chance( &mut self, voxel_byte: u8, item: I, min: u32, max: u32, chance: f32, )
Registers a single probabilistic drop for the given voxel byte.
Like DropTable::register, this replaces any previous entries for the
voxel byte.
Sourcepub fn add_entry(&mut self, voxel_byte: u8, entry: DropTableEntry<I>)
pub fn add_entry(&mut self, voxel_byte: u8, entry: DropTableEntry<I>)
Appends one runtime entry without removing existing entries for the same voxel byte.
Sourcepub fn replace_entries(
&mut self,
voxel_byte: u8,
entries: impl IntoIterator<Item = DropTableEntry<I>>,
)
pub fn replace_entries( &mut self, voxel_byte: u8, entries: impl IntoIterator<Item = DropTableEntry<I>>, )
Replaces all runtime entries for one voxel byte.
Sourcepub fn iter_entries(&self) -> impl Iterator<Item = (u8, I, u32, u32)> + '_
pub fn iter_entries(&self) -> impl Iterator<Item = (u8, I, u32, u32)> + '_
Iterates over all explicitly registered drop entries.
Yields (voxel_byte, item, min_count, max_count) for each registration.
Identity-fallback entries (not explicitly registered) are not included.
Sourcepub fn iter_drop_entries(
&self,
) -> impl Iterator<Item = (u8, &DropTableEntry<I>)> + '_
pub fn iter_drop_entries( &self, ) -> impl Iterator<Item = (u8, &DropTableEntry<I>)> + '_
Iterates over all explicitly registered runtime drop entries, including chance metadata.
Sourcepub fn get_drop(&self, voxel_byte: u8, seed: u64) -> Option<(I, u32)>
pub fn get_drop(&self, voxel_byte: u8, seed: u64) -> Option<(I, u32)>
Returns the drop for voxel_byte, using seed for deterministic count
selection within [min, max].
Explicit registrations always win. If no entry is registered for
voxel_byte, falls back to the identity mapping: I::from_byte(voxel_byte)
with count 1. If the resulting item is the empty sentinel (i.e.
item.to_byte() == 0), returns None — meaning no drop.
Trait Implementations§
impl<I: ItemType> Resource for DropTable<I>
Auto Trait Implementations§
impl<I> Freeze for DropTable<I>
impl<I> RefUnwindSafe for DropTable<I>
impl<I> Send for DropTable<I>
impl<I> Sync for DropTable<I>
impl<I> Unpin for DropTable<I>
impl<I> UnsafeUnpin for DropTable<I>
impl<I> UnwindSafe for DropTable<I>
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more