Skip to main content

Trap

Struct Trap 

Source
pub struct Trap {
    pub id: TrapId,
    pub at: AnchorId,
    pub trigger: TrapTrigger,
    pub effect: Option<TrapEffect>,
    pub payload: Vec<QuestEffect>,
    pub lethality: Lethality,
    pub disarm: Option<TrapDisarm>,
    pub reset: TrapReset,
    pub requires_flags: Vec<FlagId>,
    pub forbids_flags: Vec<FlagId>,
    pub requires_state: Vec<StateCompare>,
}
Expand description

A stage-5 trap (DSL v0.6, spec-0011; command payloads spec-0022): an environmental hazard at one cell of a placed piece.

What the prefab has to provide is one point anchor with the trigger block in its cell, and for most traps that is all. Trap::at names the trigger/hazard cell; the piece places the plate, tripwire or trapped chest there (DW0917); the compiler models it as a hazard for the completability proofs (DW0342) and, for a disarmable trap, emits the disarm affordance. A payload trap needs nothing else: the compiler owns the detection, emitting a per-tick, edge-latched execute … if entity @a[<cell>] and running the authored effect bundle from it.

Two things a piece must pre-wire, each for one case and neither for the common one:

  • the legacy effect — a dispense payload the prefab’s own redstone fires — needs the anchor’s dispenser socket cell, which the compiler fills. That is the case “harm is redstone-native” (spec-0011) was written about, and the only one in which no detection is emitted.
  • a flag-gated trap (requires_flags / forbids_flags) needs the anchor’s trigger_block, because gating removes the trigger block from the world while the gate is shut and puts it back verbatim (DW0363).

Player-vs-mob distinguishing matters in a sealed box-garden with controlled mobs, so trapped-chest (opened by a player) is called out as the only player-distinct trigger.

Fields§

§id: TrapId

Unique trap id (trap/<kebab>).

§at: AnchorId

The point anchor this trap sits on — any anchor an area’s prefab provides, whatever it is called. Its cell is the trigger/hazard cell the compiler models, and for a payload trap that cell, holding the block its trigger names, is the whole of what the piece has to provide: detection is the compiler’s, the block is the piece’s (DW0917).

The anchor additionally needs a dispenser socket for a legacy effect trap, and a trigger_block for a flag-gated one (DW0363). anchor/trap is the name the shipped pieces use, and a name is all it is.

§trigger: TrapTrigger

What springs the trap (all redstone-native).

§effect: Option<TrapEffect>

The legacy redstone consequence (spec-0011): a static dispenser payload the prefab’s own wiring fires. Superseded by Trap::payload (spec-0022) — redstone now keeps only the trigger — but kept meaningful so existing campaigns build unchanged. Optional since spec-0022; a trap must declare effect, payload, or both (DW0440).

§payload: Vec<QuestEffect>

The command payload (spec-0022): an ordered effect list in the same vocabulary quests use, run when the trigger fires. This is where a trap’s consequence lives now — the compiler owns the detection tick and the effect vocabulary, so a trap’s payload is authored like any other effect bundle rather than built out of dust and repeaters. Expressiveness moves from “what dust can carry” to “what the effect vocabulary can say”: volley and collapse (spec-0022’s trap verbs) join damage-players, play-sound, narrate, set-flag and spawn-wave.

Empty = a pure spec-0011 redstone trap, which emits exactly what it emitted before (byte-identical).

§lethality: Lethality

How dangerous the trap is. A lethal trap on the forced critical path carries the completability obligation (DW0342); harmful/nonlethal carry none. Defaults to harmful.

§disarm: Option<TrapDisarm>

Optional disarm affordance (quest-coupling): an anchor the player acts on to turn the trap off — setting a flag and emptying the dispenser — before the trap cell is forced.

§reset: TrapReset

Whether the trap re-arms after firing. once = single-shot (fires, then spent — the survivability path); rearm = re-fires each trigger (default).

§requires_flags: Vec<FlagId>

Flags that must be set before the trap is considered active (mirrors EnvTrigger::requires_flags). Default empty.

§forbids_flags: Vec<FlagId>

Negative flag gate (DSL v0.6): the trap is considered inactive while ANY listed flag is set (mirrors EnvTrigger::forbids_flags). Default empty.

§requires_state: Vec<StateCompare>

Numeric gate terms (DSL v0.10, spec-0031): every listed comparison must hold for this gate to be open. The third field of the one gate, carried by every gate consumer — never by the verb that first wanted it. Default empty, so a pre-0.10 campaign is byte-identical.

Implementations§

Source§

impl Trap

Source

pub fn gate(&self) -> Gate<'_>

This trap’s whole gate, as one value (DSL v0.10).

Source§

impl Trap

Source

pub fn dispense(&self) -> Option<(&str, u32)>

(item, count) if this trap declares a legacy dispense effect.

Source

pub fn is_lethal(&self) -> bool

Whether this trap is lethal (carries the DW0342 obligation on the forced critical path).

Trait Implementations§

Source§

impl Clone for Trap

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 Debug for Trap

Source§

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

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

impl<'de> Deserialize<'de> for Trap

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Trap

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Trap

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Trap

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Trap

Auto Trait Implementations§

§

impl Freeze for Trap

§

impl RefUnwindSafe for Trap

§

impl Send for Trap

§

impl Sync for Trap

§

impl Unpin for Trap

§

impl UnsafeUnpin for Trap

§

impl UnwindSafe for Trap

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> 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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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