pub struct SpawnRule {
pub kind: MobKind,
pub weight: f32,
pub ring: SpawnRing,
pub time: TimeWindow,
pub placement: SpawnPlacement,
pub cap: usize,
pub zone: Option<SpawnZone>,
pub despawn_outside_window: bool,
}Expand description
One spawning rule: which kind appears, where, when and how many.
Built with chained setters:
use voxel_framework::mobs::{SpawnRule, TimeWindow};
let rule = SpawnRule::new("night_slime")
.time(TimeWindow::Night)
.ring(12.0, 32.0)
.cap(6)
.zone(|ctx| ctx.position.y < 80.0)
.despawn_outside_window(true);
assert_eq!(rule.cap, 6);Fields§
§kind: MobKindKind to spawn; must be registered in MobRegistry.
weight: f32Relative chance against other rules that apply. Default: 1.0.
ring: SpawnRingDistance band around the player. Default: [12, 32]. Capped
below the kind’s despawn_distance; ground rules need a ring at least
1.5 units wide.
time: TimeWindowPart of the day in which the rule applies. Default: Any.
placement: SpawnPlacementGround or free-space placement. Default: Ground.
cap: usizeMost live mobs of this kind allowed within ring.max of one player.
Default: 4.
zone: Option<SpawnZone>Optional extra condition on the candidate position (the hook for biomes or regions). Default: none.
despawn_outside_window: boolDespawn mobs spawned by this rule once time stops applying.
Default: false.
Implementations§
Source§impl SpawnRule
impl SpawnRule
Sourcepub fn new(kind: impl Into<MobKind>) -> Self
pub fn new(kind: impl Into<MobKind>) -> Self
Creates a rule for kind with the defaults listed on each field.
Sourcepub fn ring(self, min: f32, max: f32) -> Self
pub fn ring(self, min: f32, max: f32) -> Self
Sets the distance band; see SpawnRing::new.
Sourcepub fn time(self, time: TimeWindow) -> Self
pub fn time(self, time: TimeWindow) -> Self
Sets the time window.
Sourcepub fn placement(self, placement: SpawnPlacement) -> Self
pub fn placement(self, placement: SpawnPlacement) -> Self
Sets the placement.
Sourcepub fn zone(
self,
zone: impl Fn(&SpawnContext<'_>) -> bool + Send + Sync + 'static,
) -> Self
pub fn zone( self, zone: impl Fn(&SpawnContext<'_>) -> bool + Send + Sync + 'static, ) -> Self
Sets the zone predicate.
Sourcepub fn despawn_outside_window(self, despawn: bool) -> Self
pub fn despawn_outside_window(self, despawn: bool) -> Self
Sets whether mobs despawn once the time window stops applying.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SpawnRule
impl !UnwindSafe for SpawnRule
impl Forget for SpawnRule
impl Freeze for SpawnRulewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<dyn Fn(&SpawnContext<'_>) -> bool + Sync + Send> is !null: Freeze,
PhantomData<ArcInner<dyn Fn(&SpawnContext<'_>) -> bool + Sync + Send>>: Freeze,
impl Move for SpawnRule
impl Send for SpawnRule
impl Sync for SpawnRule
impl Unpin for SpawnRule
impl UnsafeUnpin for SpawnRulewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<dyn Fn(&SpawnContext<'_>) -> bool + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(&SpawnContext<'_>) -> bool + Sync + Send>>: UnsafeUnpin,
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, 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