dpc/common/mc/
mod.rs

1pub mod block;
2pub mod entity;
3pub mod instr;
4pub mod item;
5pub mod modifier;
6pub mod pos;
7pub mod scoreboard_and_teams;
8pub mod time;
9
10use std::fmt::{Debug, Display};
11
12use crate::common::Identifier;
13
14use self::pos::IntCoordinates;
15
16use self::entity::TargetSelector;
17use super::ty::ArraySize;
18use super::ResourceLocation;
19
20#[derive(Clone, PartialEq)]
21pub enum EntityTarget {
22	Player(String),
23	Selector(TargetSelector),
24}
25
26impl EntityTarget {
27	pub fn is_blank_this(&self) -> bool {
28		matches!(self, EntityTarget::Selector(sel) if sel.is_blank_this())
29	}
30
31	pub fn is_value_eq(&self, other: &Self) -> bool {
32		matches!((self, other), (Self::Player(l), Self::Player(r)) if l == r)
33			|| matches!((self, other), (Self::Selector(l), Self::Selector(r)) if l.is_value_eq(r))
34	}
35
36	pub fn relies_on_position(&self) -> bool {
37		matches!(self, Self::Selector(tgt) if tgt.relies_on_position())
38	}
39
40	pub fn relies_on_executor(&self) -> bool {
41		matches!(self, Self::Selector(tgt) if tgt.relies_on_executor())
42	}
43}
44
45impl Debug for EntityTarget {
46	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47		match self {
48			Self::Player(player) => write!(f, "{player}"),
49			Self::Selector(sel) => write!(f, "{sel:?}"),
50		}
51	}
52}
53
54#[derive(Clone, PartialEq)]
55pub struct Score {
56	pub holder: EntityTarget,
57	pub objective: Identifier,
58}
59
60impl Score {
61	pub fn new(holder: EntityTarget, objective: Identifier) -> Self {
62		Self { holder, objective }
63	}
64
65	pub fn is_value_eq(&self, other: &Self) -> bool {
66		self.holder.is_value_eq(&other.holder) && self.objective == other.objective
67	}
68}
69
70impl Debug for Score {
71	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72		write!(f, "{:?} {}", self.holder, self.objective)
73	}
74}
75
76#[derive(Clone, PartialEq, Eq, Default)]
77pub enum DataPath {
78	#[default]
79	This,
80	String(String),
81	Access(Box<DataPath>, String),
82	Index(Box<DataPath>, ArraySize),
83}
84
85impl Debug for DataPath {
86	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87		match self {
88			Self::This => write!(f, "this"),
89			Self::String(string) => write!(f, "{string}"),
90			Self::Access(path, prop) => write!(f, "{path:?}.{prop}"),
91			Self::Index(path, idx) => write!(f, "{path:?}[{idx}]"),
92		}
93	}
94}
95
96#[derive(Debug, Clone, PartialEq)]
97pub enum DataLocation {
98	Block(IntCoordinates),
99	Entity(EntityTarget),
100	Storage(ResourceLocation),
101}
102
103impl DataLocation {
104	pub fn is_value_eq(&self, other: &Self) -> bool {
105		matches!((self, other), (Self::Block(l), Self::Block(r)) if l.is_value_eq(r))
106			|| matches!((self, other), (Self::Entity(l), Self::Entity(r)) if l.is_value_eq(r))
107			|| matches!((self, other), (Self::Storage(l), Self::Storage(r)) if l == r)
108	}
109}
110
111#[derive(Debug, Clone, PartialEq)]
112pub struct FullDataLocation {
113	pub loc: DataLocation,
114	pub path: DataPath,
115}
116
117impl FullDataLocation {
118	pub fn is_value_eq(&self, other: &Self) -> bool {
119		self.loc.is_value_eq(&other.loc) && self.path == other.path
120	}
121}
122
123#[derive(Debug, Clone, PartialEq, Eq)]
124pub enum XPValue {
125	Points,
126	Levels,
127}
128
129impl XPValue {
130	pub fn parse(string: &str) -> Option<Self> {
131		match string {
132			"points" => Some(Self::Points),
133			"levels" => Some(Self::Levels),
134			_ => None,
135		}
136	}
137}
138
139impl Display for XPValue {
140	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
141		write!(
142			f,
143			"{}",
144			match self {
145				Self::Points => "points",
146				Self::Levels => "levels",
147			}
148		)
149	}
150}
151
152#[derive(Debug, Clone, PartialEq, Eq)]
153pub enum Difficulty {
154	Peaceful,
155	Easy,
156	Normal,
157	Hard,
158}
159
160impl Display for Difficulty {
161	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
162		write!(
163			f,
164			"{}",
165			match self {
166				Self::Peaceful => "peaceful",
167				Self::Easy => "easy",
168				Self::Normal => "normal",
169				Self::Hard => "hard",
170			}
171		)
172	}
173}
174
175impl Difficulty {
176	pub fn parse(string: &str) -> Option<Self> {
177		match string {
178			"peaceful" => Some(Self::Peaceful),
179			"easy" => Some(Self::Easy),
180			"normal" => Some(Self::Normal),
181			"hard" => Some(Self::Hard),
182			_ => None,
183		}
184	}
185}
186
187#[derive(Debug, Clone, PartialEq, Eq)]
188pub enum Gamemode {
189	Survival,
190	Creative,
191	Adventure,
192	Spectator,
193}
194
195impl Display for Gamemode {
196	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
197		write!(
198			f,
199			"{}",
200			match self {
201				Self::Survival => "survival",
202				Self::Creative => "creative",
203				Self::Adventure => "adventure",
204				Self::Spectator => "spectator",
205			}
206		)
207	}
208}
209
210#[derive(Clone, PartialEq, Eq)]
211pub enum Heightmap {
212	WorldSurface,
213	MotionBlocking,
214	MotionBlockingNoLeaves,
215	OceanFloor,
216}
217
218impl Debug for Heightmap {
219	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
220		match self {
221			Self::WorldSurface => write!(f, "world_surface"),
222			Self::MotionBlocking => write!(f, "motion_blocking"),
223			Self::MotionBlockingNoLeaves => write!(f, "motion_blocking_no_leaves"),
224			Self::OceanFloor => write!(f, "ocean_floor"),
225		}
226	}
227}
228
229#[derive(Debug, Clone, PartialEq, Eq)]
230pub enum Weather {
231	Clear,
232	Rain,
233	Thunder,
234}
235
236impl Display for Weather {
237	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
238		write!(
239			f,
240			"{}",
241			match self {
242				Self::Clear => "clear",
243				Self::Rain => "rain",
244				Self::Thunder => "thunder",
245			}
246		)
247	}
248}
249
250#[derive(Clone, PartialEq, Eq)]
251pub enum DatapackPriority {
252	First,
253	Last,
254}
255
256impl Debug for DatapackPriority {
257	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
258		match self {
259			Self::First => write!(f, "first"),
260			Self::Last => write!(f, "last"),
261		}
262	}
263}
264
265#[derive(Clone, PartialEq, Eq)]
266pub enum DatapackOrder {
267	Before,
268	After,
269}
270
271impl Debug for DatapackOrder {
272	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
273		match self {
274			Self::Before => write!(f, "before"),
275			Self::After => write!(f, "after"),
276		}
277	}
278}
279
280#[derive(Clone, PartialEq, Eq)]
281pub enum DatapackListMode {
282	All,
283	Available,
284	Enabled,
285}
286
287impl Debug for DatapackListMode {
288	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
289		match self {
290			Self::All => write!(f, "all"),
291			Self::Available => write!(f, "available"),
292			Self::Enabled => write!(f, "enabled"),
293		}
294	}
295}
296
297#[derive(Clone, PartialEq, Eq)]
298pub enum Location {
299	Structure,
300	Biome,
301	POI,
302}
303
304impl Location {
305	pub fn parse(string: &str) -> Option<Self> {
306		match string {
307			"struct" => Some(Self::Structure),
308			"bio" => Some(Self::Biome),
309			"poi" => Some(Self::POI),
310			_ => None,
311		}
312	}
313}
314
315impl Debug for Location {
316	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
317		write!(
318			f,
319			"{}",
320			match self {
321				Self::Structure => "structure",
322				Self::Biome => "biome",
323				Self::POI => "poi",
324			}
325		)
326	}
327}
328
329#[derive(Clone, PartialEq, Eq)]
330pub enum SoundSource {
331	Master,
332	Music,
333	Record,
334	Weather,
335	Block,
336	Hostile,
337	Neutral,
338	Player,
339	Ambient,
340	Voice,
341}
342
343impl SoundSource {
344	pub fn parse(string: &str) -> Option<Self> {
345		match string {
346			"master" => Some(Self::Master),
347			"music" => Some(Self::Music),
348			"record" => Some(Self::Record),
349			"weather" => Some(Self::Weather),
350			"block" => Some(Self::Block),
351			"hostile" => Some(Self::Hostile),
352			"neutral" => Some(Self::Neutral),
353			"player" => Some(Self::Player),
354			"ambient" => Some(Self::Ambient),
355			"voice" => Some(Self::Voice),
356			_ => None,
357		}
358	}
359}
360
361impl Debug for SoundSource {
362	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
363		write!(
364			f,
365			"{}",
366			match self {
367				Self::Master => "master",
368				Self::Music => "music",
369				Self::Record => "record",
370				Self::Weather => "weather",
371				Self::Block => "block",
372				Self::Hostile => "hostile",
373				Self::Neutral => "neutral",
374				Self::Player => "player",
375				Self::Ambient => "ambient",
376				Self::Voice => "voice",
377			}
378		)
379	}
380}