1use std::os::raw::c_void;
17
18pub const ABI_MAJOR: u32 = 3;
21pub const ABI_MINOR: u32 = 4;
22pub const ABI_VERSION: u32 = ABI_MAJOR * 10_000 + ABI_MINOR;
24
25pub const fn compatible(version: u32) -> bool {
28 version / 10_000 == ABI_MAJOR && version % 10_000 <= ABI_MINOR
29}
30
31#[repr(C)]
36#[derive(Copy, Clone)]
37pub struct YogStr {
38 pub ptr: *const u8,
39 pub len: u32,
40}
41
42impl YogStr {
43 pub const EMPTY: Self = Self {
44 ptr: std::ptr::null(),
45 len: 0,
46 };
47
48 #[allow(clippy::should_implement_trait)]
50 #[inline]
51 pub fn from_str(s: &str) -> Self {
52 Self {
53 ptr: s.as_ptr(),
54 len: s.len() as u32,
55 }
56 }
57
58 #[inline]
59 pub fn is_empty(self) -> bool {
60 self.len == 0 || self.ptr.is_null()
61 }
62
63 #[inline]
68 pub unsafe fn as_str<'a>(self) -> &'a str {
69 unsafe {
70 if self.ptr.is_null() || self.len == 0 {
71 return "";
72 }
73 std::str::from_utf8_unchecked(std::slice::from_raw_parts(self.ptr, self.len as usize))
74 }
75 }
76}
77
78#[repr(C)]
82#[derive(Copy, Clone)]
83pub struct YogOwnedStr {
84 pub ptr: *mut u8,
85 pub len: u32,
86}
87
88impl YogOwnedStr {
89 pub const NONE: Self = Self {
90 ptr: std::ptr::null_mut(),
91 len: 0,
92 };
93
94 pub fn from_string(s: String) -> Self {
96 let len = s.len() as u32;
97 let ptr = Box::into_raw(s.into_bytes().into_boxed_slice()) as *mut u8;
98 Self { ptr, len }
99 }
100
101 #[inline]
102 pub fn is_none(self) -> bool {
103 self.ptr.is_null()
104 }
105}
106
107#[repr(C)]
109#[derive(Copy, Clone)]
110pub struct YogBlockPos {
111 pub x: i32,
112 pub y: i32,
113 pub z: i32,
114}
115
116#[repr(C)]
118#[derive(Copy, Clone)]
119pub struct YogVec3 {
120 pub x: f64,
121 pub y: f64,
122 pub z: f64,
123}
124
125#[repr(C)]
128pub struct YogBlockBreakEvent {
129 pub player: YogStr,
130 pub block: YogStr,
131 pub pos: YogBlockPos,
132 pub dimension: YogStr,
134}
135
136#[repr(C)]
137pub struct YogChatEvent {
138 pub player: YogStr,
139 pub message: YogStr,
140 pub dimension: YogStr,
141}
142
143#[repr(C)]
145pub struct YogPlayerEvent {
146 pub player: YogStr,
147 pub uuid: YogStr,
148 pub dimension: YogStr,
149}
150
151#[repr(C)]
152pub struct YogUseItemEvent {
153 pub player: YogStr,
154 pub item: YogStr,
155 pub sneaking: bool,
157 pub dimension: YogStr,
158}
159
160#[repr(C)]
161pub struct YogUseBlockEvent {
162 pub player: YogStr,
163 pub block: YogStr,
164 pub pos: YogBlockPos,
165 pub dimension: YogStr,
166 pub sneaking: bool,
168}
169
170#[repr(C)]
171pub struct YogAttackEntityEvent {
172 pub player: YogStr,
173 pub target_type: YogStr,
174 pub target_uuid: YogStr,
175 pub dimension: YogStr,
176}
177
178#[repr(C)]
179pub struct YogEntityDamageEvent {
180 pub entity_type: YogStr,
181 pub uuid: YogStr,
182 pub amount: f32,
183 pub source: YogStr,
184 pub dimension: YogStr,
185}
186
187#[repr(C)]
188pub struct YogEntityDeathEvent {
189 pub entity_type: YogStr,
190 pub uuid: YogStr,
191 pub source: YogStr,
192 pub dimension: YogStr,
193}
194
195#[repr(C)]
196pub struct YogEntitySpawnEvent {
197 pub entity_type: YogStr,
198 pub uuid: YogStr,
199 pub dimension: YogStr,
200}
201
202#[repr(C)]
205pub struct YogPlayerDeathEvent {
206 pub player: YogStr,
207 pub uuid: YogStr,
208 pub source: YogStr,
210 pub dimension: YogStr,
211}
212
213#[repr(C)]
215pub struct YogPlayerRespawnEvent {
216 pub player: YogStr,
217 pub uuid: YogStr,
218 pub at_anchor: bool,
220 pub dimension: YogStr,
222}
223
224#[repr(C)]
226pub struct YogAdvancementEvent {
227 pub player: YogStr,
228 pub uuid: YogStr,
229 pub advancement: YogStr,
231 pub dimension: YogStr,
232}
233
234#[repr(C)]
237pub struct YogEntityInteractEvent {
238 pub player: YogStr,
239 pub player_uuid: YogStr,
240 pub entity_type: YogStr,
241 pub entity_uuid: YogStr,
242 pub hand: YogStr,
244 pub dimension: YogStr,
245}
246
247#[repr(C)]
249pub struct YogCraftEvent {
250 pub player: YogStr,
251 pub player_uuid: YogStr,
252 pub result_item: YogStr,
253 pub result_count: u32,
254 pub dimension: YogStr,
255}
256
257#[repr(C)]
263pub struct YogMachineCraftEvent {
264 pub machine: YogStr,
266 pub kind: YogStr,
268 pub recipe: YogStr,
269 pub result_item: YogStr,
270 pub result_count: u32,
271 pub values: YogStr,
273 pub pos: YogBlockPos,
274 pub dimension: YogStr,
275 pub player: YogStr,
276}
277
278#[repr(C)]
281pub struct YogExplosionEvent {
282 pub dimension: YogStr,
283 pub x: f64,
284 pub y: f64,
285 pub z: f64,
286 pub power: f32,
287 pub cause_uuid: YogStr,
289}
290
291#[repr(C)]
296pub struct YogItemInsertEvent {
297 pub block: YogStr,
298 pub pos: YogBlockPos,
299 pub dimension: YogStr,
300 pub item_id: YogStr,
301 pub count: u32,
302 pub nbt: YogStr,
304}
305
306#[repr(C)]
308pub struct YogItemPickupEvent {
309 pub player: YogStr,
310 pub player_uuid: YogStr,
311 pub item_id: YogStr,
313 pub item_count: u32,
314 pub entity_uuid: YogStr,
316 pub dimension: YogStr,
317}
318
319#[repr(C)]
321pub struct YogPlayerMoveEvent {
322 pub player: YogStr,
323 pub player_uuid: YogStr,
324 pub x: f64,
325 pub y: f64,
326 pub z: f64,
327 pub yaw: f32,
328 pub pitch: f32,
329 pub dimension: YogStr,
330}
331
332#[repr(C)]
336pub struct YogContainerOpenEvent {
337 pub player: YogStr,
338 pub player_uuid: YogStr,
339 pub container_type: YogStr,
340 pub dimension: YogStr,
341}
342
343#[repr(C)]
345pub struct YogContainerCloseEvent {
346 pub player: YogStr,
347 pub player_uuid: YogStr,
348 pub dimension: YogStr,
349}
350
351#[repr(C)]
354pub struct YogProjectileHitEvent {
355 pub projectile_type: YogStr,
357 pub projectile_uuid: YogStr,
358 pub shooter_uuid: YogStr,
360 pub hit_type: YogStr,
362 pub hit_entity_uuid: YogStr,
364 pub x: f64,
365 pub y: f64,
366 pub z: f64,
367 pub dimension: YogStr,
368}
369
370#[repr(C)]
372pub struct YogPlaceBlockEvent {
373 pub player: YogStr,
374 pub block: YogStr,
375 pub pos: YogBlockPos,
376 pub dimension: YogStr,
377 pub sneaking: bool,
379}
380
381#[repr(C)]
382pub struct YogPacketEvent {
383 pub channel: YogStr,
384 pub player: YogStr, pub payload: *const u8,
386 pub payload_len: u32,
387}
388
389#[repr(C)]
390pub struct YogCommandEvent {
391 pub name: YogStr,
392 pub args: YogStr,
393 pub source: YogStr,
394 pub uuid: YogStr,
395 pub dimension: YogStr,
397}
398
399#[repr(C)]
403#[derive(Copy, Clone)]
404pub struct YogKeyPressEvent {
405 pub key_code: i32,
407 pub scan_code: i32,
408 pub action: i32,
410 pub modifiers: i32,
412}
413
414pub type YogBlockBreakFn =
426 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogBlockBreakEvent, u8) -> bool;
427pub type YogChatFn =
428 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogChatEvent, u8) -> bool;
429pub type YogPlayerFn =
430 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerEvent, u8) -> bool;
431pub type YogUseItemFn =
432 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogUseItemEvent, u8) -> bool;
433pub type YogUseBlockFn =
434 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogUseBlockEvent, u8) -> bool;
435pub type YogAttackEntityFn =
436 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogAttackEntityEvent, u8) -> bool;
437pub type YogEntityDamageFn =
438 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityDamageEvent, u8) -> bool;
439pub type YogEntityDeathFn =
440 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityDeathEvent, u8) -> bool;
441pub type YogEntitySpawnFn =
442 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntitySpawnEvent, u8) -> bool;
443pub type YogPlaceBlockFn =
444 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlaceBlockEvent, u8) -> bool;
445pub type YogPlayerDeathFn =
446 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerDeathEvent, u8) -> bool;
447pub type YogPlayerRespawnFn =
448 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerRespawnEvent, u8) -> bool;
449pub type YogAdvancementFn =
450 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogAdvancementEvent, u8) -> bool;
451pub type YogEntityInteractFn =
452 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityInteractEvent, u8) -> bool;
453pub type YogCraftFn =
454 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogCraftEvent, u8) -> bool;
455pub type YogMachineCraftFn =
456 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogMachineCraftEvent, u8) -> bool;
457pub type YogExplosionFn =
458 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogExplosionEvent, u8) -> bool;
459pub type YogItemInsertFn =
460 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogItemInsertEvent, u8) -> bool;
461pub type YogItemPickupFn =
462 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogItemPickupEvent, u8) -> bool;
463pub type YogPlayerMoveFn =
464 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerMoveEvent, u8) -> bool;
465pub type YogContainerOpenFn =
466 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogContainerOpenEvent, u8) -> bool;
467pub type YogContainerCloseFn =
468 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogContainerCloseEvent, u8) -> bool;
469pub type YogProjectileHitFn =
470 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogProjectileHitEvent, u8) -> bool;
471
472pub type YogPacketFn = unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPacketEvent);
474pub type YogServerFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
476pub type YogLootFn =
481 unsafe extern "C" fn(ud: *mut c_void, server: *const YogServer, loot: *const u8, len: usize, sink: *mut c_void, write: YogBytesSink);
482pub type YogEntityTickFn = unsafe extern "C" fn(*mut c_void, *const YogServer, YogStr);
484pub type YogCommandFn = unsafe extern "C" fn(
486 ud: *mut c_void,
487 srv: *const YogServer,
488 ev: *const YogCommandEvent,
489 reply_buf: *mut u8,
490 reply_cap: u32,
491 reply_len: *mut u32,
492);
493pub type YogScheduledFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
495
496pub type YogClientFn = unsafe extern "C" fn(ud: *mut c_void);
500pub type YogUIEventFn = unsafe extern "C" fn(ud: *mut c_void, ui_id: YogStr, event_id: YogStr);
507pub type YogHudRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
510pub type YogPageDrawFn = unsafe extern "C" fn(
514 ud: *mut c_void,
515 gfx: *const YogGfxApi,
516 data: *const u8,
517 len: usize,
518 x: f32,
519 y: f32,
520 w: f32,
521 h: f32,
522);
523pub type YogTooltipSizeFn =
526 unsafe extern "C" fn(ud: *mut c_void, item: YogStr, snbt: YogStr, w: *mut f32, h: *mut f32) -> bool;
527pub type YogTooltipDrawFn = unsafe extern "C" fn(
530 ud: *mut c_void,
531 gfx: *const YogGfxApi,
532 item: YogStr,
533 snbt: YogStr,
534 x: f32,
535 y: f32,
536 w: f32,
537 h: f32,
538);
539pub type YogTextSink = unsafe extern "C" fn(sink: *mut c_void, text: YogStr);
542pub type YogBytesSink = unsafe extern "C" fn(sink: *mut c_void, data: *const u8, len: usize);
548pub type YogBodyFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const u8, len: usize, sink: *mut c_void, write: YogBytesSink);
551pub type YogCameraFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const YogCameraFrame, out: *mut YogCameraOut);
554pub type YogTravelFn = unsafe extern "C" fn(ud: *mut c_void, frame: *const YogTravelFrame, velocity: *mut [f32; 3]) -> bool;
556
557#[repr(C)]
559#[derive(Copy, Clone)]
560pub struct YogCameraFrame {
561 pub uuid: YogStr,
562 pub partial: f32,
563 pub pos: [f64; 3],
564 pub yaw: f32,
565 pub pitch: f32,
566 pub detached: bool,
567 pub flags: u32,
568}
569
570#[repr(C)]
572#[derive(Copy, Clone)]
573pub struct YogCameraOut {
574 pub local_offset: [f32; 3],
575 pub world_offset: [f32; 3],
576 pub yaw: f32,
577 pub pitch: f32,
578 pub roll: f32,
579 pub fov: f32,
580}
581
582#[repr(C)]
584#[derive(Copy, Clone)]
585pub struct YogTravelFrame {
586 pub uuid: YogStr,
587 pub velocity: [f32; 3],
588 pub look: [f32; 3],
589 pub yaw: f32,
590 pub pitch: f32,
591 pub forward: f32,
592 pub strafe: f32,
593 pub jumping: bool,
594 pub sneaking: bool,
595 pub gravity: f32,
596 pub flags: u32,
597}
598
599pub type YogItemTextFn =
600 unsafe extern "C" fn(ud: *mut c_void, item: YogStr, snbt: YogStr, sink: *mut c_void, write: YogTextSink) -> bool;
601pub type YogWorldRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
604pub type YogKeyPressFn = unsafe extern "C" fn(ud: *mut c_void, ev: *const YogKeyPressEvent) -> bool;
606pub type YogScreenFn = unsafe extern "C" fn(ud: *mut c_void, screen_class: YogStr) -> bool;
609
610#[repr(C)]
626#[derive(Copy, Clone)]
627pub struct YogGfxApi {
628 pub screen_w: i32,
631 pub screen_h: i32,
633 pub delta_tick: f32,
635 pub scale_factor: f32,
638 pub view_proj: [f32; 16],
641 pub camera_pos: [f32; 3],
643 pub player_pos: [f32; 3],
646 pub _pad1: f32,
647
648 pub buf_create: unsafe extern "C" fn() -> u32,
651 pub buf_delete: unsafe extern "C" fn(handle: u32),
653 pub buf_data: unsafe extern "C" fn(handle: u32, bytes: *const u8, len: u32, dynamic: bool),
656 pub buf_subdata: unsafe extern "C" fn(handle: u32, offset: u32, bytes: *const u8, len: u32),
658
659 pub vao_create: unsafe extern "C" fn() -> u32,
662 pub vao_delete: unsafe extern "C" fn(handle: u32),
664 pub vao_attrib: unsafe extern "C" fn(
667 vao: u32,
668 vbo: u32,
669 index: u32,
670 components: u8,
671 dtype: u8,
672 normalized: bool,
673 stride: u32,
674 offset: u32,
675 ),
676 pub vao_set_ebo: unsafe extern "C" fn(vao: u32, ebo: u32),
678
679 pub prog_create: unsafe extern "C" fn(vert: YogStr, frag: YogStr, out: *mut u32) -> bool,
683 pub prog_delete: unsafe extern "C" fn(handle: u32),
685 pub prog_uniform_1i: unsafe extern "C" fn(prog: u32, name: YogStr, v: i32),
686 pub prog_uniform_1f: unsafe extern "C" fn(prog: u32, name: YogStr, v: f32),
687 pub prog_uniform_2f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32),
688 pub prog_uniform_3f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32),
689 pub prog_uniform_4f:
690 unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32, w: f32),
691 pub prog_uniform_mat4: unsafe extern "C" fn(prog: u32, name: YogStr, col_major: *const f32),
693
694 pub tex_create: unsafe extern "C" fn(w: u32, h: u32, rgba: *const u8, linear: bool) -> u32,
698 pub tex_delete: unsafe extern "C" fn(handle: u32),
700 pub tex_bind: unsafe extern "C" fn(unit: u32, handle: u32),
702 pub tex_from_mc: unsafe extern "C" fn(id: YogStr) -> u32,
706
707 pub draw_arrays: unsafe extern "C" fn(vao: u32, prog: u32, mode: u8, first: u32, count: u32),
711 pub draw_elements:
714 unsafe extern "C" fn(vao: u32, ebo: u32, prog: u32, mode: u8, count: u32, u32_idx: bool),
715
716 pub set_blend: unsafe extern "C" fn(enabled: bool, src: u32, dst: u32),
719 pub set_depth: unsafe extern "C" fn(test: bool, write: bool),
721 pub set_scissor: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
725 pub clear_scissor: unsafe extern "C" fn(),
727 pub set_viewport: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
729
730 pub draw2d_rect: unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, color: u32),
733 pub draw2d_gradient:
735 unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, top: u32, bottom: u32),
736 pub draw2d_text: unsafe extern "C" fn(text: YogStr, x: f32, y: f32, color: u32, shadow: bool),
738
739 pub draw2d_item: unsafe extern "C" fn(id: YogStr, x: f32, y: f32, size: f32),
745
746 pub draw2d_text_font:
752 unsafe extern "C" fn(text: YogStr, font: YogStr, x: f32, y: f32, color: u32, shadow: bool),
753 pub text_width: unsafe extern "C" fn(text: YogStr, font: YogStr) -> f32,
758
759 pub draw2d_image: unsafe extern "C" fn(
770 source: YogStr,
771 x: f32,
772 y: f32,
773 w: f32,
774 h: f32,
775 u: f32,
776 v: f32,
777 uw: f32,
778 vh: f32,
779 tint: u32,
780 ),
781 pub image_size: unsafe extern "C" fn(source: YogStr, w: *mut f32, h: *mut f32) -> bool,
786
787 pub draw2d_svg: unsafe extern "C" fn(data: YogStr, x: f32, y: f32, w: f32, h: f32),
791 pub draw2d_entity:
795 unsafe extern "C" fn(entity: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
796
797 pub draw2d_text_scaled: unsafe extern "C" fn(
801 text: YogStr,
802 font: YogStr,
803 x: f32,
804 y: f32,
805 scale: f32,
806 color: u32,
807 shadow: bool,
808 ),
809 pub draw2d_blocks:
813 unsafe extern "C" fn(blocks: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
814}
815
816unsafe impl Send for YogGfxApi {}
817unsafe impl Sync for YogGfxApi {}
818
819#[repr(C)]
829pub struct YogServer {
830 pub ctx: *mut c_void,
831 pub abi_version: u32,
832 pub size: u32,
835
836 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
838
839 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
841
842 pub get_block:
844 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
845 pub set_block: unsafe extern "C" fn(
846 ctx: *mut c_void,
847 dim: YogStr,
848 pos: YogBlockPos,
849 block: YogStr,
850 ) -> bool,
851 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
852 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
853 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
854 pub set_weather:
855 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
856
857 pub give_item:
859 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
860 pub player_teleport:
861 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
862 pub send_to_player: unsafe extern "C" fn(
863 ctx: *mut c_void,
864 player: YogStr,
865 channel: YogStr,
866 data: *const u8,
867 len: u32,
868 ) -> bool,
869 pub send_to_server:
870 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
871 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
872 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
873 pub send_title: unsafe extern "C" fn(
874 ctx: *mut c_void,
875 player: YogStr,
876 title: YogStr,
877 sub: YogStr,
878 fi: i32,
879 stay: i32,
880 fo: i32,
881 ) -> bool,
882 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
883 pub play_sound: unsafe extern "C" fn(
884 ctx: *mut c_void,
885 dim: YogStr,
886 pos: YogVec3,
887 sound: YogStr,
888 vol: f32,
889 pitch: f32,
890 ) -> bool,
891 pub play_sound_player: unsafe extern "C" fn(
892 ctx: *mut c_void,
893 player: YogStr,
894 sound: YogStr,
895 vol: f32,
896 pitch: f32,
897 ) -> bool,
898
899 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
901 pub entity_position:
902 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
903 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
904 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
905 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
906 pub spawn_entity: unsafe extern "C" fn(
907 ctx: *mut c_void,
908 type_id: YogStr,
909 dim: YogStr,
910 pos: YogVec3,
911 ) -> YogOwnedStr,
912 pub entity_add_effect: unsafe extern "C" fn(
913 ctx: *mut c_void,
914 uuid: YogStr,
915 fx: YogStr,
916 dur: i32,
917 amp: u8,
918 particles: bool,
919 ) -> bool,
920 pub entity_remove_effect:
921 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
922 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
923 pub entity_velocity:
924 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
925 pub entity_set_velocity:
926 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
927 pub entity_add_velocity:
928 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
929
930 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
932 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
933 pub drop_loot:
934 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
935
936 pub scoreboard_get:
938 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
939 pub scoreboard_set:
940 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
941 pub scoreboard_add: unsafe extern "C" fn(
942 ctx: *mut c_void,
943 obj: YogStr,
944 player: YogStr,
945 delta: i32,
946 out: *mut i32,
947 ) -> bool,
948
949 pub bossbar_create: unsafe extern "C" fn(
951 ctx: *mut c_void,
952 id: YogStr,
953 title: YogStr,
954 color: YogStr,
955 style: YogStr,
956 ) -> bool,
957 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
958 pub bossbar_set_title:
959 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
960 pub bossbar_set_progress:
961 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
962 pub bossbar_set_color:
963 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
964 pub bossbar_add_player:
965 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
966 pub bossbar_remove_player:
967 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
968 pub bossbar_set_visible:
969 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
970
971 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
973
974 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
977
978 pub get_block_nbt:
981 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
982 pub set_block_nbt:
984 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
985
986 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
989 pub player_set_slot: unsafe extern "C" fn(
991 ctx: *mut c_void,
992 player: YogStr,
993 slot: u32,
994 item_id: YogStr,
995 count: u32,
996 ) -> bool,
997
998 pub get_inventory_slot: unsafe extern "C" fn(
1002 ctx: *mut c_void,
1003 dim: YogStr,
1004 pos: YogBlockPos,
1005 slot: u32,
1006 ) -> YogOwnedStr,
1007 pub set_inventory_slot: unsafe extern "C" fn(
1011 ctx: *mut c_void,
1012 dim: YogStr,
1013 pos: YogBlockPos,
1014 slot: u32,
1015 item_id: YogStr,
1016 count: u32,
1017 ) -> bool,
1018
1019 pub player_teleport_dim:
1021 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1022 pub entity_teleport_dim:
1023 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1024
1025 pub world_entity_count:
1028 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
1029
1030 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1033 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
1035
1036 pub spawn_particles: unsafe extern "C" fn(
1041 ctx: *mut c_void,
1042 dim: YogStr,
1043 pos: YogVec3,
1044 particle_type: YogStr,
1045 count: i32,
1046 dx: f64,
1047 dy: f64,
1048 dz: f64,
1049 speed: f64,
1050 ) -> bool,
1051
1052 pub entity_attribute_get:
1057 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
1058 pub entity_attribute_set: unsafe extern "C" fn(
1060 ctx: *mut c_void,
1061 uuid: YogStr,
1062 attribute_id: YogStr,
1063 value: f64,
1064 ) -> bool,
1065
1066 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1070 pub set_held_item_nbt:
1073 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1074
1075 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1078 pub set_offhand_item_nbt:
1081 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1082 pub get_slot_item:
1085 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
1086 pub set_slot_item: unsafe extern "C" fn(
1089 ctx: *mut c_void,
1090 player: YogStr,
1091 slot: u32,
1092 item_id: YogStr,
1093 count: u32,
1094 snbt: YogStr,
1095 ) -> bool,
1096
1097 pub entity_rotation:
1101 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
1102
1103 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1108 pub entities_in_box: unsafe extern "C" fn(
1110 ctx: *mut c_void,
1111 dim: YogStr,
1112 min: YogVec3,
1113 max: YogVec3,
1114 ) -> YogOwnedStr,
1115 pub raycast_block: unsafe extern "C" fn(
1117 ctx: *mut c_void,
1118 dim: YogStr,
1119 from: YogVec3,
1120 to: YogVec3,
1121 ) -> YogOwnedStr,
1122 pub raycast_entity: unsafe extern "C" fn(
1124 ctx: *mut c_void,
1125 dim: YogStr,
1126 from: YogVec3,
1127 to: YogVec3,
1128 exclude: YogStr,
1129 ) -> YogOwnedStr,
1130 pub block_info:
1132 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1133 pub break_block: unsafe extern "C" fn(
1134 ctx: *mut c_void,
1135 dim: YogStr,
1136 pos: YogBlockPos,
1137 drop: bool,
1138 breaker: YogStr,
1139 ) -> bool,
1140 pub place_block_from_slot: unsafe extern "C" fn(
1141 ctx: *mut c_void,
1142 player: YogStr,
1143 slot: u32,
1144 dim: YogStr,
1145 pos: YogBlockPos,
1146 ) -> bool,
1147 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1148 pub explode: unsafe extern "C" fn(
1149 ctx: *mut c_void,
1150 dim: YogStr,
1151 pos: YogVec3,
1152 power: f32,
1153 fire: bool,
1154 source: YogStr,
1155 ) -> bool,
1156 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1158 pub entity_damage: unsafe extern "C" fn(
1159 ctx: *mut c_void,
1160 uuid: YogStr,
1161 amount: f32,
1162 damage_type: YogStr,
1163 attacker: YogStr,
1164 ) -> bool,
1165 pub entity_set_fire_ticks:
1166 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1167 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1168 pub player_set_may_fly:
1169 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1170 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1172 pub spawn_item: unsafe extern "C" fn(
1174 ctx: *mut c_void,
1175 dim: YogStr,
1176 pos: YogVec3,
1177 vel: YogVec3,
1178 item_id: YogStr,
1179 count: u32,
1180 snbt: YogStr,
1181 ) -> YogOwnedStr,
1182 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1184 pub item_entity_set_stack: unsafe extern "C" fn(
1185 ctx: *mut c_void,
1186 uuid: YogStr,
1187 item_id: YogStr,
1188 count: u32,
1189 snbt: YogStr,
1190 ) -> bool,
1191 pub actionbar_json:
1194 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1195 pub use_item_on_block: unsafe extern "C" fn(
1197 ctx: *mut c_void,
1198 dim: YogStr,
1199 pos: YogBlockPos,
1200 face: u8,
1201 item_id: YogStr,
1202 player: YogStr,
1203 ) -> bool,
1204 pub pour_fluid: unsafe extern "C" fn(
1205 ctx: *mut c_void,
1206 dim: YogStr,
1207 pos: YogBlockPos,
1208 bucket_item_id: YogStr,
1209 ) -> bool,
1210 pub has_entity_tag:
1211 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1212 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1214 pub place_feature: unsafe extern "C" fn(
1215 ctx: *mut c_void,
1216 dim: YogStr,
1217 pos: YogBlockPos,
1218 feature_id: YogStr,
1219 ) -> bool,
1220
1221 pub set_item_cooldown:
1223 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1224 pub entity_vehicle: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1226 pub entity_passengers: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1228 pub entity_mount:
1230 unsafe extern "C" fn(ctx: *mut c_void, rider: YogStr, vehicle: YogStr, force: bool) -> bool,
1231 pub entity_dismount: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
1233 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1235 pub entity_set_fall_distance: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, distance: f32) -> bool,
1237 pub redstone_signal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1239 pub set_redstone_output:
1240 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1241 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1243 pub set_block_state:
1244 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1245 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1246 pub world_set_thunder:
1247 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1248 pub fill_region: unsafe extern "C" fn(
1250 ctx: *mut c_void,
1251 dim: YogStr,
1252 from: YogBlockPos,
1253 to: YogBlockPos,
1254 state: YogStr,
1255 ) -> i32,
1256 pub scan_region:
1258 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1259
1260 pub entity_set_dimensions:
1264 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32) -> bool,
1265
1266 pub entity_data_set:
1271 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, data: *const u8, len: u32, flags: u32) -> bool,
1272 pub entity_data_get:
1274 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1275}
1276
1277unsafe impl Send for YogServer {}
1279unsafe impl Sync for YogServer {}
1280
1281#[repr(C)]
1288#[derive(Copy, Clone)]
1289pub struct YogChunkWriterApi {
1290 pub chunk_x: i32,
1292 pub chunk_z: i32,
1294 pub min_y: i32,
1296 pub height: i32,
1298 pub ctx: *mut c_void,
1300 pub set_block:
1303 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1304}
1305
1306unsafe impl Send for YogChunkWriterApi {}
1307unsafe impl Sync for YogChunkWriterApi {}
1308
1309pub type YogChunkGeneratorFn =
1312 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1313
1314#[repr(C)]
1323pub struct YogApi {
1324 pub abi_version: u32,
1325 pub size: u32,
1327 pub ctx: *mut c_void,
1329 pub server: *const YogServer,
1331
1332 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1335 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1336 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1337 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1338 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1339 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1340 pub on_attack_entity:
1341 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1342 pub on_entity_damage:
1343 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1344 pub on_entity_death:
1345 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1346 pub on_entity_spawn:
1347 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1348 pub on_player_place_block:
1349 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1350 pub on_player_death:
1351 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1352 pub on_player_respawn:
1353 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1354 pub on_advancement:
1355 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1356 pub on_entity_interact:
1358 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1359 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1360 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1361 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1363 pub on_item_insert: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemInsertFn),
1364 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1365 pub on_container_open:
1366 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1367 pub on_container_close:
1368 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1369 pub on_projectile_hit:
1370 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1371 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1372 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1373 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1374
1375 pub on_packet:
1377 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1378 pub on_client_packet:
1379 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1380
1381 pub register_command:
1383 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1384 pub register_typed_command: unsafe extern "C" fn(
1385 ctx: *mut c_void,
1386 name: YogStr,
1387 schema: YogStr,
1388 ud: *mut c_void,
1389 h: YogCommandFn,
1390 ),
1391
1392 pub register_content: unsafe extern "C" fn(ctx: *mut c_void, kind: YogStr, id: YogStr, data: *const u8, len: usize),
1400
1401 pub schedule_once: unsafe extern "C" fn(
1403 ctx: *mut c_void,
1404 delay_ticks: u64,
1405 ud: *mut c_void,
1406 h: YogScheduledFn,
1407 ),
1408 pub schedule_repeating: unsafe extern "C" fn(
1409 ctx: *mut c_void,
1410 period_ticks: u64,
1411 ud: *mut c_void,
1412 h: YogScheduledFn,
1413 ),
1414
1415 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1417 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1418 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1419 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1420 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1421
1422 pub on_world_render:
1427 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1428
1429 pub register_ui: unsafe extern "C" fn(
1434 ctx: *mut c_void,
1435 ui_id: YogStr,
1436 layout_json: YogStr,
1437 ud: *mut c_void,
1438 h: YogUIEventFn,
1439 ),
1440
1441 pub on_ui_render:
1448 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1449
1450 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1456
1457 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1464 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1467
1468 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1473
1474 pub interop_export:
1478 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1479 pub interop_import:
1482 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1483
1484 pub register_chunk_generator:
1489 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1490
1491 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1496 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1500
1501 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1509
1510 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1515 pub client_play_sound: unsafe extern "C" fn(
1519 ctx: *mut c_void,
1520 sound_id: YogStr,
1521 volume: f32,
1522 pitch: f32,
1523 looping: bool,
1524 ) -> u32,
1525 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1527 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1530 pub client_set_block_tint: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, color: i64),
1533 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1535
1536 pub on_book_page:
1540 unsafe extern "C" fn(ctx: *mut c_void, drawer: YogStr, ud: *mut c_void, f: YogPageDrawFn),
1541
1542 pub on_item_tooltip: unsafe extern "C" fn(
1547 ctx: *mut c_void,
1548 item: YogStr,
1549 ud: *mut c_void,
1550 size: YogTooltipSizeFn,
1551 draw: YogTooltipDrawFn,
1552 ),
1553
1554 pub is_mod_loaded: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
1558 pub java_call: unsafe extern "C" fn(ctx: *mut c_void, expr: YogStr, args: YogStr) -> YogOwnedStr,
1565
1566 pub on_item_text: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, ud: *mut c_void, f: YogItemTextFn),
1570
1571 pub on_machine_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogMachineCraftFn),
1574
1575 pub client_body_track: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, on: bool),
1578 pub client_body_track_type: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, on: bool),
1580 pub on_body: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogBodyFn),
1582 pub on_camera: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogCameraFn),
1584 pub on_travel: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogTravelFn),
1586
1587 pub client_set_dimensions: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32),
1591
1592 pub client_entity_data:
1596 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1597
1598 pub on_entity_tick: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, ud: *mut c_void, f: YogEntityTickFn),
1601
1602 pub on_loot: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogLootFn),
1607}
1608
1609pub mod ui_flags {
1611 pub const MODAL: u32 = 1;
1613 pub const PAUSE: u32 = 1 << 1;
1615 pub const NO_BACKGROUND: u32 = 1 << 2;
1617}
1618
1619unsafe impl Send for YogApi {}
1620unsafe impl Sync for YogApi {}
1621
1622#[cfg(test)]
1623mod tests {
1624 use super::*;
1625 use std::mem::{align_of, size_of};
1626
1627 fn layout_fingerprint() -> u64 {
1629 macro_rules! layouts {
1630 ($($t:ty),* $(,)?) => { [$((stringify!($t), size_of::<$t>(), align_of::<$t>())),*] };
1631 }
1632 let all = layouts!(
1633 YogStr, YogOwnedStr, YogBlockPos, YogVec3, YogBlockBreakEvent, YogChatEvent, YogPlayerEvent,
1634 YogUseItemEvent, YogUseBlockEvent, YogAttackEntityEvent, YogEntityDamageEvent, YogEntityDeathEvent,
1635 YogEntitySpawnEvent, YogPlayerDeathEvent, YogPlayerRespawnEvent, YogAdvancementEvent,
1636 YogEntityInteractEvent, YogCraftEvent, YogExplosionEvent, YogItemPickupEvent, YogItemInsertEvent, YogPlayerMoveEvent,
1637 YogContainerOpenEvent, YogContainerCloseEvent, YogProjectileHitEvent, YogPlaceBlockEvent,
1638 YogPacketEvent, YogCommandEvent,
1639 YogKeyPressEvent, YogGfxApi, YogServer, YogChunkWriterApi, YogApi,
1640 );
1641 let mut h: u64 = 0xcbf2_9ce4_8422_2325;
1643 for (name, size, align) in all {
1644 for b in name.bytes().chain((size as u64).to_le_bytes()).chain((align as u64).to_le_bytes()) {
1645 h = (h ^ b as u64).wrapping_mul(0x0100_0000_01b3);
1646 }
1647 }
1648 h
1649 }
1650
1651 #[test]
1655 #[cfg(target_pointer_width = "64")]
1656 fn the_layout_matches_its_version() {
1657 assert_eq!((ABI_VERSION, layout_fingerprint()), (30004, 0x840b_06ee_cd95_a5c4), "layout fingerprint: {:#x}", layout_fingerprint());
1658 }
1659
1660 #[test]
1661 fn older_minors_of_the_major_are_compatible() {
1662 assert!(compatible(ABI_VERSION));
1663 assert!(compatible(ABI_MAJOR * 10_000));
1664 assert!(!compatible(ABI_VERSION + 1), "a newer minor may use what isn't here");
1665 assert!(!compatible((ABI_MAJOR - 1) * 10_000 + ABI_MINOR), "another major");
1666 assert!(!compatible((ABI_MAJOR + 1) * 10_000));
1667 }
1668
1669 #[test]
1670 fn strings_cross_and_come_back() {
1671 let s = YogStr::from_str("Ünïcode ✓");
1672 assert_eq!(unsafe { s.as_str() }, "Ünïcode ✓");
1673 assert!(YogStr::EMPTY.is_empty());
1674 assert_eq!(unsafe { YogStr::EMPTY.as_str() }, "");
1675 let owned = YogOwnedStr::from_string("runtime".to_string());
1676 assert!(!owned.is_none() && owned.len == 7);
1677 assert!(YogOwnedStr::NONE.is_none());
1678 drop(unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(owned.ptr, owned.len as usize)) });
1680 }
1681}