1use std::os::raw::c_void;
17
18pub const ABI_MAJOR: u32 = 3;
21pub const ABI_MINOR: u32 = 10;
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 YogKeyBindingFn = unsafe extern "C" fn(ud: *mut c_void, id: YogStr);
608pub type YogScreenFn = unsafe extern "C" fn(ud: *mut c_void, screen_class: YogStr) -> bool;
611
612#[repr(C)]
628#[derive(Copy, Clone)]
629pub struct YogGfxApi {
630 pub screen_w: i32,
633 pub screen_h: i32,
635 pub delta_tick: f32,
637 pub scale_factor: f32,
640 pub view_proj: [f32; 16],
643 pub camera_pos: [f32; 3],
645 pub player_pos: [f32; 3],
648 pub _pad1: f32,
649
650 pub buf_create: unsafe extern "C" fn() -> u32,
653 pub buf_delete: unsafe extern "C" fn(handle: u32),
655 pub buf_data: unsafe extern "C" fn(handle: u32, bytes: *const u8, len: u32, dynamic: bool),
658 pub buf_subdata: unsafe extern "C" fn(handle: u32, offset: u32, bytes: *const u8, len: u32),
660
661 pub vao_create: unsafe extern "C" fn() -> u32,
664 pub vao_delete: unsafe extern "C" fn(handle: u32),
666 pub vao_attrib: unsafe extern "C" fn(
669 vao: u32,
670 vbo: u32,
671 index: u32,
672 components: u8,
673 dtype: u8,
674 normalized: bool,
675 stride: u32,
676 offset: u32,
677 ),
678 pub vao_set_ebo: unsafe extern "C" fn(vao: u32, ebo: u32),
680
681 pub prog_create: unsafe extern "C" fn(vert: YogStr, frag: YogStr, out: *mut u32) -> bool,
685 pub prog_delete: unsafe extern "C" fn(handle: u32),
687 pub prog_uniform_1i: unsafe extern "C" fn(prog: u32, name: YogStr, v: i32),
688 pub prog_uniform_1f: unsafe extern "C" fn(prog: u32, name: YogStr, v: f32),
689 pub prog_uniform_2f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32),
690 pub prog_uniform_3f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32),
691 pub prog_uniform_4f:
692 unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32, w: f32),
693 pub prog_uniform_mat4: unsafe extern "C" fn(prog: u32, name: YogStr, col_major: *const f32),
695
696 pub tex_create: unsafe extern "C" fn(w: u32, h: u32, rgba: *const u8, linear: bool) -> u32,
700 pub tex_delete: unsafe extern "C" fn(handle: u32),
702 pub tex_bind: unsafe extern "C" fn(unit: u32, handle: u32),
704 pub tex_from_mc: unsafe extern "C" fn(id: YogStr) -> u32,
708
709 pub draw_arrays: unsafe extern "C" fn(vao: u32, prog: u32, mode: u8, first: u32, count: u32),
713 pub draw_elements:
716 unsafe extern "C" fn(vao: u32, ebo: u32, prog: u32, mode: u8, count: u32, u32_idx: bool),
717
718 pub set_blend: unsafe extern "C" fn(enabled: bool, src: u32, dst: u32),
721 pub set_depth: unsafe extern "C" fn(test: bool, write: bool),
723 pub set_scissor: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
727 pub clear_scissor: unsafe extern "C" fn(),
729 pub set_viewport: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
731
732 pub draw2d_rect: unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, color: u32),
735 pub draw2d_gradient:
737 unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, top: u32, bottom: u32),
738 pub draw2d_text: unsafe extern "C" fn(text: YogStr, x: f32, y: f32, color: u32, shadow: bool),
740
741 pub draw2d_item: unsafe extern "C" fn(id: YogStr, x: f32, y: f32, size: f32),
747
748 pub draw2d_text_font:
754 unsafe extern "C" fn(text: YogStr, font: YogStr, x: f32, y: f32, color: u32, shadow: bool),
755 pub text_width: unsafe extern "C" fn(text: YogStr, font: YogStr) -> f32,
760
761 pub draw2d_image: unsafe extern "C" fn(
772 source: YogStr,
773 x: f32,
774 y: f32,
775 w: f32,
776 h: f32,
777 u: f32,
778 v: f32,
779 uw: f32,
780 vh: f32,
781 tint: u32,
782 ),
783 pub image_size: unsafe extern "C" fn(source: YogStr, w: *mut f32, h: *mut f32) -> bool,
788
789 pub draw2d_svg: unsafe extern "C" fn(data: YogStr, x: f32, y: f32, w: f32, h: f32),
793 pub draw2d_entity:
797 unsafe extern "C" fn(entity: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
798
799 pub draw2d_text_scaled: unsafe extern "C" fn(
803 text: YogStr,
804 font: YogStr,
805 x: f32,
806 y: f32,
807 scale: f32,
808 color: u32,
809 shadow: bool,
810 ),
811 pub draw2d_blocks:
815 unsafe extern "C" fn(blocks: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
816}
817
818unsafe impl Send for YogGfxApi {}
819unsafe impl Sync for YogGfxApi {}
820
821#[repr(C)]
831pub struct YogServer {
832 pub ctx: *mut c_void,
833 pub abi_version: u32,
834 pub size: u32,
837
838 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
840
841 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
843
844 pub get_block:
846 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
847 pub set_block: unsafe extern "C" fn(
848 ctx: *mut c_void,
849 dim: YogStr,
850 pos: YogBlockPos,
851 block: YogStr,
852 ) -> bool,
853 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
854 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
855 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
856 pub set_weather:
857 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
858
859 pub give_item:
861 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
862 pub player_teleport:
863 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
864 pub send_to_player: unsafe extern "C" fn(
865 ctx: *mut c_void,
866 player: YogStr,
867 channel: YogStr,
868 data: *const u8,
869 len: u32,
870 ) -> bool,
871 pub send_to_server:
872 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
873 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
874 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
875 pub send_title: unsafe extern "C" fn(
876 ctx: *mut c_void,
877 player: YogStr,
878 title: YogStr,
879 sub: YogStr,
880 fi: i32,
881 stay: i32,
882 fo: i32,
883 ) -> bool,
884 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
885 pub play_sound: unsafe extern "C" fn(
886 ctx: *mut c_void,
887 dim: YogStr,
888 pos: YogVec3,
889 sound: YogStr,
890 vol: f32,
891 pitch: f32,
892 ) -> bool,
893 pub play_sound_player: unsafe extern "C" fn(
894 ctx: *mut c_void,
895 player: YogStr,
896 sound: YogStr,
897 vol: f32,
898 pitch: f32,
899 ) -> bool,
900
901 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
903 pub entity_position:
904 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
905 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
906 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
907 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
908 pub spawn_entity: unsafe extern "C" fn(
909 ctx: *mut c_void,
910 type_id: YogStr,
911 dim: YogStr,
912 pos: YogVec3,
913 ) -> YogOwnedStr,
914 pub entity_add_effect: unsafe extern "C" fn(
915 ctx: *mut c_void,
916 uuid: YogStr,
917 fx: YogStr,
918 dur: i32,
919 amp: u8,
920 particles: bool,
921 ) -> bool,
922 pub entity_remove_effect:
923 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
924 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
925 pub entity_velocity:
926 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
927 pub entity_set_velocity:
928 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
929 pub entity_add_velocity:
930 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
931
932 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
934 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
935 pub drop_loot:
936 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
937
938 pub scoreboard_get:
940 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
941 pub scoreboard_set:
942 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
943 pub scoreboard_add: unsafe extern "C" fn(
944 ctx: *mut c_void,
945 obj: YogStr,
946 player: YogStr,
947 delta: i32,
948 out: *mut i32,
949 ) -> bool,
950
951 pub bossbar_create: unsafe extern "C" fn(
953 ctx: *mut c_void,
954 id: YogStr,
955 title: YogStr,
956 color: YogStr,
957 style: YogStr,
958 ) -> bool,
959 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
960 pub bossbar_set_title:
961 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
962 pub bossbar_set_progress:
963 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
964 pub bossbar_set_color:
965 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
966 pub bossbar_add_player:
967 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
968 pub bossbar_remove_player:
969 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
970 pub bossbar_set_visible:
971 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
972
973 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
975
976 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
979
980 pub get_block_nbt:
983 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
984 pub set_block_nbt:
986 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
987
988 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
991 pub player_set_slot: unsafe extern "C" fn(
993 ctx: *mut c_void,
994 player: YogStr,
995 slot: u32,
996 item_id: YogStr,
997 count: u32,
998 ) -> bool,
999
1000 pub get_inventory_slot: unsafe extern "C" fn(
1004 ctx: *mut c_void,
1005 dim: YogStr,
1006 pos: YogBlockPos,
1007 slot: u32,
1008 ) -> YogOwnedStr,
1009 pub set_inventory_slot: unsafe extern "C" fn(
1013 ctx: *mut c_void,
1014 dim: YogStr,
1015 pos: YogBlockPos,
1016 slot: u32,
1017 item_id: YogStr,
1018 count: u32,
1019 ) -> bool,
1020
1021 pub player_teleport_dim:
1023 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1024 pub entity_teleport_dim:
1025 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1026
1027 pub world_entity_count:
1030 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
1031
1032 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1035 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
1037
1038 pub spawn_particles: unsafe extern "C" fn(
1043 ctx: *mut c_void,
1044 dim: YogStr,
1045 pos: YogVec3,
1046 particle_type: YogStr,
1047 count: i32,
1048 dx: f64,
1049 dy: f64,
1050 dz: f64,
1051 speed: f64,
1052 ) -> bool,
1053
1054 pub entity_attribute_get:
1059 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
1060 pub entity_attribute_set: unsafe extern "C" fn(
1062 ctx: *mut c_void,
1063 uuid: YogStr,
1064 attribute_id: YogStr,
1065 value: f64,
1066 ) -> bool,
1067
1068 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1072 pub set_held_item_nbt:
1075 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1076
1077 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1080 pub set_offhand_item_nbt:
1083 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1084 pub get_slot_item:
1087 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
1088 pub set_slot_item: unsafe extern "C" fn(
1091 ctx: *mut c_void,
1092 player: YogStr,
1093 slot: u32,
1094 item_id: YogStr,
1095 count: u32,
1096 snbt: YogStr,
1097 ) -> bool,
1098
1099 pub entity_rotation:
1103 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
1104
1105 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1110 pub entities_in_box: unsafe extern "C" fn(
1112 ctx: *mut c_void,
1113 dim: YogStr,
1114 min: YogVec3,
1115 max: YogVec3,
1116 ) -> YogOwnedStr,
1117 pub raycast_block: unsafe extern "C" fn(
1119 ctx: *mut c_void,
1120 dim: YogStr,
1121 from: YogVec3,
1122 to: YogVec3,
1123 ) -> YogOwnedStr,
1124 pub raycast_entity: unsafe extern "C" fn(
1126 ctx: *mut c_void,
1127 dim: YogStr,
1128 from: YogVec3,
1129 to: YogVec3,
1130 exclude: YogStr,
1131 ) -> YogOwnedStr,
1132 pub block_info:
1134 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1135 pub break_block: unsafe extern "C" fn(
1136 ctx: *mut c_void,
1137 dim: YogStr,
1138 pos: YogBlockPos,
1139 drop: bool,
1140 breaker: YogStr,
1141 ) -> bool,
1142 pub place_block_from_slot: unsafe extern "C" fn(
1143 ctx: *mut c_void,
1144 player: YogStr,
1145 slot: u32,
1146 dim: YogStr,
1147 pos: YogBlockPos,
1148 ) -> bool,
1149 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1150 pub explode: unsafe extern "C" fn(
1151 ctx: *mut c_void,
1152 dim: YogStr,
1153 pos: YogVec3,
1154 power: f32,
1155 fire: bool,
1156 source: YogStr,
1157 ) -> bool,
1158 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1160 pub entity_damage: unsafe extern "C" fn(
1161 ctx: *mut c_void,
1162 uuid: YogStr,
1163 amount: f32,
1164 damage_type: YogStr,
1165 attacker: YogStr,
1166 ) -> bool,
1167 pub entity_set_fire_ticks:
1168 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1169 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1170 pub player_set_may_fly:
1171 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1172 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1174 pub spawn_item: unsafe extern "C" fn(
1176 ctx: *mut c_void,
1177 dim: YogStr,
1178 pos: YogVec3,
1179 vel: YogVec3,
1180 item_id: YogStr,
1181 count: u32,
1182 snbt: YogStr,
1183 ) -> YogOwnedStr,
1184 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1186 pub item_entity_set_stack: unsafe extern "C" fn(
1187 ctx: *mut c_void,
1188 uuid: YogStr,
1189 item_id: YogStr,
1190 count: u32,
1191 snbt: YogStr,
1192 ) -> bool,
1193 pub actionbar_json:
1196 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1197 pub use_item_on_block: unsafe extern "C" fn(
1199 ctx: *mut c_void,
1200 dim: YogStr,
1201 pos: YogBlockPos,
1202 face: u8,
1203 item_id: YogStr,
1204 player: YogStr,
1205 ) -> bool,
1206 pub pour_fluid: unsafe extern "C" fn(
1207 ctx: *mut c_void,
1208 dim: YogStr,
1209 pos: YogBlockPos,
1210 bucket_item_id: YogStr,
1211 ) -> bool,
1212 pub has_entity_tag:
1213 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1214 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1216 pub place_feature: unsafe extern "C" fn(
1217 ctx: *mut c_void,
1218 dim: YogStr,
1219 pos: YogBlockPos,
1220 feature_id: YogStr,
1221 ) -> bool,
1222
1223 pub set_item_cooldown:
1225 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1226 pub entity_vehicle: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1228 pub entity_passengers: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1230 pub entity_mount:
1232 unsafe extern "C" fn(ctx: *mut c_void, rider: YogStr, vehicle: YogStr, force: bool) -> bool,
1233 pub entity_dismount: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
1235 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1237 pub entity_set_fall_distance: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, distance: f32) -> bool,
1239 pub redstone_signal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1241 pub set_redstone_output:
1242 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1243 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1245 pub set_block_state:
1246 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1247 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1248 pub world_set_thunder:
1249 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1250 pub fill_region: unsafe extern "C" fn(
1252 ctx: *mut c_void,
1253 dim: YogStr,
1254 from: YogBlockPos,
1255 to: YogBlockPos,
1256 state: YogStr,
1257 ) -> i32,
1258 pub scan_region:
1260 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1261
1262 pub entity_set_dimensions:
1266 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32) -> bool,
1267
1268 pub entity_data_set:
1273 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, data: *const u8, len: u32, flags: u32) -> bool,
1274 pub entity_data_get:
1276 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1277
1278 pub world_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1283
1284 pub entity_attribute_value: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
1289
1290 pub advancement_grant: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, id: YogStr) -> bool,
1294 pub advancement_done: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, id: YogStr) -> bool,
1296}
1297
1298unsafe impl Send for YogServer {}
1300unsafe impl Sync for YogServer {}
1301
1302#[repr(C)]
1309#[derive(Copy, Clone)]
1310pub struct YogChunkWriterApi {
1311 pub chunk_x: i32,
1313 pub chunk_z: i32,
1315 pub min_y: i32,
1317 pub height: i32,
1319 pub ctx: *mut c_void,
1321 pub set_block:
1324 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1325}
1326
1327unsafe impl Send for YogChunkWriterApi {}
1328unsafe impl Sync for YogChunkWriterApi {}
1329
1330pub type YogChunkGeneratorFn =
1333 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1334
1335#[repr(C)]
1344pub struct YogApi {
1345 pub abi_version: u32,
1346 pub size: u32,
1348 pub ctx: *mut c_void,
1350 pub server: *const YogServer,
1352
1353 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1356 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1357 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1358 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1359 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1360 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1361 pub on_attack_entity:
1362 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1363 pub on_entity_damage:
1364 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1365 pub on_entity_death:
1366 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1367 pub on_entity_spawn:
1368 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1369 pub on_player_place_block:
1370 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1371 pub on_player_death:
1372 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1373 pub on_player_respawn:
1374 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1375 pub on_advancement:
1376 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1377 pub on_entity_interact:
1379 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1380 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1381 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1382 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1384 pub on_item_insert: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemInsertFn),
1385 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1386 pub on_container_open:
1387 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1388 pub on_container_close:
1389 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1390 pub on_projectile_hit:
1391 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1392 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1393 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1394 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1395
1396 pub on_packet:
1398 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1399 pub on_client_packet:
1400 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1401
1402 pub register_command:
1404 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1405 pub register_typed_command: unsafe extern "C" fn(
1406 ctx: *mut c_void,
1407 name: YogStr,
1408 schema: YogStr,
1409 ud: *mut c_void,
1410 h: YogCommandFn,
1411 ),
1412
1413 pub register_content: unsafe extern "C" fn(ctx: *mut c_void, kind: YogStr, id: YogStr, data: *const u8, len: usize),
1421
1422 pub schedule_once: unsafe extern "C" fn(
1424 ctx: *mut c_void,
1425 delay_ticks: u64,
1426 ud: *mut c_void,
1427 h: YogScheduledFn,
1428 ),
1429 pub schedule_repeating: unsafe extern "C" fn(
1430 ctx: *mut c_void,
1431 period_ticks: u64,
1432 ud: *mut c_void,
1433 h: YogScheduledFn,
1434 ),
1435
1436 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1438 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1439 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1440 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1441 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1442
1443 pub on_world_render:
1448 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1449
1450 pub register_ui: unsafe extern "C" fn(
1455 ctx: *mut c_void,
1456 ui_id: YogStr,
1457 layout_json: YogStr,
1458 ud: *mut c_void,
1459 h: YogUIEventFn,
1460 ),
1461
1462 pub on_ui_render:
1469 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1470
1471 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1477
1478 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1485 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1488
1489 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1494
1495 pub interop_export:
1499 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1500 pub interop_import:
1503 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1504
1505 pub register_chunk_generator:
1510 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1511
1512 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1517 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1521
1522 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1530
1531 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1536 pub client_play_sound: unsafe extern "C" fn(
1540 ctx: *mut c_void,
1541 sound_id: YogStr,
1542 volume: f32,
1543 pitch: f32,
1544 looping: bool,
1545 ) -> u32,
1546 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1548 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1551 pub client_set_block_tint: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, color: i64),
1554 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1556
1557 pub on_book_page:
1561 unsafe extern "C" fn(ctx: *mut c_void, drawer: YogStr, ud: *mut c_void, f: YogPageDrawFn),
1562
1563 pub on_item_tooltip: unsafe extern "C" fn(
1568 ctx: *mut c_void,
1569 item: YogStr,
1570 ud: *mut c_void,
1571 size: YogTooltipSizeFn,
1572 draw: YogTooltipDrawFn,
1573 ),
1574
1575 pub is_mod_loaded: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
1579 pub java_call: unsafe extern "C" fn(ctx: *mut c_void, expr: YogStr, args: YogStr) -> YogOwnedStr,
1586
1587 pub on_item_text: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, ud: *mut c_void, f: YogItemTextFn),
1591
1592 pub on_machine_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogMachineCraftFn),
1595
1596 pub client_body_track: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, on: bool),
1599 pub client_body_track_type: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, on: bool),
1601 pub on_body: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogBodyFn),
1603 pub on_camera: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogCameraFn),
1605 pub on_travel: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogTravelFn),
1607
1608 pub client_set_dimensions: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, width: f32, height: f32, eye: f32),
1612
1613 pub client_entity_data:
1617 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, key: YogStr, sink: *mut c_void, write: YogBytesSink) -> bool,
1618
1619 pub on_entity_tick: unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, ud: *mut c_void, f: YogEntityTickFn),
1622
1623 pub on_loot: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogLootFn),
1628
1629 pub client_attribute_value: unsafe extern "C" fn(ctx: *mut c_void, attribute_id: YogStr) -> f64,
1633
1634 pub client_advancement_done: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
1638
1639 pub log: unsafe extern "C" fn(level: u32, message: YogStr),
1644
1645 pub client_op: unsafe extern "C" fn(ctx: *mut c_void, op: YogStr, args: YogStr) -> YogOwnedStr,
1650
1651 pub register_key_binding: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, name: YogStr, default_key: i32),
1657 pub on_key_binding: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, f: YogKeyBindingFn),
1659}
1660
1661pub mod ui_flags {
1663 pub const MODAL: u32 = 1;
1665 pub const PAUSE: u32 = 1 << 1;
1667 pub const NO_BACKGROUND: u32 = 1 << 2;
1669}
1670
1671unsafe impl Send for YogApi {}
1672unsafe impl Sync for YogApi {}
1673
1674#[cfg(test)]
1675mod tests {
1676 use super::*;
1677 use std::mem::{align_of, size_of};
1678
1679 fn layout_fingerprint() -> u64 {
1681 macro_rules! layouts {
1682 ($($t:ty),* $(,)?) => { [$((stringify!($t), size_of::<$t>(), align_of::<$t>())),*] };
1683 }
1684 let all = layouts!(
1685 YogStr, YogOwnedStr, YogBlockPos, YogVec3, YogBlockBreakEvent, YogChatEvent, YogPlayerEvent,
1686 YogUseItemEvent, YogUseBlockEvent, YogAttackEntityEvent, YogEntityDamageEvent, YogEntityDeathEvent,
1687 YogEntitySpawnEvent, YogPlayerDeathEvent, YogPlayerRespawnEvent, YogAdvancementEvent,
1688 YogEntityInteractEvent, YogCraftEvent, YogExplosionEvent, YogItemPickupEvent, YogItemInsertEvent, YogPlayerMoveEvent,
1689 YogContainerOpenEvent, YogContainerCloseEvent, YogProjectileHitEvent, YogPlaceBlockEvent,
1690 YogPacketEvent, YogCommandEvent,
1691 YogKeyPressEvent, YogGfxApi, YogServer, YogChunkWriterApi, YogApi,
1692 );
1693 let mut h: u64 = 0xcbf2_9ce4_8422_2325;
1695 for (name, size, align) in all {
1696 for b in name.bytes().chain((size as u64).to_le_bytes()).chain((align as u64).to_le_bytes()) {
1697 h = (h ^ b as u64).wrapping_mul(0x0100_0000_01b3);
1698 }
1699 }
1700 h
1701 }
1702
1703 #[test]
1707 #[cfg(target_pointer_width = "64")]
1708 fn the_layout_matches_its_version() {
1709 assert_eq!((ABI_VERSION, layout_fingerprint()), (30010, 0xb367_665c_47ac_7374), "layout fingerprint: {:#x}", layout_fingerprint());
1710 }
1711
1712 #[test]
1713 fn older_minors_of_the_major_are_compatible() {
1714 assert!(compatible(ABI_VERSION));
1715 assert!(compatible(ABI_MAJOR * 10_000));
1716 assert!(!compatible(ABI_VERSION + 1), "a newer minor may use what isn't here");
1717 assert!(!compatible((ABI_MAJOR - 1) * 10_000 + ABI_MINOR), "another major");
1718 assert!(!compatible((ABI_MAJOR + 1) * 10_000));
1719 }
1720
1721 #[test]
1722 fn strings_cross_and_come_back() {
1723 let s = YogStr::from_str("Ünïcode ✓");
1724 assert_eq!(unsafe { s.as_str() }, "Ünïcode ✓");
1725 assert!(YogStr::EMPTY.is_empty());
1726 assert_eq!(unsafe { YogStr::EMPTY.as_str() }, "");
1727 let owned = YogOwnedStr::from_string("runtime".to_string());
1728 assert!(!owned.is_none() && owned.len == 7);
1729 assert!(YogOwnedStr::NONE.is_none());
1730 drop(unsafe { Box::from_raw(std::ptr::slice_from_raw_parts_mut(owned.ptr, owned.len as usize)) });
1732 }
1733}