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)> {
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    ) -> bool {
217        Default::default()
218    }
219    fn player_inventory(&self, player: &str) -> Vec<(u32, String, u32)> {
220        Default::default()
221    }
222    fn player_set_slot(&self, player: &str, slot: u32, item_id: &str, count: u32) -> bool {
223        Default::default()
224    }
225    fn teleport_to_dim(&self, player: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
226        Default::default()
227    }
228    fn entity_teleport_to_dim(&self, uuid: &str, dimension: &str, x: f64, y: f64, z: f64) -> bool {
229        Default::default()
230    }
231    fn world_entity_count(&self, dimension: &str, entity_type: &str) -> i32 {
232        Default::default()
233    }
234    fn entity_get_nbt(&self, uuid: &str) -> Option<String> {
235        Default::default()
236    }
237    fn entity_set_nbt(&self, uuid: &str, snbt: &str) -> bool {
238        Default::default()
239    }
240    fn spawn_particles(
241        &self,
242        dimension: &str,
243        x: f64,
244        y: f64,
245        z: f64,
246        particle_type: &str,
247        count: i32,
248        dx: f64,
249        dy: f64,
250        dz: f64,
251        speed: f64,
252    ) -> bool {
253        Default::default()
254    }
255    fn entity_attribute_get(&self, uuid: &str, attribute_id: &str) -> Option<f64> {
256        Default::default()
257    }
258    fn entity_attribute_set(&self, uuid: &str, attribute_id: &str, value: f64) -> bool {
259        Default::default()
260    }
261    fn get_held_item_nbt(&self, player: &str) -> Option<String> {
262        Default::default()
263    }
264    fn set_held_item_nbt(&self, player: &str, snbt: &str) -> bool {
265        Default::default()
266    }
267    fn get_offhand_item_nbt(&self, player: &str) -> Option<String> {
268        Default::default()
269    }
270    fn set_offhand_item_nbt(&self, player: &str, snbt: &str) -> bool {
271        Default::default()
272    }
273    fn get_slot_item(&self, player: &str, slot: u32) -> Option<(String, u32, String)> {
274        Default::default()
275    }
276    fn set_slot_item(
277        &self,
278        player: &str,
279        slot: u32,
280        item_id: &str,
281        count: u32,
282        snbt: &str,
283    ) -> bool {
284        Default::default()
285    }
286    fn entity_info(&self, uuid: &str) -> Option<EntityInfo> {
287        Default::default()
288    }
289    fn entities_in_box(
290        &self,
291        dimension: &str,
292        min: (f64, f64, f64),
293        max: (f64, f64, f64),
294    ) -> Vec<String> {
295        Default::default()
296    }
297    fn raycast_block(
298        &self,
299        dimension: &str,
300        from: (f64, f64, f64),
301        to: (f64, f64, f64),
302    ) -> Option<BlockHit> {
303        Default::default()
304    }
305    fn raycast_entity(
306        &self,
307        dimension: &str,
308        from: (f64, f64, f64),
309        to: (f64, f64, f64),
310        exclude: &str,
311    ) -> Option<String> {
312        Default::default()
313    }
314    fn block_info(&self, dimension: &str, pos: BlockPos) -> Option<BlockInfo> {
315        Default::default()
316    }
317    fn break_block(&self, dimension: &str, pos: BlockPos, drop: bool, breaker: &str) -> bool {
318        Default::default()
319    }
320    fn place_block_from_slot(
321        &self,
322        player: &str,
323        slot: u32,
324        dimension: &str,
325        pos: BlockPos,
326    ) -> bool {
327        Default::default()
328    }
329    fn bonemeal(&self, dimension: &str, pos: BlockPos) -> bool {
330        Default::default()
331    }
332    fn explode(
333        &self,
334        dimension: &str,
335        x: f64,
336        y: f64,
337        z: f64,
338        power: f32,
339        fire: bool,
340        source: &str,
341    ) -> bool {
342        Default::default()
343    }
344    fn tellraw(&self, player: &str, json: &str) -> bool {
345        Default::default()
346    }
347    fn entity_damage(&self, uuid: &str, amount: f32, damage_type: &str, attacker: &str) -> bool {
348        Default::default()
349    }
350    fn entity_set_fire_ticks(&self, uuid: &str, ticks: i32) -> bool {
351        Default::default()
352    }
353    fn player_add_xp(&self, player: &str, amount: i32) -> bool {
354        Default::default()
355    }
356    fn player_set_may_fly(&self, player: &str, may_fly: bool) -> bool {
357        Default::default()
358    }
359    fn player_info(&self, player: &str) -> Option<PlayerInfo> {
360        Default::default()
361    }
362    fn spawn_item(
363        &self,
364        dimension: &str,
365        pos: (f64, f64, f64),
366        vel: (f64, f64, f64),
367        item_id: &str,
368        count: u32,
369        snbt: &str,
370    ) -> Option<String> {
371        Default::default()
372    }
373    fn item_entity_stack(&self, uuid: &str) -> Option<(String, u32, String)> {
374        Default::default()
375    }
376    fn item_entity_set_stack(&self, uuid: &str, item_id: &str, count: u32, snbt: &str) -> bool {
377        Default::default()
378    }
379    fn actionbar_json(&self, player: &str, json: &str) -> bool {
380        Default::default()
381    }
382    fn use_item_on_block(
383        &self,
384        dimension: &str,
385        pos: BlockPos,
386        face: Face,
387        item_id: &str,
388        player: &str,
389    ) -> bool {
390        Default::default()
391    }
392    fn pour_fluid(&self, dimension: &str, pos: BlockPos, bucket_item_id: &str) -> bool {
393        Default::default()
394    }
395    fn has_entity_tag(&self, entity_type: &str, tag_id: &str) -> bool {
396        Default::default()
397    }
398    fn item_block(&self, item_id: &str) -> Option<String> {
399        Default::default()
400    }
401    fn place_feature(&self, dimension: &str, pos: BlockPos, feature_id: &str) -> bool {
402        Default::default()
403    }
404}