1use std::os::raw::c_void;
13
14pub const ABI_MAJOR: u32 = 3;
17pub const ABI_MINOR: u32 = 3;
18pub const ABI_VERSION: u32 = ABI_MAJOR * 10_000 + ABI_MINOR;
20
21#[repr(C)]
26#[derive(Copy, Clone)]
27pub struct YogStr {
28 pub ptr: *const u8,
29 pub len: u32,
30}
31
32impl YogStr {
33 pub const EMPTY: Self = Self {
34 ptr: std::ptr::null(),
35 len: 0,
36 };
37
38 #[allow(clippy::should_implement_trait)]
40 #[inline]
41 pub fn from_str(s: &str) -> Self {
42 Self {
43 ptr: s.as_ptr(),
44 len: s.len() as u32,
45 }
46 }
47
48 #[inline]
49 pub fn is_empty(self) -> bool {
50 self.len == 0 || self.ptr.is_null()
51 }
52
53 #[inline]
58 pub unsafe fn as_str<'a>(self) -> &'a str {
59 unsafe {
60 if self.ptr.is_null() || self.len == 0 {
61 return "";
62 }
63 std::str::from_utf8_unchecked(std::slice::from_raw_parts(self.ptr, self.len as usize))
64 }
65 }
66}
67
68#[repr(C)]
72#[derive(Copy, Clone)]
73pub struct YogOwnedStr {
74 pub ptr: *mut u8,
75 pub len: u32,
76}
77
78impl YogOwnedStr {
79 pub const NONE: Self = Self {
80 ptr: std::ptr::null_mut(),
81 len: 0,
82 };
83
84 pub fn from_string(s: String) -> Self {
86 let len = s.len() as u32;
87 let ptr = Box::into_raw(s.into_bytes().into_boxed_slice()) as *mut u8;
88 Self { ptr, len }
89 }
90
91 #[inline]
92 pub fn is_none(self) -> bool {
93 self.ptr.is_null()
94 }
95}
96
97#[repr(C)]
99#[derive(Copy, Clone)]
100pub struct YogBlockPos {
101 pub x: i32,
102 pub y: i32,
103 pub z: i32,
104}
105
106#[repr(C)]
108#[derive(Copy, Clone)]
109pub struct YogVec3 {
110 pub x: f64,
111 pub y: f64,
112 pub z: f64,
113}
114
115#[repr(C)]
118pub struct YogBlockBreakEvent {
119 pub player: YogStr,
120 pub block: YogStr,
121 pub pos: YogBlockPos,
122 pub dimension: YogStr,
124}
125
126#[repr(C)]
127pub struct YogChatEvent {
128 pub player: YogStr,
129 pub message: YogStr,
130 pub dimension: YogStr,
131}
132
133#[repr(C)]
135pub struct YogPlayerEvent {
136 pub player: YogStr,
137 pub uuid: YogStr,
138 pub dimension: YogStr,
139}
140
141#[repr(C)]
142pub struct YogUseItemEvent {
143 pub player: YogStr,
144 pub item: YogStr,
145 pub sneaking: bool,
147 pub dimension: YogStr,
148}
149
150#[repr(C)]
151pub struct YogUseBlockEvent {
152 pub player: YogStr,
153 pub block: YogStr,
154 pub pos: YogBlockPos,
155 pub dimension: YogStr,
156 pub sneaking: bool,
158}
159
160#[repr(C)]
161pub struct YogAttackEntityEvent {
162 pub player: YogStr,
163 pub target_type: YogStr,
164 pub target_uuid: YogStr,
165 pub dimension: YogStr,
166}
167
168#[repr(C)]
169pub struct YogEntityDamageEvent {
170 pub entity_type: YogStr,
171 pub uuid: YogStr,
172 pub amount: f32,
173 pub source: YogStr,
174 pub dimension: YogStr,
175}
176
177#[repr(C)]
178pub struct YogEntityDeathEvent {
179 pub entity_type: YogStr,
180 pub uuid: YogStr,
181 pub source: YogStr,
182 pub dimension: YogStr,
183}
184
185#[repr(C)]
186pub struct YogEntitySpawnEvent {
187 pub entity_type: YogStr,
188 pub uuid: YogStr,
189 pub dimension: YogStr,
190}
191
192#[repr(C)]
195pub struct YogPlayerDeathEvent {
196 pub player: YogStr,
197 pub uuid: YogStr,
198 pub source: YogStr,
200 pub dimension: YogStr,
201}
202
203#[repr(C)]
205pub struct YogPlayerRespawnEvent {
206 pub player: YogStr,
207 pub uuid: YogStr,
208 pub at_anchor: bool,
210 pub dimension: YogStr,
212}
213
214#[repr(C)]
216pub struct YogAdvancementEvent {
217 pub player: YogStr,
218 pub uuid: YogStr,
219 pub advancement: YogStr,
221 pub dimension: YogStr,
222}
223
224#[repr(C)]
227pub struct YogEntityInteractEvent {
228 pub player: YogStr,
229 pub player_uuid: YogStr,
230 pub entity_type: YogStr,
231 pub entity_uuid: YogStr,
232 pub hand: YogStr,
234 pub dimension: YogStr,
235}
236
237#[repr(C)]
239pub struct YogCraftEvent {
240 pub player: YogStr,
241 pub player_uuid: YogStr,
242 pub result_item: YogStr,
243 pub result_count: u32,
244 pub dimension: YogStr,
245}
246
247#[repr(C)]
253pub struct YogMachineCraftEvent {
254 pub machine: YogStr,
256 pub kind: YogStr,
258 pub recipe: YogStr,
259 pub result_item: YogStr,
260 pub result_count: u32,
261 pub values: YogStr,
263 pub pos: YogBlockPos,
264 pub dimension: YogStr,
265 pub player: YogStr,
266}
267
268#[repr(C)]
271pub struct YogExplosionEvent {
272 pub dimension: YogStr,
273 pub x: f64,
274 pub y: f64,
275 pub z: f64,
276 pub power: f32,
277 pub cause_uuid: YogStr,
279}
280
281#[repr(C)]
286pub struct YogItemInsertEvent {
287 pub block: YogStr,
288 pub pos: YogBlockPos,
289 pub dimension: YogStr,
290 pub item_id: YogStr,
291 pub count: u32,
292 pub nbt: YogStr,
294}
295
296#[repr(C)]
298pub struct YogItemPickupEvent {
299 pub player: YogStr,
300 pub player_uuid: YogStr,
301 pub item_id: YogStr,
303 pub item_count: u32,
304 pub entity_uuid: YogStr,
306 pub dimension: YogStr,
307}
308
309#[repr(C)]
311pub struct YogPlayerMoveEvent {
312 pub player: YogStr,
313 pub player_uuid: YogStr,
314 pub x: f64,
315 pub y: f64,
316 pub z: f64,
317 pub yaw: f32,
318 pub pitch: f32,
319 pub dimension: YogStr,
320}
321
322#[repr(C)]
326pub struct YogContainerOpenEvent {
327 pub player: YogStr,
328 pub player_uuid: YogStr,
329 pub container_type: YogStr,
330 pub dimension: YogStr,
331}
332
333#[repr(C)]
335pub struct YogContainerCloseEvent {
336 pub player: YogStr,
337 pub player_uuid: YogStr,
338 pub dimension: YogStr,
339}
340
341#[repr(C)]
344pub struct YogProjectileHitEvent {
345 pub projectile_type: YogStr,
347 pub projectile_uuid: YogStr,
348 pub shooter_uuid: YogStr,
350 pub hit_type: YogStr,
352 pub hit_entity_uuid: YogStr,
354 pub x: f64,
355 pub y: f64,
356 pub z: f64,
357 pub dimension: YogStr,
358}
359
360#[repr(C)]
362pub struct YogPlaceBlockEvent {
363 pub player: YogStr,
364 pub block: YogStr,
365 pub pos: YogBlockPos,
366 pub dimension: YogStr,
367 pub sneaking: bool,
369}
370
371#[repr(C)]
372pub struct YogPacketEvent {
373 pub channel: YogStr,
374 pub player: YogStr, pub payload: *const u8,
376 pub payload_len: u32,
377}
378
379#[repr(C)]
380pub struct YogCommandEvent {
381 pub name: YogStr,
382 pub args: YogStr,
383 pub source: YogStr,
384 pub uuid: YogStr,
385 pub dimension: YogStr,
387}
388
389#[repr(C)]
393#[derive(Copy, Clone)]
394pub struct YogKeyPressEvent {
395 pub key_code: i32,
397 pub scan_code: i32,
398 pub action: i32,
400 pub modifiers: i32,
402}
403
404pub type YogBlockBreakFn =
416 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogBlockBreakEvent, u8) -> bool;
417pub type YogChatFn =
418 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogChatEvent, u8) -> bool;
419pub type YogPlayerFn =
420 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerEvent, u8) -> bool;
421pub type YogUseItemFn =
422 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogUseItemEvent, u8) -> bool;
423pub type YogUseBlockFn =
424 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogUseBlockEvent, u8) -> bool;
425pub type YogAttackEntityFn =
426 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogAttackEntityEvent, u8) -> bool;
427pub type YogEntityDamageFn =
428 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityDamageEvent, u8) -> bool;
429pub type YogEntityDeathFn =
430 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityDeathEvent, u8) -> bool;
431pub type YogEntitySpawnFn =
432 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntitySpawnEvent, u8) -> bool;
433pub type YogPlaceBlockFn =
434 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlaceBlockEvent, u8) -> bool;
435pub type YogPlayerDeathFn =
436 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerDeathEvent, u8) -> bool;
437pub type YogPlayerRespawnFn =
438 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerRespawnEvent, u8) -> bool;
439pub type YogAdvancementFn =
440 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogAdvancementEvent, u8) -> bool;
441pub type YogEntityInteractFn =
442 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityInteractEvent, u8) -> bool;
443pub type YogCraftFn =
444 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogCraftEvent, u8) -> bool;
445pub type YogMachineCraftFn =
446 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogMachineCraftEvent, u8) -> bool;
447pub type YogExplosionFn =
448 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogExplosionEvent, u8) -> bool;
449pub type YogItemInsertFn =
450 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogItemInsertEvent, u8) -> bool;
451pub type YogItemPickupFn =
452 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogItemPickupEvent, u8) -> bool;
453pub type YogPlayerMoveFn =
454 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerMoveEvent, u8) -> bool;
455pub type YogContainerOpenFn =
456 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogContainerOpenEvent, u8) -> bool;
457pub type YogContainerCloseFn =
458 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogContainerCloseEvent, u8) -> bool;
459pub type YogProjectileHitFn =
460 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogProjectileHitEvent, u8) -> bool;
461
462pub type YogPacketFn = unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPacketEvent);
464pub type YogServerFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
466pub type YogEntityTickFn = unsafe extern "C" fn(*mut c_void, *const YogServer, YogStr);
468pub type YogCommandFn = unsafe extern "C" fn(
470 ud: *mut c_void,
471 srv: *const YogServer,
472 ev: *const YogCommandEvent,
473 reply_buf: *mut u8,
474 reply_cap: u32,
475 reply_len: *mut u32,
476);
477pub type YogScheduledFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
479
480pub type YogClientFn = unsafe extern "C" fn(ud: *mut c_void);
484pub type YogUIEventFn = unsafe extern "C" fn(ud: *mut c_void, ui_id: YogStr, event_id: YogStr);
491pub type YogHudRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
494pub type YogPageDrawFn = unsafe extern "C" fn(
498 ud: *mut c_void,
499 gfx: *const YogGfxApi,
500 data: *const u8,
501 len: usize,
502 x: f32,
503 y: f32,
504 w: f32,
505 h: f32,
506);
507pub type YogTooltipSizeFn =
510 unsafe extern "C" fn(ud: *mut c_void, item: YogStr, snbt: YogStr, w: *mut f32, h: *mut f32) -> bool;
511pub type YogTooltipDrawFn = unsafe extern "C" fn(
514 ud: *mut c_void,
515 gfx: *const YogGfxApi,
516 item: YogStr,
517 snbt: YogStr,
518 x: f32,
519 y: f32,
520 w: f32,
521 h: f32,
522);
523pub type YogTextSink = unsafe extern "C" fn(sink: *mut c_void, text: YogStr);
526pub type YogBytesSink = unsafe extern "C" fn(sink: *mut c_void, data: *const u8, len: usize);
532pub type YogBodyFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const u8, len: usize, sink: *mut c_void, write: YogBytesSink);
535pub type YogCameraFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const YogCameraFrame, out: *mut YogCameraOut);
538pub type YogTravelFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const YogTravelFrame, velocity: *mut [f32; 3]) -> bool;
540
541#[repr(C)]
543#[derive(Copy, Clone)]
544pub struct YogCameraFrame {
545 pub uuid: YogStr,
546 pub partial: f32,
547 pub pos: [f64; 3],
548 pub yaw: f32,
549 pub pitch: f32,
550 pub detached: bool,
551 pub flags: u32,
552}
553
554#[repr(C)]
556#[derive(Copy, Clone)]
557pub struct YogCameraOut {
558 pub local_offset: [f32; 3],
559 pub world_offset: [f32; 3],
560 pub yaw: f32,
561 pub pitch: f32,
562 pub roll: f32,
563 pub fov: f32,
564}
565
566#[repr(C)]
568#[derive(Copy, Clone)]
569pub struct YogTravelFrame {
570 pub uuid: YogStr,
571 pub velocity: [f32; 3],
572 pub look: [f32; 3],
573 pub yaw: f32,
574 pub pitch: f32,
575 pub forward: f32,
576 pub strafe: f32,
577 pub jumping: bool,
578 pub sneaking: bool,
579 pub gravity: f32,
580 pub flags: u32,
581}
582
583pub type YogItemTextFn =
584 unsafe extern "C" fn(ud: *mut c_void, item: YogStr, snbt: YogStr, sink: *mut c_void, write: YogTextSink) -> bool;
585pub type YogWorldRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
588pub type YogKeyPressFn = unsafe extern "C" fn(ud: *mut c_void, ev: *const YogKeyPressEvent) -> bool;
590pub type YogScreenFn = unsafe extern "C" fn(ud: *mut c_void, screen_class: YogStr) -> bool;
593
594#[repr(C)]
610#[derive(Copy, Clone)]
611pub struct YogGfxApi {
612 pub screen_w: i32,
615 pub screen_h: i32,
617 pub delta_tick: f32,
619 pub scale_factor: f32,
622 pub view_proj: [f32; 16],
625 pub camera_pos: [f32; 3],
627 pub player_pos: [f32; 3],
630 pub _pad1: f32,
631
632 pub buf_create: unsafe extern "C" fn() -> u32,
635 pub buf_delete: unsafe extern "C" fn(handle: u32),
637 pub buf_data: unsafe extern "C" fn(handle: u32, bytes: *const u8, len: u32, dynamic: bool),
640 pub buf_subdata: unsafe extern "C" fn(handle: u32, offset: u32, bytes: *const u8, len: u32),
642
643 pub vao_create: unsafe extern "C" fn() -> u32,
646 pub vao_delete: unsafe extern "C" fn(handle: u32),
648 pub vao_attrib: unsafe extern "C" fn(
651 vao: u32,
652 vbo: u32,
653 index: u32,
654 components: u8,
655 dtype: u8,
656 normalized: bool,
657 stride: u32,
658 offset: u32,
659 ),
660 pub vao_set_ebo: unsafe extern "C" fn(vao: u32, ebo: u32),
662
663 pub prog_create: unsafe extern "C" fn(vert: YogStr, frag: YogStr, out: *mut u32) -> bool,
667 pub prog_delete: unsafe extern "C" fn(handle: u32),
669 pub prog_uniform_1i: unsafe extern "C" fn(prog: u32, name: YogStr, v: i32),
670 pub prog_uniform_1f: unsafe extern "C" fn(prog: u32, name: YogStr, v: f32),
671 pub prog_uniform_2f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32),
672 pub prog_uniform_3f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32),
673 pub prog_uniform_4f:
674 unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32, w: f32),
675 pub prog_uniform_mat4: unsafe extern "C" fn(prog: u32, name: YogStr, col_major: *const f32),
677
678 pub tex_create: unsafe extern "C" fn(w: u32, h: u32, rgba: *const u8, linear: bool) -> u32,
682 pub tex_delete: unsafe extern "C" fn(handle: u32),
684 pub tex_bind: unsafe extern "C" fn(unit: u32, handle: u32),
686 pub tex_from_mc: unsafe extern "C" fn(id: YogStr) -> u32,
690
691 pub draw_arrays: unsafe extern "C" fn(vao: u32, prog: u32, mode: u8, first: u32, count: u32),
695 pub draw_elements:
698 unsafe extern "C" fn(vao: u32, ebo: u32, prog: u32, mode: u8, count: u32, u32_idx: bool),
699
700 pub set_blend: unsafe extern "C" fn(enabled: bool, src: u32, dst: u32),
703 pub set_depth: unsafe extern "C" fn(test: bool, write: bool),
705 pub set_scissor: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
709 pub clear_scissor: unsafe extern "C" fn(),
711 pub set_viewport: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
713
714 pub draw2d_rect: unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, color: u32),
717 pub draw2d_gradient:
719 unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, top: u32, bottom: u32),
720 pub draw2d_text: unsafe extern "C" fn(text: YogStr, x: f32, y: f32, color: u32, shadow: bool),
722
723 pub draw2d_item: unsafe extern "C" fn(id: YogStr, x: f32, y: f32, size: f32),
729
730 pub draw2d_text_font:
736 unsafe extern "C" fn(text: YogStr, font: YogStr, x: f32, y: f32, color: u32, shadow: bool),
737 pub text_width: unsafe extern "C" fn(text: YogStr, font: YogStr) -> f32,
742
743 pub draw2d_image: unsafe extern "C" fn(
754 source: YogStr,
755 x: f32,
756 y: f32,
757 w: f32,
758 h: f32,
759 u: f32,
760 v: f32,
761 uw: f32,
762 vh: f32,
763 tint: u32,
764 ),
765 pub image_size: unsafe extern "C" fn(source: YogStr, w: *mut f32, h: *mut f32) -> bool,
770
771 pub draw2d_svg: unsafe extern "C" fn(data: YogStr, x: f32, y: f32, w: f32, h: f32),
775 pub draw2d_entity:
779 unsafe extern "C" fn(entity: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
780
781 pub draw2d_text_scaled: unsafe extern "C" fn(
785 text: YogStr,
786 font: YogStr,
787 x: f32,
788 y: f32,
789 scale: f32,
790 color: u32,
791 shadow: bool,
792 ),
793 pub draw2d_blocks:
797 unsafe extern "C" fn(blocks: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
798}
799
800unsafe impl Send for YogGfxApi {}
801unsafe impl Sync for YogGfxApi {}
802
803#[repr(C)]
813pub struct YogServer {
814 pub ctx: *mut c_void,
815 pub abi_version: u32,
816 pub size: u32,
819
820 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
822
823 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
825
826 pub get_block:
828 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
829 pub set_block: unsafe extern "C" fn(
830 ctx: *mut c_void,
831 dim: YogStr,
832 pos: YogBlockPos,
833 block: YogStr,
834 ) -> bool,
835 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
836 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
837 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
838 pub set_weather:
839 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
840
841 pub give_item:
843 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
844 pub player_teleport:
845 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
846 pub send_to_player: unsafe extern "C" fn(
847 ctx: *mut c_void,
848 player: YogStr,
849 channel: YogStr,
850 data: *const u8,
851 len: u32,
852 ) -> bool,
853 pub send_to_server:
854 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
855 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
856 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
857 pub send_title: unsafe extern "C" fn(
858 ctx: *mut c_void,
859 player: YogStr,
860 title: YogStr,
861 sub: YogStr,
862 fi: i32,
863 stay: i32,
864 fo: i32,
865 ) -> bool,
866 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
867 pub play_sound: unsafe extern "C" fn(
868 ctx: *mut c_void,
869 dim: YogStr,
870 pos: YogVec3,
871 sound: YogStr,
872 vol: f32,
873 pitch: f32,
874 ) -> bool,
875 pub play_sound_player: unsafe extern "C" fn(
876 ctx: *mut c_void,
877 player: YogStr,
878 sound: YogStr,
879 vol: f32,
880 pitch: f32,
881 ) -> bool,
882
883 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
885 pub entity_position:
886 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
887 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
888 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
889 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
890 pub spawn_entity: unsafe extern "C" fn(
891 ctx: *mut c_void,
892 type_id: YogStr,
893 dim: YogStr,
894 pos: YogVec3,
895 ) -> YogOwnedStr,
896 pub entity_add_effect: unsafe extern "C" fn(
897 ctx: *mut c_void,
898 uuid: YogStr,
899 fx: YogStr,
900 dur: i32,
901 amp: u8,
902 particles: bool,
903 ) -> bool,
904 pub entity_remove_effect:
905 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
906 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
907 pub entity_velocity:
908 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
909 pub entity_set_velocity:
910 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
911 pub entity_add_velocity:
912 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
913
914 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
916 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
917 pub drop_loot:
918 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
919
920 pub scoreboard_get:
922 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
923 pub scoreboard_set:
924 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
925 pub scoreboard_add: unsafe extern "C" fn(
926 ctx: *mut c_void,
927 obj: YogStr,
928 player: YogStr,
929 delta: i32,
930 out: *mut i32,
931 ) -> bool,
932
933 pub bossbar_create: unsafe extern "C" fn(
935 ctx: *mut c_void,
936 id: YogStr,
937 title: YogStr,
938 color: YogStr,
939 style: YogStr,
940 ) -> bool,
941 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
942 pub bossbar_set_title:
943 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
944 pub bossbar_set_progress:
945 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
946 pub bossbar_set_color:
947 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
948 pub bossbar_add_player:
949 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
950 pub bossbar_remove_player:
951 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
952 pub bossbar_set_visible:
953 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
954
955 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
957
958 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
961
962 pub get_block_nbt:
965 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
966 pub set_block_nbt:
968 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
969
970 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
973 pub player_set_slot: unsafe extern "C" fn(
975 ctx: *mut c_void,
976 player: YogStr,
977 slot: u32,
978 item_id: YogStr,
979 count: u32,
980 ) -> bool,
981
982 pub get_inventory_slot: unsafe extern "C" fn(
986 ctx: *mut c_void,
987 dim: YogStr,
988 pos: YogBlockPos,
989 slot: u32,
990 ) -> YogOwnedStr,
991 pub set_inventory_slot: unsafe extern "C" fn(
995 ctx: *mut c_void,
996 dim: YogStr,
997 pos: YogBlockPos,
998 slot: u32,
999 item_id: YogStr,
1000 count: u32,
1001 ) -> bool,
1002
1003 pub player_teleport_dim:
1005 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1006 pub entity_teleport_dim:
1007 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1008
1009 pub world_entity_count:
1012 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
1013
1014 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1017 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
1019
1020 pub spawn_particles: unsafe extern "C" fn(
1025 ctx: *mut c_void,
1026 dim: YogStr,
1027 pos: YogVec3,
1028 particle_type: YogStr,
1029 count: i32,
1030 dx: f64,
1031 dy: f64,
1032 dz: f64,
1033 speed: f64,
1034 ) -> bool,
1035
1036 pub entity_attribute_get:
1041 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
1042 pub entity_attribute_set: unsafe extern "C" fn(
1044 ctx: *mut c_void,
1045 uuid: YogStr,
1046 attribute_id: YogStr,
1047 value: f64,
1048 ) -> bool,
1049
1050 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1054 pub set_held_item_nbt:
1057 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1058
1059 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1062 pub set_offhand_item_nbt:
1065 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1066 pub get_slot_item:
1069 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
1070 pub set_slot_item: unsafe extern "C" fn(
1073 ctx: *mut c_void,
1074 player: YogStr,
1075 slot: u32,
1076 item_id: YogStr,
1077 count: u32,
1078 snbt: YogStr,
1079 ) -> bool,
1080
1081 pub entity_rotation:
1085 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
1086
1087 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1092 pub entities_in_box: unsafe extern "C" fn(
1094 ctx: *mut c_void,
1095 dim: YogStr,
1096 min: YogVec3,
1097 max: YogVec3,
1098 ) -> YogOwnedStr,
1099 pub raycast_block: unsafe extern "C" fn(
1101 ctx: *mut c_void,
1102 dim: YogStr,
1103 from: YogVec3,
1104 to: YogVec3,
1105 ) -> YogOwnedStr,
1106 pub raycast_entity: unsafe extern "C" fn(
1108 ctx: *mut c_void,
1109 dim: YogStr,
1110 from: YogVec3,
1111 to: YogVec3,
1112 exclude: YogStr,
1113 ) -> YogOwnedStr,
1114 pub block_info:
1116 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1117 pub break_block: unsafe extern "C" fn(
1118 ctx: *mut c_void,
1119 dim: YogStr,
1120 pos: YogBlockPos,
1121 drop: bool,
1122 breaker: YogStr,
1123 ) -> bool,
1124 pub place_block_from_slot: unsafe extern "C" fn(
1125 ctx: *mut c_void,
1126 player: YogStr,
1127 slot: u32,
1128 dim: YogStr,
1129 pos: YogBlockPos,
1130 ) -> bool,
1131 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1132 pub explode: unsafe extern "C" fn(
1133 ctx: *mut c_void,
1134 dim: YogStr,
1135 pos: YogVec3,
1136 power: f32,
1137 fire: bool,
1138 source: YogStr,
1139 ) -> bool,
1140 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1142 pub entity_damage: unsafe extern "C" fn(
1143 ctx: *mut c_void,
1144 uuid: YogStr,
1145 amount: f32,
1146 damage_type: YogStr,
1147 attacker: YogStr,
1148 ) -> bool,
1149 pub entity_set_fire_ticks:
1150 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1151 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1152 pub player_set_may_fly:
1153 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1154 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1156 pub spawn_item: unsafe extern "C" fn(
1158 ctx: *mut c_void,
1159 dim: YogStr,
1160 pos: YogVec3,
1161 vel: YogVec3,
1162 item_id: YogStr,
1163 count: u32,
1164 snbt: YogStr,
1165 ) -> YogOwnedStr,
1166 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1168 pub item_entity_set_stack: unsafe extern "C" fn(
1169 ctx: *mut c_void,
1170 uuid: YogStr,
1171 item_id: YogStr,
1172 count: u32,
1173 snbt: YogStr,
1174 ) -> bool,
1175 pub actionbar_json:
1178 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1179 pub use_item_on_block: unsafe extern "C" fn(
1181 ctx: *mut c_void,
1182 dim: YogStr,
1183 pos: YogBlockPos,
1184 face: u8,
1185 item_id: YogStr,
1186 player: YogStr,
1187 ) -> bool,
1188 pub pour_fluid: unsafe extern "C" fn(
1189 ctx: *mut c_void,
1190 dim: YogStr,
1191 pos: YogBlockPos,
1192 bucket_item_id: YogStr,
1193 ) -> bool,
1194 pub has_entity_tag:
1195 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1196 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1198 pub place_feature: unsafe extern "C" fn(
1199 ctx: *mut c_void,
1200 dim: YogStr,
1201 pos: YogBlockPos,
1202 feature_id: YogStr,
1203 ) -> bool,
1204
1205 pub set_item_cooldown:
1207 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1208 pub entity_vehicle: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1210 pub entity_passengers: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1212 pub entity_mount:
1214 unsafe extern "C" fn(ctx: *mut c_void, rider: YogStr, vehicle: YogStr, force: bool) -> bool,
1215 pub entity_dismount: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
1217 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1219 pub entity_set_fall_distance: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, distance: f32) -> bool,
1221 pub redstone_signal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1223 pub set_redstone_output:
1224 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1225 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1227 pub set_block_state:
1228 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1229 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1230 pub world_set_thunder:
1231 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1232 pub fill_region: unsafe extern "C" fn(
1234 ctx: *mut c_void,
1235 dim: YogStr,
1236 from: YogBlockPos,
1237 to: YogBlockPos,
1238 state: YogStr,
1239 ) -> i32,
1240 pub scan_region:
1242 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1243
1244 pub entity_set_dimensions:
1248 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32) -> bool,
1249
1250 pub entity_data_set:
1255 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, data: *const u8, len: u32, flags: u32) -> bool,
1256 pub entity_data_get:
1258 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1259}
1260
1261unsafe impl Send for YogServer {}
1263unsafe impl Sync for YogServer {}
1264
1265#[repr(C)]
1272#[derive(Copy, Clone)]
1273pub struct YogChunkWriterApi {
1274 pub chunk_x: i32,
1276 pub chunk_z: i32,
1278 pub min_y: i32,
1280 pub height: i32,
1282 pub ctx: *mut c_void,
1284 pub set_block:
1287 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1288}
1289
1290unsafe impl Send for YogChunkWriterApi {}
1291unsafe impl Sync for YogChunkWriterApi {}
1292
1293pub type YogChunkGeneratorFn =
1296 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1297
1298#[repr(C)]
1307pub struct YogApi {
1308 pub abi_version: u32,
1309 pub size: u32,
1311 pub ctx: *mut c_void,
1313 pub server: *const YogServer,
1315
1316 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1319 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1320 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1321 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1322 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1323 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1324 pub on_attack_entity:
1325 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1326 pub on_entity_damage:
1327 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1328 pub on_entity_death:
1329 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1330 pub on_entity_spawn:
1331 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1332 pub on_player_place_block:
1333 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1334 pub on_player_death:
1335 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1336 pub on_player_respawn:
1337 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1338 pub on_advancement:
1339 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1340 pub on_entity_interact:
1342 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1343 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1344 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1345 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1347 pub on_item_insert: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemInsertFn),
1348 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1349 pub on_container_open:
1350 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1351 pub on_container_close:
1352 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1353 pub on_projectile_hit:
1354 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1355 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1356 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1357 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1358
1359 pub on_packet:
1361 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1362 pub on_client_packet:
1363 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1364
1365 pub register_command:
1367 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1368 pub register_typed_command: unsafe extern "C" fn(
1369 ctx: *mut c_void,
1370 name: YogStr,
1371 schema: YogStr,
1372 ud: *mut c_void,
1373 h: YogCommandFn,
1374 ),
1375
1376 pub register_content: unsafe extern "C" fn(ctx: *mut c_void, kind: YogStr, id: YogStr, data: *const u8, len: usize),
1384
1385 pub schedule_once: unsafe extern "C" fn(
1387 ctx: *mut c_void,
1388 delay_ticks: u64,
1389 ud: *mut c_void,
1390 h: YogScheduledFn,
1391 ),
1392 pub schedule_repeating: unsafe extern "C" fn(
1393 ctx: *mut c_void,
1394 period_ticks: u64,
1395 ud: *mut c_void,
1396 h: YogScheduledFn,
1397 ),
1398
1399 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1401 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1402 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1403 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1404 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1405
1406 pub on_world_render:
1411 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1412
1413 pub register_ui: unsafe extern "C" fn(
1418 ctx: *mut c_void,
1419 ui_id: YogStr,
1420 layout_json: YogStr,
1421 ud: *mut c_void,
1422 h: YogUIEventFn,
1423 ),
1424
1425 pub on_ui_render:
1432 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1433
1434 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1440
1441 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1448 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1451
1452 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1457
1458 pub interop_export:
1462 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1463 pub interop_import:
1466 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1467
1468 pub register_chunk_generator:
1473 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1474
1475 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1480 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1484
1485 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1493
1494 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1499 pub client_play_sound: unsafe extern "C" fn(
1503 ctx: *mut c_void,
1504 sound_id: YogStr,
1505 volume: f32,
1506 pitch: f32,
1507 looping: bool,
1508 ) -> u32,
1509 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1511 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1514 pub client_set_block_tint: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, color: i64),
1517 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1519
1520 pub on_book_page:
1524 unsafe extern "C" fn(ctx: *mut c_void, drawer: YogStr, ud: *mut c_void, f: YogPageDrawFn),
1525
1526 pub on_item_tooltip: unsafe extern "C" fn(
1531 ctx: *mut c_void,
1532 item: YogStr,
1533 ud: *mut c_void,
1534 size: YogTooltipSizeFn,
1535 draw: YogTooltipDrawFn,
1536 ),
1537
1538 pub is_mod_loaded: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
1542 pub java_call: unsafe extern "C" fn(ctx: *mut c_void, expr: YogStr, args: YogStr) -> YogOwnedStr,
1549
1550 pub on_item_text: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, ud: *mut c_void, f: YogItemTextFn),
1554
1555 pub on_machine_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogMachineCraftFn),
1558
1559 pub client_body_track: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, on: bool),
1562 pub client_body_track_type: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, on: bool),
1564 pub on_body: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogBodyFn),
1566 pub on_camera: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogCameraFn),
1568 pub on_travel: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogTravelFn),
1570
1571 pub client_set_dimensions: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32),
1575
1576 pub client_entity_data:
1580 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1581
1582 pub on_entity_tick: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, ud: *mut c_void, f: YogEntityTickFn),
1585}
1586
1587pub mod ui_flags {
1589 pub const MODAL: u32 = 1;
1591 pub const PAUSE: u32 = 1 << 1;
1593 pub const NO_BACKGROUND: u32 = 1 << 2;
1595}
1596
1597unsafe impl Send for YogApi {}
1598unsafe impl Sync for YogApi {}
1599
1600#[cfg(test)]
1601mod tests {
1602 use super::*;
1603 use std::mem::{align_of, size_of};
1604
1605 fn layout_fingerprint() -> u64 {
1607 macro_rules! layouts {
1608 ($($t:ty),* $(,)?) => { [$((stringify!($t), size_of::<$t>(), align_of::<$t>())),*] };
1609 }
1610 let all = layouts!(
1611 YogStr, YogOwnedStr, YogBlockPos, YogVec3, YogBlockBreakEvent, YogChatEvent, YogPlayerEvent,
1612 YogUseItemEvent, YogUseBlockEvent, YogAttackEntityEvent, YogEntityDamageEvent, YogEntityDeathEvent,
1613 YogEntitySpawnEvent, YogPlayerDeathEvent, YogPlayerRespawnEvent, YogAdvancementEvent,
1614 YogEntityInteractEvent, YogCraftEvent, YogExplosionEvent, YogItemPickupEvent, YogItemInsertEvent, YogPlayerMoveEvent,
1615 YogContainerOpenEvent, YogContainerCloseEvent, YogProjectileHitEvent, YogPlaceBlockEvent,
1616 YogPacketEvent, YogCommandEvent,
1617 YogKeyPressEvent, YogGfxApi, YogServer, YogChunkWriterApi, YogApi,
1618 );
1619 let mut h: u64 = 0xcbf2_9ce4_8422_2325;
1621 for (name, size, align) in all {
1622 for b in name.bytes().chain((size as u64).to_le_bytes()).chain((align as u64).to_le_bytes()) {
1623 h = (h ^ b as u64).wrapping_mul(0x0100_0000_01b3);
1624 }
1625 }
1626 h
1627 }
1628
1629 #[test]
1633 #[cfg(target_pointer_width = "64")]
1634 fn the_layout_matches_its_version() {
1635 assert_eq!((ABI_VERSION, layout_fingerprint()), (30003, 0xeba8_25c0_1533_09dc), "layout fingerprint: {:#x}", layout_fingerprint());
1636 }
1637
1638 #[test]
1639 fn strings_cross_and_come_back() {
1640 let s = YogStr::from_str("Ünïcode ✓");
1641 assert_eq!(unsafe { s.as_str() }, "Ünïcode ✓");
1642 assert!(YogStr::EMPTY.is_empty());
1643 assert_eq!(unsafe { YogStr::EMPTY.as_str() }, "");
1644 let owned = YogOwnedStr::from_string("runtime".to_string());
1645 assert!(!owned.is_none() && owned.len == 7);
1646 assert!(YogOwnedStr::NONE.is_none());
1647 drop(unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(owned.ptr, owned.len as usize)) });
1649 }
1650}