Skip to main content

DropTable

Struct DropTable 

Source
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>

Source

pub fn new() -> Self

Creates an empty drop table.

Source

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.

Source

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.

Source

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.

Source

pub fn replace_entries( &mut self, voxel_byte: u8, entries: impl IntoIterator<Item = DropTableEntry<I>>, )

Replaces all runtime entries for one voxel byte.

Source

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.

Source

pub fn iter_drop_entries( &self, ) -> impl Iterator<Item = (u8, &DropTableEntry<I>)> + '_

Iterates over all explicitly registered runtime drop entries, including chance metadata.

Source

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.

Source

pub fn get_drops(&self, voxel_byte: u8, seed: u64) -> Vec<(I, u32)>

Returns all drops produced for voxel_byte with deterministic chance rolls and count selection.

Trait Implementations§

Source§

impl<I: Clone + ItemType> Clone for DropTable<I>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug + ItemType> Debug for DropTable<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: ItemType> Default for DropTable<I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<I: ItemType> Resource for DropTable<I>
where Self: Send + Sync + 'static,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more