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
193    fn world_dir(&self) -> String {
194        self.game_dir.clone()
195    }
196    fn online_players(&self) -> Vec<String> {
197        Default::default()
198    }
199    fn get_block_nbt(&self, dimension: &str, pos: BlockPos) -> Option<String> {
200        Default::default()
201    }
202    fn set_block_nbt(&self, dimension: &str, pos: BlockPos, snbt: &str) -> bool {
203        Default::default()
204    }
205    fn get_inventory_slot(
206        &self,
207        dimension: &str,
208        pos: BlockPos,
209        slot: u32,
210    ) -> Option<(String, u32, String)> {
211        Default::default()
212    }
213    fn set_inventory_slot(
214        &self,
215        dimension: &str,
216        pos: BlockPos,
217        slot: u32,
218        item_id: &str,
219        count: u32,
220        snbt: &str,
221    ) -> bool {
222        Default::default()
223    }
224    fn player_inventory(&self, player: &str) -> Vec<(u32, String, u32)> {
225        Default::default()
226    }
227    fn player_set_slot(&self, player: &str, slot: u32, item_id: &str, count: u32) -> bool {
228        Default::default()
229    }
230    fn teleport_to_dim(&self, player: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
231        Default::default()
232    }
233    fn entity_teleport_to_dim(&self, uuid: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
234        Default::default()
235    }
236    fn world_entity_count(&self, dimension: &str, entity_type: &str) -> i32 {
237        Default::default()
238    }
239    fn entity_get_nbt(&self, uuid: &str) -> Option<String> {
240        Default::default()
241    }
242    fn entity_set_nbt(&self, uuid: &str, snbt: &str) -> bool {
243        Default::default()
244    }
245    fn spawn_particles(
246        &self,
247        dimension: &str,
248        x: f64,
249        y: f64,
250        z: f64,
251        particle_type: &str,
252        count: i32,
253        dx: f64,
254        dy: f64,
255        dz: f64,
256        speed: f64,
257    ) -> bool {
258        Default::default()
259    }
260    fn entity_attribute_get(&self, uuid: &str, attribute_id: &str) -> Option<f64> {
261        Default::default()
262    }
263    fn entity_attribute_set(&self, uuid: &str, attribute_id: &str, value: f64) -> bool {
264        Default::default()
265    }
266    fn get_held_item_nbt(&self, player: &str) -> Option<String> {
267        Default::default()
268    }
269    fn set_held_item_nbt(&self, player: &str, snbt: &str) -> bool {
270        Default::default()
271    }
272    fn get_offhand_item_nbt(&self, player: &str) -> Option<String> {
273        Default::default()
274    }
275    fn set_offhand_item_nbt(&self, player: &str, snbt: &str) -> bool {
276        Default::default()
277    }
278    fn get_slot_item(&self, player: &str, slot: u32) -> Option<(String, u32, String)> {
279        Default::default()
280    }
281    fn set_slot_item(
282        &self,
283        player: &str,
284        slot: u32,
285        item_id: &str,
286        count: u32,
287        snbt: &str,
288    ) -> bool {
289        Default::default()
290    }
291    fn entity_info(&self, uuid: &str) -> Option<EntityInfo> {
292        Default::default()
293    }
294    fn entities_in_box(
295        &self,
296        dimension: &str,
297        min: (f64, f64, f64),
298        max: (f64, f64, f64),
299    ) -> Vec<String> {
300        Default::default()
301    }
302    fn raycast_block(
303        &self,
304        dimension: &str,
305        from: (f64, f64, f64),
306        to: (f64, f64, f64),
307    ) -> Option<BlockHit> {
308        Default::default()
309    }
310    fn raycast_entity(
311        &self,
312        dimension: &str,
313        from: (f64, f64, f64),
314        to: (f64, f64, f64),
315        exclude: &str,
316    ) -> Option<String> {
317        Default::default()
318    }
319    fn block_info(&self, dimension: &str, pos: BlockPos) -> Option<BlockInfo> {
320        Default::default()
321    }
322    fn break_block(&self, dimension: &str, pos: BlockPos, drop: bool, breaker: &str) -> bool {
323        Default::default()
324    }
325    fn place_block_from_slot(
326        &self,
327        player: &str,
328        slot: u32,
329        dimension: &str,
330        pos: BlockPos,
331    ) -> bool {
332        Default::default()
333    }
334    fn bonemeal(&self, dimension: &str, pos: BlockPos) -> bool {
335        Default::default()
336    }
337    fn explode(
338        &self,
339        dimension: &str,
340        x: f64,
341        y: f64,
342        z: f64,
343        power: f32,
344        fire: bool,
345        source: &str,
346    ) -> bool {
347        Default::default()
348    }
349    fn tellraw(&self, player: &str, json: &str) -> bool {
350        Default::default()
351    }
352    fn entity_damage(&self, uuid: &str, amount: f32, damage_type: &str, attacker: &str) -> bool {
353        Default::default()
354    }
355    fn entity_set_fire_ticks(&self, uuid: &str, ticks: i32) -> bool {
356        Default::default()
357    }
358    fn player_add_xp(&self, player: &str, amount: i32) -> bool {
359        Default::default()
360    }
361    fn player_set_may_fly(&self, player: &str, may_fly: bool) -> bool {
362        Default::default()
363    }
364    fn player_info(&self, player: &str) -> Option<PlayerInfo> {
365        Default::default()
366    }
367    fn spawn_item(
368        &self,
369        dimension: &str,
370        pos: (f64, f64, f64),
371        vel: (f64, f64, f64),
372        item_id: &str,
373        count: u32,
374        snbt: &str,
375    ) -> Option<String> {
376        Default::default()
377    }
378    fn item_entity_stack(&self, uuid: &str) -> Option<(String, u32, String)> {
379        Default::default()
380    }
381    fn item_entity_set_stack(&self, uuid: &str, item_id: &str, count: u32, snbt: &str) -> bool {
382        Default::default()
383    }
384    fn actionbar_json(&self, player: &str, json: &str) -> bool {
385        Default::default()
386    }
387    fn use_item_on_block(
388        &self,
389        dimension: &str,
390        pos: BlockPos,
391        face: Face,
392        item_id: &str,
393        player: &str,
394    ) -> bool {
395        Default::default()
396    }
397    fn pour_fluid(&self, dimension: &str, pos: BlockPos, bucket_item_id: &str) -> bool {
398        Default::default()
399    }
400    fn has_entity_tag(&self, entity_type: &str, tag_id: &str) -> bool {
401        Default::default()
402    }
403    fn item_block(&self, item_id: &str) -> Option<String> {
404        Default::default()
405    }
406    fn place_feature(&self, dimension: &str, pos: BlockPos, feature_id: &str) -> bool {
407        Default::default()
408    }
409    fn set_item_cooldown(&self, player: &str, item_id: &str, ticks: u32) -> bool {
410        Default::default()
411    }
412    fn entity_vehicle(&self, uuid: &str) -> Option<String> {
413        Default::default()
414    }
415    fn entity_passengers(&self, uuid: &str) -> Vec<String> {
416        Default::default()
417    }
418    fn entity_mount(&self, rider: &str, vehicle: &str, force: bool) -> bool {
419        Default::default()
420    }
421    fn entity_dismount(&self, uuid: &str) -> bool {
422        Default::default()
423    }
424    fn entity_data(&self, uuid: &str, key: &str) -> Option<Vec<u8>> {
425        Default::default()
426    }
427    fn set_entity_data(&self, uuid: &str, key: &str, value: Option<&[u8]>, persist: bool) -> bool {
428        Default::default()
429    }
430    fn entity_set_dimensions(&self, uuid: &str, size: Option<(f32, f32, f32)>) -> bool {
431        Default::default()
432    }
433    fn entity_set_fall_distance(&self, uuid: &str, distance: f32) -> bool {
434        Default::default()
435    }
436    fn redstone_signal(&self, dimension: &str, pos: BlockPos) -> Option<u8> {
437        Default::default()
438    }
439    fn redstone_power(&self, dimension: &str, pos: BlockPos) -> Option<u8> {
440        Default::default()
441    }
442    fn set_redstone_output(&self, dimension: &str, pos: BlockPos, level: u8) -> bool {
443        Default::default()
444    }
445    fn get_block_state(&self, dimension: &str, pos: BlockPos) -> Option<String> {
446        Default::default()
447    }
448    fn set_block_state(&self, dimension: &str, pos: BlockPos, state: &str) -> bool {
449        Default::default()
450    }
451    fn world_is_thundering(&self, dimension: &str) -> bool {
452        Default::default()
453    }
454    fn world_set_thunder(&self, dimension: &str, thundering: bool, duration_ticks: i32) -> bool {
455        Default::default()
456    }
457    fn fill_region(&self, dimension: &str, from: BlockPos, to: BlockPos, state: &str) -> Option<u32> {
458        Default::default()
459    }
460    fn scan_region(&self, dimension: &str, from: BlockPos, to: BlockPos) -> Vec<(BlockPos, String)> {
461        Default::default()
462    }
463}