Struct MerchantRef
pub struct MerchantRef(/* private fields */);Expand description
A villager or wandering trader (vanilla’s AbstractVillager, a Merchant),
narrowed from an entity with host.merchant(entity). If a villager’s saved
profession is unresolved, offers read empty and merchant mutations are
refused until its profession is available again; saved offers are retained.
Implementations§
§impl MerchantRef
impl MerchantRef
pub fn offers(self, host: &dyn Host) -> Option<Vec<MerchantOffer>>
pub fn offers(self, host: &dyn Host) -> Option<Vec<MerchantOffer>>
Side: server.
AbstractVillager.getOffers, as they are now (a copy). Offers not
rolled yet read as empty: they are rolled when a player first trades,
or by add_offer; reading never draws a random.
In a mob’s goal tick (GoalContext::host) this reads
the active mob or a disjoint live mob when available; player reads use the
game host. Other unsupported reads retain their typed refusal.
pub fn trading_player(self, host: &dyn Host) -> Option<PlayerRef>
pub fn trading_player(self, host: &dyn Host) -> Option<PlayerRef>
Side: server.
Merchant.getTradingPlayer: the player whose trading screen is open on
it. None when nobody trades, or the screen is the host window’s.
In a mob’s goal tick (GoalContext::host) this reads
the active mob or a disjoint live mob when available; player reads use the
game host. Other unsupported reads retain their typed refusal.
pub fn profession(self, host: &dyn Host) -> Option<String>
pub fn profession(self, host: &dyn Host) -> Option<String>
Side: server.
VillagerData.profession, a registry id (minecraft:farmer; none is
minecraft:none). None for a wandering trader.
In a mob’s goal tick (GoalContext::host) this reads
the active mob or a disjoint live mob when available; player reads use the
game host. Other unsupported reads retain their typed refusal.
pub fn level(self, host: &dyn Host) -> Option<i32>
pub fn level(self, host: &dyn Host) -> Option<i32>
Side: server.
VillagerData.level, at least 1.
In a mob’s goal tick (GoalContext::host) this reads
the active mob or a disjoint live mob when available; player reads use the
game host. Other unsupported reads retain their typed refusal.
pub fn villager_type(self, host: &dyn Host) -> Option<String>
pub fn villager_type(self, host: &dyn Host) -> Option<String>
Side: server.
VillagerData.type, a registry id (minecraft:plains).
In a mob’s goal tick (GoalContext::host) this reads
the active mob or a disjoint live mob when available; player reads use the
game host. Other unsupported reads retain their typed refusal.
pub fn xp(self, host: &dyn Host) -> Option<i32>
pub fn xp(self, host: &dyn Host) -> Option<i32>
Side: server.
Villager.getVillagerXp.
In a mob’s goal tick (GoalContext::host) this reads
the active mob or a disjoint live mob when available; player reads use the
game host. Other unsupported reads retain their typed refusal.
pub fn set_offer(
self,
host: &mut dyn ServerHost,
index: u32,
offer: MerchantOffer,
) -> Result<bool, StackWriteError>
pub fn set_offer( self, host: &mut dyn ServerHost, index: u32, offer: MerchantOffer, ) -> Result<bool, StackWriteError>
Side: server.
Replaces offer index (a player trading with it is sent the new
offers). False for an index past the end, a stale handle, or an offer
without a real item in base_cost_a or result (or cost_b when set).
An invalid count, damage or component maximum refuses the whole write with a typed error.
pub fn add_offer(
self,
host: &mut dyn ServerHost,
offer: MerchantOffer,
) -> Result<bool, StackWriteError>
pub fn add_offer( self, host: &mut dyn ServerHost, offer: MerchantOffer, ) -> Result<bool, StackWriteError>
Side: server.
Appends an offer, as getOffers().add(offer) does. Offers not rolled
yet are rolled first, as getOffers does for a player’s first trade
(this draws the trade set’s world random sequence, as that does).
False for a stale handle or an invalid offer (see set_offer).
pub fn remove_offer(self, host: &mut dyn ServerHost, index: u32) -> bool
pub fn remove_offer(self, host: &mut dyn ServerHost, index: u32) -> bool
Side: server.
Removes offer index, the ones after it moving up. False for an index
past the end or a stale handle.
pub fn set_profession(self, host: &mut dyn ServerHost, profession: &str) -> bool
pub fn set_profession(self, host: &mut dyn ServerHost, profession: &str) -> bool
Side: server.
Villager.setVillagerData with a new profession: a different one
forgets the offers, which roll again on the next trade. Clients see the
new profession through entity data. False for an unknown id, a wandering
trader, or a villager with a trading screen open.
pub fn set_level(self, host: &mut dyn ServerHost, level: i32) -> bool
pub fn set_level(self, host: &mut dyn ServerHost, level: i32) -> bool
Side: server.
VillagerData.withLevel: Math.max(1, level), with no upper limit in
vanilla. The offers stay as they are; the next level-up adds its trades
(a level past 5 can’t level up). A trading guest’s session follows,
and gets the sequences a level-up from the new level needs.
pub fn set_villager_type(self, host: &mut dyn ServerHost, kind: &str) -> bool
pub fn set_villager_type(self, host: &mut dyn ServerHost, kind: &str) -> bool
Side: server.
VillagerData.withType: also the type a trading guest’s session
rolls its next level-up offers with. False for an unknown id, a
wandering trader, or a trade open where this can’t reach.
pub fn set_xp(self, host: &mut dyn ServerHost, xp: i32) -> bool
pub fn set_xp(self, host: &mut dyn ServerHost, xp: i32) -> bool
Side: server.
Villager.setVillagerXp: assigned as given, as vanilla does.
§impl MerchantRef
impl MerchantRef
Trait Implementations§
§impl Clone for MerchantRef
impl Clone for MerchantRef
§fn clone(&self) -> MerchantRef
fn clone(&self) -> MerchantRef
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more