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— adispensepayload the prefab’s own redstone fires — needs the anchor’sdispensersocket 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’strigger_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: TrapIdUnique trap id (trap/<kebab>).
at: AnchorIdThe 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: TrapTriggerWhat 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: LethalityHow 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: TrapResetWhether 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§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Trap
impl<'de> Deserialize<'de> for Trap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for Trap
impl JsonSchema for Trap
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more