1use std::os::raw::c_void;
13
14pub const ABI_MAJOR: u32 = 3;
17pub const ABI_MINOR: u32 = 2;
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 YogCommandFn = unsafe extern "C" fn(
468 ud: *mut c_void,
469 srv: *const YogServer,
470 ev: *const YogCommandEvent,
471 reply_buf: *mut u8,
472 reply_cap: u32,
473 reply_len: *mut u32,
474);
475pub type YogScheduledFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
477
478pub type YogClientFn = unsafe extern "C" fn(ud: *mut c_void);
482pub type YogUIEventFn = unsafe extern "C" fn(ud: *mut c_void, ui_id: YogStr, event_id: YogStr);
489pub type YogHudRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
492pub type YogPageDrawFn = unsafe extern "C" fn(
496 ud: *mut c_void,
497 gfx: *const YogGfxApi,
498 data: *const u8,
499 len: usize,
500 x: f32,
501 y: f32,
502 w: f32,
503 h: f32,
504);
505pub type YogTooltipSizeFn =
508 unsafe extern "C" fn(ud: *mut c_void, item: YogStr, snbt: YogStr, w: *mut f32, h: *mut f32) -> bool;
509pub type YogTooltipDrawFn = unsafe extern "C" fn(
512 ud: *mut c_void,
513 gfx: *const YogGfxApi,
514 item: YogStr,
515 snbt: YogStr,
516 x: f32,
517 y: f32,
518 w: f32,
519 h: f32,
520);
521pub type YogTextSink = unsafe extern "C" fn(sink: *mut c_void, text: YogStr);
524pub type YogBytesSink = unsafe extern "C" fn(sink: *mut c_void, data: *const u8, len: usize);
530pub type YogBodyFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const u8, len: usize, sink: *mut c_void, write: YogBytesSink);
533pub type YogCameraFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const YogCameraFrame, out: *mut YogCameraOut);
536pub type YogTravelFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const YogTravelFrame, velocity: *mut [f32; 3]) -> bool;
538
539#[repr(C)]
541#[derive(Copy, Clone)]
542pub struct YogCameraFrame {
543 pub uuid: YogStr,
544 pub partial: f32,
545 pub pos: [f64; 3],
546 pub yaw: f32,
547 pub pitch: f32,
548 pub detached: bool,
549 pub flags: u32,
550}
551
552#[repr(C)]
554#[derive(Copy, Clone)]
555pub struct YogCameraOut {
556 pub local_offset: [f32; 3],
557 pub world_offset: [f32; 3],
558 pub yaw: f32,
559 pub pitch: f32,
560 pub roll: f32,
561 pub fov: f32,
562}
563
564#[repr(C)]
566#[derive(Copy, Clone)]
567pub struct YogTravelFrame {
568 pub uuid: YogStr,
569 pub velocity: [f32; 3],
570 pub look: [f32; 3],
571 pub yaw: f32,
572 pub pitch: f32,
573 pub forward: f32,
574 pub strafe: f32,
575 pub jumping: bool,
576 pub sneaking: bool,
577 pub gravity: f32,
578 pub flags: u32,
579}
580
581pub type YogItemTextFn =
582 unsafe extern "C" fn(ud: *mut c_void, item: YogStr, snbt: YogStr, sink: *mut c_void, write: YogTextSink) -> bool;
583pub type YogWorldRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
586pub type YogKeyPressFn = unsafe extern "C" fn(ud: *mut c_void, ev: *const YogKeyPressEvent) -> bool;
588pub type YogScreenFn = unsafe extern "C" fn(ud: *mut c_void, screen_class: YogStr) -> bool;
591
592#[repr(C)]
608#[derive(Copy, Clone)]
609pub struct YogGfxApi {
610 pub screen_w: i32,
613 pub screen_h: i32,
615 pub delta_tick: f32,
617 pub scale_factor: f32,
620 pub view_proj: [f32; 16],
623 pub camera_pos: [f32; 3],
625 pub player_pos: [f32; 3],
628 pub _pad1: f32,
629
630 pub buf_create: unsafe extern "C" fn() -> u32,
633 pub buf_delete: unsafe extern "C" fn(handle: u32),
635 pub buf_data: unsafe extern "C" fn(handle: u32, bytes: *const u8, len: u32, dynamic: bool),
638 pub buf_subdata: unsafe extern "C" fn(handle: u32, offset: u32, bytes: *const u8, len: u32),
640
641 pub vao_create: unsafe extern "C" fn() -> u32,
644 pub vao_delete: unsafe extern "C" fn(handle: u32),
646 pub vao_attrib: unsafe extern "C" fn(
649 vao: u32,
650 vbo: u32,
651 index: u32,
652 components: u8,
653 dtype: u8,
654 normalized: bool,
655 stride: u32,
656 offset: u32,
657 ),
658 pub vao_set_ebo: unsafe extern "C" fn(vao: u32, ebo: u32),
660
661 pub prog_create: unsafe extern "C" fn(vert: YogStr, frag: YogStr, out: *mut u32) -> bool,
665 pub prog_delete: unsafe extern "C" fn(handle: u32),
667 pub prog_uniform_1i: unsafe extern "C" fn(prog: u32, name: YogStr, v: i32),
668 pub prog_uniform_1f: unsafe extern "C" fn(prog: u32, name: YogStr, v: f32),
669 pub prog_uniform_2f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32),
670 pub prog_uniform_3f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32),
671 pub prog_uniform_4f:
672 unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32, w: f32),
673 pub prog_uniform_mat4: unsafe extern "C" fn(prog: u32, name: YogStr, col_major: *const f32),
675
676 pub tex_create: unsafe extern "C" fn(w: u32, h: u32, rgba: *const u8, linear: bool) -> u32,
680 pub tex_delete: unsafe extern "C" fn(handle: u32),
682 pub tex_bind: unsafe extern "C" fn(unit: u32, handle: u32),
684 pub tex_from_mc: unsafe extern "C" fn(id: YogStr) -> u32,
688
689 pub draw_arrays: unsafe extern "C" fn(vao: u32, prog: u32, mode: u8, first: u32, count: u32),
693 pub draw_elements:
696 unsafe extern "C" fn(vao: u32, ebo: u32, prog: u32, mode: u8, count: u32, u32_idx: bool),
697
698 pub set_blend: unsafe extern "C" fn(enabled: bool, src: u32, dst: u32),
701 pub set_depth: unsafe extern "C" fn(test: bool, write: bool),
703 pub set_scissor: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
707 pub clear_scissor: unsafe extern "C" fn(),
709 pub set_viewport: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
711
712 pub draw2d_rect: unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, color: u32),
715 pub draw2d_gradient:
717 unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, top: u32, bottom: u32),
718 pub draw2d_text: unsafe extern "C" fn(text: YogStr, x: f32, y: f32, color: u32, shadow: bool),
720
721 pub draw2d_item: unsafe extern "C" fn(id: YogStr, x: f32, y: f32, size: f32),
727
728 pub draw2d_text_font:
734 unsafe extern "C" fn(text: YogStr, font: YogStr, x: f32, y: f32, color: u32, shadow: bool),
735 pub text_width: unsafe extern "C" fn(text: YogStr, font: YogStr) -> f32,
740
741 pub draw2d_image: unsafe extern "C" fn(
752 source: YogStr,
753 x: f32,
754 y: f32,
755 w: f32,
756 h: f32,
757 u: f32,
758 v: f32,
759 uw: f32,
760 vh: f32,
761 tint: u32,
762 ),
763 pub image_size: unsafe extern "C" fn(source: YogStr, w: *mut f32, h: *mut f32) -> bool,
768
769 pub draw2d_svg: unsafe extern "C" fn(data: YogStr, x: f32, y: f32, w: f32, h: f32),
773 pub draw2d_entity:
777 unsafe extern "C" fn(entity: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
778
779 pub draw2d_text_scaled: unsafe extern "C" fn(
783 text: YogStr,
784 font: YogStr,
785 x: f32,
786 y: f32,
787 scale: f32,
788 color: u32,
789 shadow: bool,
790 ),
791 pub draw2d_blocks:
795 unsafe extern "C" fn(blocks: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
796}
797
798unsafe impl Send for YogGfxApi {}
799unsafe impl Sync for YogGfxApi {}
800
801#[repr(C)]
811pub struct YogServer {
812 pub ctx: *mut c_void,
813 pub abi_version: u32,
814 pub size: u32,
817
818 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
820
821 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
823
824 pub get_block:
826 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
827 pub set_block: unsafe extern "C" fn(
828 ctx: *mut c_void,
829 dim: YogStr,
830 pos: YogBlockPos,
831 block: YogStr,
832 ) -> bool,
833 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
834 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
835 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
836 pub set_weather:
837 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
838
839 pub give_item:
841 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
842 pub player_teleport:
843 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
844 pub send_to_player: unsafe extern "C" fn(
845 ctx: *mut c_void,
846 player: YogStr,
847 channel: YogStr,
848 data: *const u8,
849 len: u32,
850 ) -> bool,
851 pub send_to_server:
852 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
853 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
854 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
855 pub send_title: unsafe extern "C" fn(
856 ctx: *mut c_void,
857 player: YogStr,
858 title: YogStr,
859 sub: YogStr,
860 fi: i32,
861 stay: i32,
862 fo: i32,
863 ) -> bool,
864 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
865 pub play_sound: unsafe extern "C" fn(
866 ctx: *mut c_void,
867 dim: YogStr,
868 pos: YogVec3,
869 sound: YogStr,
870 vol: f32,
871 pitch: f32,
872 ) -> bool,
873 pub play_sound_player: unsafe extern "C" fn(
874 ctx: *mut c_void,
875 player: YogStr,
876 sound: YogStr,
877 vol: f32,
878 pitch: f32,
879 ) -> bool,
880
881 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
883 pub entity_position:
884 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
885 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
886 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
887 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
888 pub spawn_entity: unsafe extern "C" fn(
889 ctx: *mut c_void,
890 type_id: YogStr,
891 dim: YogStr,
892 pos: YogVec3,
893 ) -> YogOwnedStr,
894 pub entity_add_effect: unsafe extern "C" fn(
895 ctx: *mut c_void,
896 uuid: YogStr,
897 fx: YogStr,
898 dur: i32,
899 amp: u8,
900 particles: bool,
901 ) -> bool,
902 pub entity_remove_effect:
903 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
904 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
905 pub entity_velocity:
906 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
907 pub entity_set_velocity:
908 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
909 pub entity_add_velocity:
910 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
911
912 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
914 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
915 pub drop_loot:
916 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
917
918 pub scoreboard_get:
920 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
921 pub scoreboard_set:
922 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
923 pub scoreboard_add: unsafe extern "C" fn(
924 ctx: *mut c_void,
925 obj: YogStr,
926 player: YogStr,
927 delta: i32,
928 out: *mut i32,
929 ) -> bool,
930
931 pub bossbar_create: unsafe extern "C" fn(
933 ctx: *mut c_void,
934 id: YogStr,
935 title: YogStr,
936 color: YogStr,
937 style: YogStr,
938 ) -> bool,
939 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
940 pub bossbar_set_title:
941 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
942 pub bossbar_set_progress:
943 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
944 pub bossbar_set_color:
945 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
946 pub bossbar_add_player:
947 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
948 pub bossbar_remove_player:
949 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
950 pub bossbar_set_visible:
951 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
952
953 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
955
956 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
959
960 pub get_block_nbt:
963 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
964 pub set_block_nbt:
966 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
967
968 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
971 pub player_set_slot: unsafe extern "C" fn(
973 ctx: *mut c_void,
974 player: YogStr,
975 slot: u32,
976 item_id: YogStr,
977 count: u32,
978 ) -> bool,
979
980 pub get_inventory_slot: unsafe extern "C" fn(
984 ctx: *mut c_void,
985 dim: YogStr,
986 pos: YogBlockPos,
987 slot: u32,
988 ) -> YogOwnedStr,
989 pub set_inventory_slot: unsafe extern "C" fn(
993 ctx: *mut c_void,
994 dim: YogStr,
995 pos: YogBlockPos,
996 slot: u32,
997 item_id: YogStr,
998 count: u32,
999 ) -> bool,
1000
1001 pub player_teleport_dim:
1003 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1004 pub entity_teleport_dim:
1005 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1006
1007 pub world_entity_count:
1010 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
1011
1012 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1015 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
1017
1018 pub spawn_particles: unsafe extern "C" fn(
1023 ctx: *mut c_void,
1024 dim: YogStr,
1025 pos: YogVec3,
1026 particle_type: YogStr,
1027 count: i32,
1028 dx: f64,
1029 dy: f64,
1030 dz: f64,
1031 speed: f64,
1032 ) -> bool,
1033
1034 pub entity_attribute_get:
1039 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
1040 pub entity_attribute_set: unsafe extern "C" fn(
1042 ctx: *mut c_void,
1043 uuid: YogStr,
1044 attribute_id: YogStr,
1045 value: f64,
1046 ) -> bool,
1047
1048 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1052 pub set_held_item_nbt:
1055 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1056
1057 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1060 pub set_offhand_item_nbt:
1063 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1064 pub get_slot_item:
1067 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
1068 pub set_slot_item: unsafe extern "C" fn(
1071 ctx: *mut c_void,
1072 player: YogStr,
1073 slot: u32,
1074 item_id: YogStr,
1075 count: u32,
1076 snbt: YogStr,
1077 ) -> bool,
1078
1079 pub entity_rotation:
1083 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
1084
1085 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1090 pub entities_in_box: unsafe extern "C" fn(
1092 ctx: *mut c_void,
1093 dim: YogStr,
1094 min: YogVec3,
1095 max: YogVec3,
1096 ) -> YogOwnedStr,
1097 pub raycast_block: unsafe extern "C" fn(
1099 ctx: *mut c_void,
1100 dim: YogStr,
1101 from: YogVec3,
1102 to: YogVec3,
1103 ) -> YogOwnedStr,
1104 pub raycast_entity: unsafe extern "C" fn(
1106 ctx: *mut c_void,
1107 dim: YogStr,
1108 from: YogVec3,
1109 to: YogVec3,
1110 exclude: YogStr,
1111 ) -> YogOwnedStr,
1112 pub block_info:
1114 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1115 pub break_block: unsafe extern "C" fn(
1116 ctx: *mut c_void,
1117 dim: YogStr,
1118 pos: YogBlockPos,
1119 drop: bool,
1120 breaker: YogStr,
1121 ) -> bool,
1122 pub place_block_from_slot: unsafe extern "C" fn(
1123 ctx: *mut c_void,
1124 player: YogStr,
1125 slot: u32,
1126 dim: YogStr,
1127 pos: YogBlockPos,
1128 ) -> bool,
1129 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1130 pub explode: unsafe extern "C" fn(
1131 ctx: *mut c_void,
1132 dim: YogStr,
1133 pos: YogVec3,
1134 power: f32,
1135 fire: bool,
1136 source: YogStr,
1137 ) -> bool,
1138 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1140 pub entity_damage: unsafe extern "C" fn(
1141 ctx: *mut c_void,
1142 uuid: YogStr,
1143 amount: f32,
1144 damage_type: YogStr,
1145 attacker: YogStr,
1146 ) -> bool,
1147 pub entity_set_fire_ticks:
1148 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1149 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1150 pub player_set_may_fly:
1151 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1152 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1154 pub spawn_item: unsafe extern "C" fn(
1156 ctx: *mut c_void,
1157 dim: YogStr,
1158 pos: YogVec3,
1159 vel: YogVec3,
1160 item_id: YogStr,
1161 count: u32,
1162 snbt: YogStr,
1163 ) -> YogOwnedStr,
1164 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1166 pub item_entity_set_stack: unsafe extern "C" fn(
1167 ctx: *mut c_void,
1168 uuid: YogStr,
1169 item_id: YogStr,
1170 count: u32,
1171 snbt: YogStr,
1172 ) -> bool,
1173 pub actionbar_json:
1176 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1177 pub use_item_on_block: unsafe extern "C" fn(
1179 ctx: *mut c_void,
1180 dim: YogStr,
1181 pos: YogBlockPos,
1182 face: u8,
1183 item_id: YogStr,
1184 player: YogStr,
1185 ) -> bool,
1186 pub pour_fluid: unsafe extern "C" fn(
1187 ctx: *mut c_void,
1188 dim: YogStr,
1189 pos: YogBlockPos,
1190 bucket_item_id: YogStr,
1191 ) -> bool,
1192 pub has_entity_tag:
1193 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1194 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1196 pub place_feature: unsafe extern "C" fn(
1197 ctx: *mut c_void,
1198 dim: YogStr,
1199 pos: YogBlockPos,
1200 feature_id: YogStr,
1201 ) -> bool,
1202
1203 pub set_item_cooldown:
1205 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1206 pub entity_vehicle: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1208 pub entity_passengers: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1210 pub entity_mount:
1212 unsafe extern "C" fn(ctx: *mut c_void, rider: YogStr, vehicle: YogStr, force: bool) -> bool,
1213 pub entity_dismount: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
1215 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1217 pub entity_set_fall_distance: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, distance: f32) -> bool,
1219 pub redstone_signal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1221 pub set_redstone_output:
1222 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1223 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1225 pub set_block_state:
1226 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1227 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1228 pub world_set_thunder:
1229 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1230 pub fill_region: unsafe extern "C" fn(
1232 ctx: *mut c_void,
1233 dim: YogStr,
1234 from: YogBlockPos,
1235 to: YogBlockPos,
1236 state: YogStr,
1237 ) -> i32,
1238 pub scan_region:
1240 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1241
1242 pub entity_set_dimensions:
1246 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32) -> bool,
1247
1248 pub entity_data_set:
1253 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, data: *const u8, len: u32, flags: u32) -> bool,
1254 pub entity_data_get:
1256 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1257}
1258
1259unsafe impl Send for YogServer {}
1261unsafe impl Sync for YogServer {}
1262
1263#[repr(C)]
1270#[derive(Copy, Clone)]
1271pub struct YogChunkWriterApi {
1272 pub chunk_x: i32,
1274 pub chunk_z: i32,
1276 pub min_y: i32,
1278 pub height: i32,
1280 pub ctx: *mut c_void,
1282 pub set_block:
1285 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1286}
1287
1288unsafe impl Send for YogChunkWriterApi {}
1289unsafe impl Sync for YogChunkWriterApi {}
1290
1291pub type YogChunkGeneratorFn =
1294 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1295
1296#[repr(C)]
1305pub struct YogApi {
1306 pub abi_version: u32,
1307 pub size: u32,
1309 pub ctx: *mut c_void,
1311 pub server: *const YogServer,
1313
1314 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1317 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1318 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1319 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1320 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1321 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1322 pub on_attack_entity:
1323 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1324 pub on_entity_damage:
1325 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1326 pub on_entity_death:
1327 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1328 pub on_entity_spawn:
1329 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1330 pub on_player_place_block:
1331 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1332 pub on_player_death:
1333 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1334 pub on_player_respawn:
1335 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1336 pub on_advancement:
1337 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1338 pub on_entity_interact:
1340 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1341 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1342 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1343 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1345 pub on_item_insert: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemInsertFn),
1346 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1347 pub on_container_open:
1348 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1349 pub on_container_close:
1350 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1351 pub on_projectile_hit:
1352 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1353 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1354 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1355 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1356
1357 pub on_packet:
1359 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1360 pub on_client_packet:
1361 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1362
1363 pub register_command:
1365 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1366 pub register_typed_command: unsafe extern "C" fn(
1367 ctx: *mut c_void,
1368 name: YogStr,
1369 schema: YogStr,
1370 ud: *mut c_void,
1371 h: YogCommandFn,
1372 ),
1373
1374 pub register_content: unsafe extern "C" fn(ctx: *mut c_void, kind: YogStr, id: YogStr, data: *const u8, len: usize),
1382
1383 pub schedule_once: unsafe extern "C" fn(
1385 ctx: *mut c_void,
1386 delay_ticks: u64,
1387 ud: *mut c_void,
1388 h: YogScheduledFn,
1389 ),
1390 pub schedule_repeating: unsafe extern "C" fn(
1391 ctx: *mut c_void,
1392 period_ticks: u64,
1393 ud: *mut c_void,
1394 h: YogScheduledFn,
1395 ),
1396
1397 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1399 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1400 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1401 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1402 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1403
1404 pub on_world_render:
1409 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1410
1411 pub register_ui: unsafe extern "C" fn(
1416 ctx: *mut c_void,
1417 ui_id: YogStr,
1418 layout_json: YogStr,
1419 ud: *mut c_void,
1420 h: YogUIEventFn,
1421 ),
1422
1423 pub on_ui_render:
1430 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1431
1432 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1438
1439 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1446 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1449
1450 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1455
1456 pub interop_export:
1460 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1461 pub interop_import:
1464 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1465
1466 pub register_chunk_generator:
1471 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1472
1473 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1478 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1482
1483 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1491
1492 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1497 pub client_play_sound: unsafe extern "C" fn(
1501 ctx: *mut c_void,
1502 sound_id: YogStr,
1503 volume: f32,
1504 pitch: f32,
1505 looping: bool,
1506 ) -> u32,
1507 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1509 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1512 pub client_set_block_tint: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, color: i64),
1515 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1517
1518 pub on_book_page:
1522 unsafe extern "C" fn(ctx: *mut c_void, drawer: YogStr, ud: *mut c_void, f: YogPageDrawFn),
1523
1524 pub on_item_tooltip: unsafe extern "C" fn(
1529 ctx: *mut c_void,
1530 item: YogStr,
1531 ud: *mut c_void,
1532 size: YogTooltipSizeFn,
1533 draw: YogTooltipDrawFn,
1534 ),
1535
1536 pub is_mod_loaded: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
1540 pub java_call: unsafe extern "C" fn(ctx: *mut c_void, expr: YogStr, args: YogStr) -> YogOwnedStr,
1547
1548 pub on_item_text: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, ud: *mut c_void, f: YogItemTextFn),
1552
1553 pub on_machine_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogMachineCraftFn),
1556
1557 pub client_body_track: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, on: bool),
1560 pub client_body_track_type: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, on: bool),
1562 pub on_body: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogBodyFn),
1564 pub on_camera: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogCameraFn),
1566 pub on_travel: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogTravelFn),
1568
1569 pub client_set_dimensions: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32),
1573
1574 pub client_entity_data:
1578 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1579}
1580
1581pub mod ui_flags {
1583 pub const MODAL: u32 = 1;
1585 pub const PAUSE: u32 = 1 << 1;
1587 pub const NO_BACKGROUND: u32 = 1 << 2;
1589}
1590
1591unsafe impl Send for YogApi {}
1592unsafe impl Sync for YogApi {}
1593
1594#[cfg(test)]
1595mod tests {
1596 use super::*;
1597 use std::mem::{align_of, size_of};
1598
1599 fn layout_fingerprint() -> u64 {
1601 macro_rules! layouts {
1602 ($($t:ty),* $(,)?) => { [$((stringify!($t), size_of::<$t>(), align_of::<$t>())),*] };
1603 }
1604 let all = layouts!(
1605 YogStr, YogOwnedStr, YogBlockPos, YogVec3, YogBlockBreakEvent, YogChatEvent, YogPlayerEvent,
1606 YogUseItemEvent, YogUseBlockEvent, YogAttackEntityEvent, YogEntityDamageEvent, YogEntityDeathEvent,
1607 YogEntitySpawnEvent, YogPlayerDeathEvent, YogPlayerRespawnEvent, YogAdvancementEvent,
1608 YogEntityInteractEvent, YogCraftEvent, YogExplosionEvent, YogItemPickupEvent, YogItemInsertEvent, YogPlayerMoveEvent,
1609 YogContainerOpenEvent, YogContainerCloseEvent, YogProjectileHitEvent, YogPlaceBlockEvent,
1610 YogPacketEvent, YogCommandEvent,
1611 YogKeyPressEvent, YogGfxApi, YogServer, YogChunkWriterApi, YogApi,
1612 );
1613 let mut h: u64 = 0xcbf2_9ce4_8422_2325;
1615 for (name, size, align) in all {
1616 for b in name.bytes().chain((size as u64).to_le_bytes()).chain((align as u64).to_le_bytes()) {
1617 h = (h ^ b as u64).wrapping_mul(0x0100_0000_01b3);
1618 }
1619 }
1620 h
1621 }
1622
1623 #[test]
1627 #[cfg(target_pointer_width = "64")]
1628 fn the_layout_matches_its_version() {
1629 assert_eq!((ABI_VERSION, layout_fingerprint()), (30002, 0x73ec_636f_fee7_29d4), "layout fingerprint: {:#x}", layout_fingerprint());
1630 }
1631
1632 #[test]
1633 fn strings_cross_and_come_back() {
1634 let s = YogStr::from_str("Ünïcode ✓");
1635 assert_eq!(unsafe { s.as_str() }, "Ünïcode ✓");
1636 assert!(YogStr::EMPTY.is_empty());
1637 assert_eq!(unsafe { YogStr::EMPTY.as_str() }, "");
1638 let owned = YogOwnedStr::from_string("runtime".to_string());
1639 assert!(!owned.is_none() && owned.len == 7);
1640 assert!(YogOwnedStr::NONE.is_none());
1641 drop(unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(owned.ptr, owned.len as usize)) });
1643 }
1644}