Skip to main content

yog_core/
null_server.rs

1//! [`NullServer`] — a [`Server`] with no game behind it, for benchmarks and
2//! tests of a mod's own logic.
3
4use crate::{BlockHit, BlockInfo, BlockPos, EntityInfo, Face, PlayerInfo, Server};
5
6/// A [`Server`] that does nothing: every query comes back empty, every
7/// action reports failure. Enough to run mod logic that only needs a handle
8/// (`yog bench` benchmarks, unit tests). `game_dir` is where the mod's
9/// storage goes — point it at a scratch directory.
10#[derive(Debug, Clone, Default)]
11pub struct NullServer {
12    pub game_dir: String,
13}
14
15impl NullServer {
16    /// A null server whose game directory is `dir`.
17    pub fn new(dir: impl Into<String>) -> Self {
18        Self {
19            game_dir: dir.into(),
20        }
21    }
22}
23
24#[allow(unused_variables)]
25impl Server for NullServer {
26    fn broadcast(&self, message: &str) {
27        Default::default()
28    }
29    fn get_block(&self, dimension: &str, pos: BlockPos) -> Option<String> {
30        Default::default()
31    }
32    fn set_block(&self, dimension: &str, pos: BlockPos, block_id: &str) -> bool {
33        Default::default()
34    }
35    fn give_item(&self, player: &str, item_id: &str, count: u32) -> bool {
36        Default::default()
37    }
38    fn teleport(&self, player: &str, x: f64, y: f64, z: f64) -> bool {
39        Default::default()
40    }
41    fn send_to_player(&self, player: &str, channel: &str, payload: &[u8]) -> bool {
42        Default::default()
43    }
44    fn send_to_server(&self, channel: &str, payload: &[u8]) -> bool {
45        Default::default()
46    }
47    fn entity_teleport(&self, uuid: &str, x: f64, y: f64, z: f64) -> bool {
48        Default::default()
49    }
50    fn entity_position(&self, uuid: &str) -> Option<(f64, f64, f64)> {
51        Default::default()
52    }
53    fn entity_health(&self, uuid: &str) -> Option<f32> {
54        Default::default()
55    }
56    fn entity_set_health(&self, uuid: &str, health: f32) -> bool {
57        Default::default()
58    }
59    fn entity_kill(&self, uuid: &str) -> bool {
60        Default::default()
61    }
62    fn spawn_entity(
63        &self,
64        entity_type: &str,
65        dimension: &str,
66        x: f64,
67        y: f64,
68        z: f64,
69    ) -> Option<String> {
70        Default::default()
71    }
72    fn entity_add_effect(
73        &self,
74        uuid: &str,
75        effect_id: &str,
76        duration_ticks: i32,
77        amplifier: u8,
78        show_particles: bool,
79    ) -> bool {
80        Default::default()
81    }
82    fn entity_remove_effect(&self, uuid: &str, effect_id: &str) -> bool {
83        Default::default()
84    }
85    fn entity_clear_effects(&self, uuid: &str) -> bool {
86        Default::default()
87    }
88    fn drop_loot(&self, table_id: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
89        Default::default()
90    }
91    fn has_item_tag(&self, item_id: &str, tag_id: &str) -> bool {
92        Default::default()
93    }
94    fn has_block_tag(&self, block_id: &str, tag_id: &str) -> bool {
95        Default::default()
96    }
97    fn world_time(&self, dimension: &str) -> Option<i64> {
98        Default::default()
99    }
100    fn world_set_time(&self, dimension: &str, time: i64) -> bool {
101        Default::default()
102    }
103    fn world_is_raining(&self, dimension: &str) -> bool {
104        Default::default()
105    }
106    fn world_set_weather(&self, dimension: &str, raining: bool, duration_ticks: i32) -> bool {
107        Default::default()
108    }
109    fn entity_velocity(&self, uuid: &str) -> Option<(f64, f64, f64)> {
110        Default::default()
111    }
112    fn entity_set_velocity(&self, uuid: &str, vx: f64, vy: f64, vz: f64) -> bool {
113        Default::default()
114    }
115    fn entity_add_velocity(&self, uuid: &str, vx: f64, vy: f64, vz: f64) -> bool {
116        Default::default()
117    }
118    fn scoreboard_get(&self, objective: &str, player: &str) -> Option<i32> {
119        Default::default()
120    }
121    fn scoreboard_set(&self, objective: &str, player: &str, score: i32) -> bool {
122        Default::default()
123    }
124    fn scoreboard_add(&self, objective: &str, player: &str, delta: i32) -> Option<i32> {
125        Default::default()
126    }
127    fn play_sound(
128        &self,
129        dimension: &str,
130        x: f64,
131        y: f64,
132        z: f64,
133        sound_id: &str,
134        volume: f32,
135        pitch: f32,
136    ) -> bool {
137        Default::default()
138    }
139    fn play_sound_to_player(&self, player: &str, sound_id: &str, volume: f32, pitch: f32) -> bool {
140        Default::default()
141    }
142    fn send_title(
143        &self,
144        player: &str,
145        title: &str,
146        subtitle: &str,
147        fadein: i32,
148        stay: i32,
149        fadeout: i32,
150    ) -> bool {
151        Default::default()
152    }
153    fn send_actionbar(&self, player: &str, message: &str) -> bool {
154        Default::default()
155    }
156    fn entity_rotation(&self, uuid: &str) -> Option<(f32, f32)> {
157        Default::default()
158    }
159    fn kick_player(&self, player: &str, reason: &str) -> bool {
160        Default::default()
161    }
162    fn set_gamemode(&self, player: &str, gamemode: &str) -> bool {
163        Default::default()
164    }
165    fn bossbar_create(&self, id: &str, title: &str, color: &str, style: &str) -> bool {
166        Default::default()
167    }
168    fn bossbar_remove(&self, id: &str) -> bool {
169        Default::default()
170    }
171    fn bossbar_set_title(&self, id: &str, title: &str) -> bool {
172        Default::default()
173    }
174    fn bossbar_set_progress(&self, id: &str, progress: f32) -> bool {
175        Default::default()
176    }
177    fn bossbar_set_color(&self, id: &str, color: &str) -> bool {
178        Default::default()
179    }
180    fn bossbar_add_player(&self, id: &str, player: &str) -> bool {
181        Default::default()
182    }
183    fn bossbar_remove_player(&self, id: &str, player: &str) -> bool {
184        Default::default()
185    }
186    fn bossbar_set_visible(&self, id: &str, visible: bool) -> bool {
187        Default::default()
188    }
189    fn game_dir(&self) -> String {
190        self.game_dir.clone()
191    }
192    fn online_players(&self) -> Vec<String> {
193        Default::default()
194    }
195    fn get_block_nbt(&self, dimension: &str, pos: BlockPos) -> Option<String> {
196        Default::default()
197    }
198    fn set_block_nbt(&self, dimension: &str, pos: BlockPos, snbt: &str) -> bool {
199        Default::default()
200    }
201    fn get_inventory_slot(
202        &self,
203        dimension: &str,
204        pos: BlockPos,
205        slot: u32,
206    ) -> Option<(String, u32, String)> {
207        Default::default()
208    }
209    fn set_inventory_slot(
210        &self,
211        dimension: &str,
212        pos: BlockPos,
213        slot: u32,
214        item_id: &str,
215        count: u32,
216        snbt: &str,
217    ) -> bool {
218        Default::default()
219    }
220    fn player_inventory(&self, player: &str) -> Vec<(u32, String, u32)> {
221        Default::default()
222    }
223    fn player_set_slot(&self, player: &str, slot: u32, item_id: &str, count: u32) -> bool {
224        Default::default()
225    }
226    fn teleport_to_dim(&self, player: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
227        Default::default()
228    }
229    fn entity_teleport_to_dim(&self, uuid: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
230        Default::default()
231    }
232    fn world_entity_count(&self, dimension: &str, entity_type: &str) -> i32 {
233        Default::default()
234    }
235    fn entity_get_nbt(&self, uuid: &str) -> Option<String> {
236        Default::default()
237    }
238    fn entity_set_nbt(&self, uuid: &str, snbt: &str) -> bool {
239        Default::default()
240    }
241    fn spawn_particles(
242        &self,
243        dimension: &str,
244        x: f64,
245        y: f64,
246        z: f64,
247        particle_type: &str,
248        count: i32,
249        dx: f64,
250        dy: f64,
251        dz: f64,
252        speed: f64,
253    ) -> bool {
254        Default::default()
255    }
256    fn entity_attribute_get(&self, uuid: &str, attribute_id: &str) -> Option<f64> {
257        Default::default()
258    }
259    fn entity_attribute_set(&self, uuid: &str, attribute_id: &str, value: f64) -> bool {
260        Default::default()
261    }
262    fn get_held_item_nbt(&self, player: &str) -> Option<String> {
263        Default::default()
264    }
265    fn set_held_item_nbt(&self, player: &str, snbt: &str) -> bool {
266        Default::default()
267    }
268    fn get_offhand_item_nbt(&self, player: &str) -> Option<String> {
269        Default::default()
270    }
271    fn set_offhand_item_nbt(&self, player: &str, snbt: &str) -> bool {
272        Default::default()
273    }
274    fn get_slot_item(&self, player: &str, slot: u32) -> Option<(String, u32, String)> {
275        Default::default()
276    }
277    fn set_slot_item(
278        &self,
279        player: &str,
280        slot: u32,
281        item_id: &str,
282        count: u32,
283        snbt: &str,
284    ) -> bool {
285        Default::default()
286    }
287    fn entity_info(&self, uuid: &str) -> Option<EntityInfo> {
288        Default::default()
289    }
290    fn entities_in_box(
291        &self,
292        dimension: &str,
293        min: (f64, f64, f64),
294        max: (f64, f64, f64),
295    ) -> Vec<String> {
296        Default::default()
297    }
298    fn raycast_block(
299        &self,
300        dimension: &str,
301        from: (f64, f64, f64),
302        to: (f64, f64, f64),
303    ) -> Option<BlockHit> {
304        Default::default()
305    }
306    fn raycast_entity(
307        &self,
308        dimension: &str,
309        from: (f64, f64, f64),
310        to: (f64, f64, f64),
311        exclude: &str,
312    ) -> Option<String> {
313        Default::default()
314    }
315    fn block_info(&self, dimension: &str, pos: BlockPos) -> Option<BlockInfo> {
316        Default::default()
317    }
318    fn break_block(&self, dimension: &str, pos: BlockPos, drop: bool, breaker: &str) -> bool {
319        Default::default()
320    }
321    fn place_block_from_slot(
322        &self,
323        player: &str,
324        slot: u32,
325        dimension: &str,
326        pos: BlockPos,
327    ) -> bool {
328        Default::default()
329    }
330    fn bonemeal(&self, dimension: &str, pos: BlockPos) -> bool {
331        Default::default()
332    }
333    fn explode(
334        &self,
335        dimension: &str,
336        x: f64,
337        y: f64,
338        z: f64,
339        power: f32,
340        fire: bool,
341        source: &str,
342    ) -> bool {
343        Default::default()
344    }
345    fn tellraw(&self, player: &str, json: &str) -> bool {
346        Default::default()
347    }
348    fn entity_damage(&self, uuid: &str, amount: f32, damage_type: &str, attacker: &str) -> bool {
349        Default::default()
350    }
351    fn entity_set_fire_ticks(&self, uuid: &str, ticks: i32) -> bool {
352        Default::default()
353    }
354    fn player_add_xp(&self, player: &str, amount: i32) -> bool {
355        Default::default()
356    }
357    fn player_set_may_fly(&self, player: &str, may_fly: bool) -> bool {
358        Default::default()
359    }
360    fn player_info(&self, player: &str) -> Option<PlayerInfo> {
361        Default::default()
362    }
363    fn spawn_item(
364        &self,
365        dimension: &str,
366        pos: (f64, f64, f64),
367        vel: (f64, f64, f64),
368        item_id: &str,
369        count: u32,
370        snbt: &str,
371    ) -> Option<String> {
372        Default::default()
373    }
374    fn item_entity_stack(&self, uuid: &str) -> Option<(String, u32, String)> {
375        Default::default()
376    }
377    fn item_entity_set_stack(&self, uuid: &str, item_id: &str, count: u32, snbt: &str) -> bool {
378        Default::default()
379    }
380    fn actionbar_json(&self, player: &str, json: &str) -> bool {
381        Default::default()
382    }
383    fn use_item_on_block(
384        &self,
385        dimension: &str,
386        pos: BlockPos,
387        face: Face,
388        item_id: &str,
389        player: &str,
390    ) -> bool {
391        Default::default()
392    }
393    fn pour_fluid(&self, dimension: &str, pos: BlockPos, bucket_item_id: &str) -> bool {
394        Default::default()
395    }
396    fn has_entity_tag(&self, entity_type: &str, tag_id: &str) -> bool {
397        Default::default()
398    }
399    fn item_block(&self, item_id: &str) -> Option<String> {
400        Default::default()
401    }
402    fn place_feature(&self, dimension: &str, pos: BlockPos, feature_id: &str) -> bool {
403        Default::default()
404    }
405    fn set_item_cooldown(&self, player: &str, item_id: &str, ticks: u32) -> bool {
406        Default::default()
407    }
408    fn entity_teleport_with_passengers(&self, uuid: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
409        Default::default()
410    }
411    fn redstone_power(&self, dimension: &str, pos: BlockPos) -> Option<u8> {
412        Default::default()
413    }
414    fn set_redstone_output(&self, dimension: &str, pos: BlockPos, level: u8) -> bool {
415        Default::default()
416    }
417    fn get_block_state(&self, dimension: &str, pos: BlockPos) -> Option<String> {
418        Default::default()
419    }
420    fn set_block_state(&self, dimension: &str, pos: BlockPos, state: &str) -> bool {
421        Default::default()
422    }
423    fn world_is_thundering(&self, dimension: &str) -> bool {
424        Default::default()
425    }
426    fn world_set_thunder(&self, dimension: &str, thundering: bool, duration_ticks: i32) -> bool {
427        Default::default()
428    }
429    fn fill_region(&self, dimension: &str, from: BlockPos, to: BlockPos, state: &str) -> Option<u32> {
430        Default::default()
431    }
432    fn scan_region(&self, dimension: &str, from: BlockPos, to: BlockPos) -> Vec<(BlockPos, String)> {
433        Default::default()
434    }
435}