1use std::os::raw::c_void;
13
14pub const ABI_MAJOR: u32 = 1;
17pub const ABI_MINOR: u32 = 4;
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}
157
158#[repr(C)]
159pub struct YogAttackEntityEvent {
160 pub player: YogStr,
161 pub target_type: YogStr,
162 pub target_uuid: YogStr,
163 pub dimension: YogStr,
164}
165
166#[repr(C)]
167pub struct YogEntityDamageEvent {
168 pub entity_type: YogStr,
169 pub uuid: YogStr,
170 pub amount: f32,
171 pub source: YogStr,
172 pub dimension: YogStr,
173}
174
175#[repr(C)]
176pub struct YogEntityDeathEvent {
177 pub entity_type: YogStr,
178 pub uuid: YogStr,
179 pub source: YogStr,
180 pub dimension: YogStr,
181}
182
183#[repr(C)]
184pub struct YogEntitySpawnEvent {
185 pub entity_type: YogStr,
186 pub uuid: YogStr,
187 pub dimension: YogStr,
188}
189
190#[repr(C)]
193pub struct YogPlayerDeathEvent {
194 pub player: YogStr,
195 pub uuid: YogStr,
196 pub source: YogStr,
198 pub dimension: YogStr,
199}
200
201#[repr(C)]
203pub struct YogPlayerRespawnEvent {
204 pub player: YogStr,
205 pub uuid: YogStr,
206 pub at_anchor: bool,
208 pub dimension: YogStr,
210}
211
212#[repr(C)]
214pub struct YogAdvancementEvent {
215 pub player: YogStr,
216 pub uuid: YogStr,
217 pub advancement: YogStr,
219 pub dimension: YogStr,
220}
221
222#[repr(C)]
225pub struct YogEntityInteractEvent {
226 pub player: YogStr,
227 pub player_uuid: YogStr,
228 pub entity_type: YogStr,
229 pub entity_uuid: YogStr,
230 pub hand: YogStr,
232 pub dimension: YogStr,
233}
234
235#[repr(C)]
237pub struct YogCraftEvent {
238 pub player: YogStr,
239 pub player_uuid: YogStr,
240 pub result_item: YogStr,
241 pub result_count: u32,
242 pub dimension: YogStr,
243}
244
245#[repr(C)]
248pub struct YogExplosionEvent {
249 pub dimension: YogStr,
250 pub x: f64,
251 pub y: f64,
252 pub z: f64,
253 pub power: f32,
254 pub cause_uuid: YogStr,
256}
257
258#[repr(C)]
262pub struct YogItemPickupEvent {
263 pub player: YogStr,
264 pub player_uuid: YogStr,
265 pub item_id: YogStr,
267 pub item_count: u32,
268 pub entity_uuid: YogStr,
270 pub dimension: YogStr,
271}
272
273#[repr(C)]
275pub struct YogPlayerMoveEvent {
276 pub player: YogStr,
277 pub player_uuid: YogStr,
278 pub x: f64,
279 pub y: f64,
280 pub z: f64,
281 pub yaw: f32,
282 pub pitch: f32,
283 pub dimension: YogStr,
284}
285
286#[repr(C)]
290pub struct YogContainerOpenEvent {
291 pub player: YogStr,
292 pub player_uuid: YogStr,
293 pub container_type: YogStr,
294 pub dimension: YogStr,
295}
296
297#[repr(C)]
299pub struct YogContainerCloseEvent {
300 pub player: YogStr,
301 pub player_uuid: YogStr,
302 pub dimension: YogStr,
303}
304
305#[repr(C)]
308pub struct YogProjectileHitEvent {
309 pub projectile_type: YogStr,
311 pub projectile_uuid: YogStr,
312 pub shooter_uuid: YogStr,
314 pub hit_type: YogStr,
316 pub hit_entity_uuid: YogStr,
318 pub x: f64,
319 pub y: f64,
320 pub z: f64,
321 pub dimension: YogStr,
322}
323
324#[repr(C)]
326pub struct YogPlaceBlockEvent {
327 pub player: YogStr,
328 pub block: YogStr,
329 pub pos: YogBlockPos,
330 pub dimension: YogStr,
331}
332
333#[repr(C)]
334pub struct YogPacketEvent {
335 pub channel: YogStr,
336 pub player: YogStr, pub payload: *const u8,
338 pub payload_len: u32,
339}
340
341#[repr(C)]
342pub struct YogCommandEvent {
343 pub name: YogStr,
344 pub args: YogStr,
345 pub source: YogStr,
346 pub uuid: YogStr,
347 pub dimension: YogStr,
349}
350
351#[repr(C)]
353pub struct YogStartupGrantDef {
354 pub id: YogStr,
355 pub items: YogStr, pub book: YogStr, pub command: YogStr, }
359
360#[repr(C)]
363pub struct YogItemDef {
364 pub id: YogStr,
365 pub max_stack: u32,
366 pub name: YogStr, pub tooltip: YogStr, pub max_damage: u32,
369 pub fire_resistant: bool,
370 pub fuel_ticks: u32,
371 pub food_nutrition: u32, pub food_saturation: f32,
373 pub food_always_eat: bool,
374}
375
376#[repr(C)]
377pub struct YogBlockDef {
378 pub id: YogStr,
379 pub hardness: f32,
380 pub resistance: f32,
381 pub name: YogStr,
382 pub light_level: u8,
383 pub sound: YogStr, pub requires_tool: bool,
385 pub no_collision: bool,
386 pub slipperiness: f32,
387 pub shape: [f32; 6],
389 pub connects: bool,
392 pub connect_groups: YogStr,
395 pub inventory_id: YogStr,
399 pub redstone_source: bool,
401}
402
403#[repr(C)]
405pub struct YogInventoryDef {
406 pub id: YogStr,
407 pub slot_count: u32,
408 pub layout: YogStr,
411 pub include_player_inventory: bool,
412 pub player_inv_x: f32,
413 pub player_inv_y: f32,
414 pub background_texture: YogStr,
416 pub title: YogStr,
417 pub background_w: f32,
424 pub background_h: f32,
425}
426
427#[repr(C)]
431#[derive(Copy, Clone)]
432pub struct YogKeyPressEvent {
433 pub key_code: i32,
435 pub scan_code: i32,
436 pub action: i32,
438 pub modifiers: i32,
440}
441
442pub type YogBlockBreakFn =
454 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogBlockBreakEvent, u8) -> bool;
455pub type YogChatFn =
456 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogChatEvent, u8) -> bool;
457pub type YogPlayerFn =
458 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerEvent, u8) -> bool;
459pub type YogUseItemFn =
460 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogUseItemEvent, u8) -> bool;
461pub type YogUseBlockFn =
462 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogUseBlockEvent, u8) -> bool;
463pub type YogAttackEntityFn =
464 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogAttackEntityEvent, u8) -> bool;
465pub type YogEntityDamageFn =
466 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityDamageEvent, u8) -> bool;
467pub type YogEntityDeathFn =
468 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityDeathEvent, u8) -> bool;
469pub type YogEntitySpawnFn =
470 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntitySpawnEvent, u8) -> bool;
471pub type YogPlaceBlockFn =
472 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlaceBlockEvent, u8) -> bool;
473pub type YogPlayerDeathFn =
474 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerDeathEvent, u8) -> bool;
475pub type YogPlayerRespawnFn =
476 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerRespawnEvent, u8) -> bool;
477pub type YogAdvancementFn =
478 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogAdvancementEvent, u8) -> bool;
479pub type YogEntityInteractFn =
480 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogEntityInteractEvent, u8) -> bool;
481pub type YogCraftFn =
482 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogCraftEvent, u8) -> bool;
483pub type YogExplosionFn =
484 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogExplosionEvent, u8) -> bool;
485pub type YogItemPickupFn =
486 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogItemPickupEvent, u8) -> bool;
487pub type YogPlayerMoveFn =
488 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPlayerMoveEvent, u8) -> bool;
489pub type YogContainerOpenFn =
490 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogContainerOpenEvent, u8) -> bool;
491pub type YogContainerCloseFn =
492 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogContainerCloseEvent, u8) -> bool;
493pub type YogProjectileHitFn =
494 unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogProjectileHitEvent, u8) -> bool;
495
496pub type YogPacketFn = unsafe extern "C" fn(*mut c_void, *const YogServer, *const YogPacketEvent);
498pub type YogServerFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
500pub type YogCommandFn = unsafe extern "C" fn(
502 ud: *mut c_void,
503 srv: *const YogServer,
504 ev: *const YogCommandEvent,
505 reply_buf: *mut u8,
506 reply_cap: u32,
507 reply_len: *mut u32,
508);
509pub type YogScheduledFn = unsafe extern "C" fn(*mut c_void, *const YogServer);
511
512pub type YogClientFn = unsafe extern "C" fn(ud: *mut c_void);
516pub type YogUIEventFn = unsafe extern "C" fn(ud: *mut c_void, ui_id: YogStr, event_id: YogStr);
523pub type YogHudRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
526pub type YogWorldRenderFn = unsafe extern "C" fn(ud: *mut c_void, gfx: *const YogGfxApi);
529pub type YogKeyPressFn = unsafe extern "C" fn(ud: *mut c_void, ev: *const YogKeyPressEvent) -> bool;
531pub type YogScreenFn = unsafe extern "C" fn(ud: *mut c_void, screen_class: YogStr) -> bool;
534
535#[repr(C)]
551#[derive(Copy, Clone)]
552pub struct YogGfxApi {
553 pub screen_w: i32,
556 pub screen_h: i32,
558 pub delta_tick: f32,
560 pub scale_factor: f32,
563 pub view_proj: [f32; 16],
566 pub camera_pos: [f32; 3],
568 pub player_pos: [f32; 3],
571 pub _pad1: f32,
572
573 pub buf_create: unsafe extern "C" fn() -> u32,
576 pub buf_delete: unsafe extern "C" fn(handle: u32),
578 pub buf_data: unsafe extern "C" fn(handle: u32, bytes: *const u8, len: u32, dynamic: bool),
581 pub buf_subdata: unsafe extern "C" fn(handle: u32, offset: u32, bytes: *const u8, len: u32),
583
584 pub vao_create: unsafe extern "C" fn() -> u32,
587 pub vao_delete: unsafe extern "C" fn(handle: u32),
589 pub vao_attrib: unsafe extern "C" fn(
592 vao: u32,
593 vbo: u32,
594 index: u32,
595 components: u8,
596 dtype: u8,
597 normalized: bool,
598 stride: u32,
599 offset: u32,
600 ),
601 pub vao_set_ebo: unsafe extern "C" fn(vao: u32, ebo: u32),
603
604 pub prog_create: unsafe extern "C" fn(vert: YogStr, frag: YogStr, out: *mut u32) -> bool,
608 pub prog_delete: unsafe extern "C" fn(handle: u32),
610 pub prog_uniform_1i: unsafe extern "C" fn(prog: u32, name: YogStr, v: i32),
611 pub prog_uniform_1f: unsafe extern "C" fn(prog: u32, name: YogStr, v: f32),
612 pub prog_uniform_2f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32),
613 pub prog_uniform_3f: unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32),
614 pub prog_uniform_4f:
615 unsafe extern "C" fn(prog: u32, name: YogStr, x: f32, y: f32, z: f32, w: f32),
616 pub prog_uniform_mat4: unsafe extern "C" fn(prog: u32, name: YogStr, col_major: *const f32),
618
619 pub tex_create: unsafe extern "C" fn(w: u32, h: u32, rgba: *const u8, linear: bool) -> u32,
623 pub tex_delete: unsafe extern "C" fn(handle: u32),
625 pub tex_bind: unsafe extern "C" fn(unit: u32, handle: u32),
627 pub tex_from_mc: unsafe extern "C" fn(id: YogStr) -> u32,
631
632 pub draw_arrays: unsafe extern "C" fn(vao: u32, prog: u32, mode: u8, first: u32, count: u32),
636 pub draw_elements:
639 unsafe extern "C" fn(vao: u32, ebo: u32, prog: u32, mode: u8, count: u32, u32_idx: bool),
640
641 pub set_blend: unsafe extern "C" fn(enabled: bool, src: u32, dst: u32),
644 pub set_depth: unsafe extern "C" fn(test: bool, write: bool),
646 pub set_scissor: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
648 pub clear_scissor: unsafe extern "C" fn(),
650 pub set_viewport: unsafe extern "C" fn(x: i32, y: i32, w: i32, h: i32),
652
653 pub draw2d_rect: unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, color: u32),
656 pub draw2d_gradient:
658 unsafe extern "C" fn(x1: f32, y1: f32, x2: f32, y2: f32, top: u32, bottom: u32),
659 pub draw2d_text: unsafe extern "C" fn(text: YogStr, x: f32, y: f32, color: u32, shadow: bool),
661
662 pub draw2d_item: unsafe extern "C" fn(id: YogStr, x: f32, y: f32, size: f32),
668
669 pub draw2d_text_font:
675 unsafe extern "C" fn(text: YogStr, font: YogStr, x: f32, y: f32, color: u32, shadow: bool),
676 pub text_width: unsafe extern "C" fn(text: YogStr, font: YogStr) -> f32,
681
682 pub draw2d_image: unsafe extern "C" fn(
693 source: YogStr,
694 x: f32,
695 y: f32,
696 w: f32,
697 h: f32,
698 u: f32,
699 v: f32,
700 uw: f32,
701 vh: f32,
702 tint: u32,
703 ),
704 pub image_size: unsafe extern "C" fn(source: YogStr, w: *mut f32, h: *mut f32) -> bool,
709
710 pub draw2d_svg: unsafe extern "C" fn(data: YogStr, x: f32, y: f32, w: f32, h: f32),
714 pub draw2d_entity:
718 unsafe extern "C" fn(entity: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
719}
720
721unsafe impl Send for YogGfxApi {}
722unsafe impl Sync for YogGfxApi {}
723
724#[repr(C)]
734pub struct YogServer {
735 pub ctx: *mut c_void,
736 pub abi_version: u32,
737 pub size: u32,
740
741 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
743
744 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
746
747 pub get_block:
749 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
750 pub set_block: unsafe extern "C" fn(
751 ctx: *mut c_void,
752 dim: YogStr,
753 pos: YogBlockPos,
754 block: YogStr,
755 ) -> bool,
756 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
757 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
758 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
759 pub set_weather:
760 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
761
762 pub give_item:
764 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
765 pub player_teleport:
766 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
767 pub send_to_player: unsafe extern "C" fn(
768 ctx: *mut c_void,
769 player: YogStr,
770 channel: YogStr,
771 data: *const u8,
772 len: u32,
773 ) -> bool,
774 pub send_to_server:
775 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
776 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
777 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
778 pub send_title: unsafe extern "C" fn(
779 ctx: *mut c_void,
780 player: YogStr,
781 title: YogStr,
782 sub: YogStr,
783 fi: i32,
784 stay: i32,
785 fo: i32,
786 ) -> bool,
787 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
788 pub play_sound: unsafe extern "C" fn(
789 ctx: *mut c_void,
790 dim: YogStr,
791 pos: YogVec3,
792 sound: YogStr,
793 vol: f32,
794 pitch: f32,
795 ) -> bool,
796 pub play_sound_player: unsafe extern "C" fn(
797 ctx: *mut c_void,
798 player: YogStr,
799 sound: YogStr,
800 vol: f32,
801 pitch: f32,
802 ) -> bool,
803
804 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
806 pub entity_position:
807 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
808 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
809 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
810 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
811 pub spawn_entity: unsafe extern "C" fn(
812 ctx: *mut c_void,
813 type_id: YogStr,
814 dim: YogStr,
815 pos: YogVec3,
816 ) -> YogOwnedStr,
817 pub entity_add_effect: unsafe extern "C" fn(
818 ctx: *mut c_void,
819 uuid: YogStr,
820 fx: YogStr,
821 dur: i32,
822 amp: u8,
823 particles: bool,
824 ) -> bool,
825 pub entity_remove_effect:
826 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
827 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
828 pub entity_velocity:
829 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
830 pub entity_set_velocity:
831 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
832 pub entity_add_velocity:
833 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
834
835 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
837 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
838 pub drop_loot:
839 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
840
841 pub scoreboard_get:
843 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
844 pub scoreboard_set:
845 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
846 pub scoreboard_add: unsafe extern "C" fn(
847 ctx: *mut c_void,
848 obj: YogStr,
849 player: YogStr,
850 delta: i32,
851 out: *mut i32,
852 ) -> bool,
853
854 pub bossbar_create: unsafe extern "C" fn(
856 ctx: *mut c_void,
857 id: YogStr,
858 title: YogStr,
859 color: YogStr,
860 style: YogStr,
861 ) -> bool,
862 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
863 pub bossbar_set_title:
864 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
865 pub bossbar_set_progress:
866 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
867 pub bossbar_set_color:
868 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
869 pub bossbar_add_player:
870 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
871 pub bossbar_remove_player:
872 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
873 pub bossbar_set_visible:
874 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
875
876 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
878
879 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
882
883 pub get_block_nbt:
886 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
887 pub set_block_nbt:
889 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
890
891 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
894 pub player_set_slot: unsafe extern "C" fn(
896 ctx: *mut c_void,
897 player: YogStr,
898 slot: u32,
899 item_id: YogStr,
900 count: u32,
901 ) -> bool,
902
903 pub get_inventory_slot: unsafe extern "C" fn(
907 ctx: *mut c_void,
908 dim: YogStr,
909 pos: YogBlockPos,
910 slot: u32,
911 ) -> YogOwnedStr,
912 pub set_inventory_slot: unsafe extern "C" fn(
916 ctx: *mut c_void,
917 dim: YogStr,
918 pos: YogBlockPos,
919 slot: u32,
920 item_id: YogStr,
921 count: u32,
922 ) -> bool,
923
924 pub player_teleport_dim:
926 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
927 pub entity_teleport_dim:
928 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
929
930 pub world_entity_count:
933 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
934
935 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
938 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
940
941 pub spawn_particles: unsafe extern "C" fn(
946 ctx: *mut c_void,
947 dim: YogStr,
948 pos: YogVec3,
949 particle_type: YogStr,
950 count: i32,
951 dx: f64,
952 dy: f64,
953 dz: f64,
954 speed: f64,
955 ) -> bool,
956
957 pub entity_attribute_get:
962 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
963 pub entity_attribute_set: unsafe extern "C" fn(
965 ctx: *mut c_void,
966 uuid: YogStr,
967 attribute_id: YogStr,
968 value: f64,
969 ) -> bool,
970
971 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
975 pub set_held_item_nbt:
978 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
979
980 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
983 pub set_offhand_item_nbt:
986 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
987 pub get_slot_item:
990 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
991 pub set_slot_item: unsafe extern "C" fn(
994 ctx: *mut c_void,
995 player: YogStr,
996 slot: u32,
997 item_id: YogStr,
998 count: u32,
999 snbt: YogStr,
1000 ) -> bool,
1001
1002 pub entity_rotation:
1006 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
1007
1008 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1013 pub entities_in_box: unsafe extern "C" fn(
1015 ctx: *mut c_void,
1016 dim: YogStr,
1017 min: YogVec3,
1018 max: YogVec3,
1019 ) -> YogOwnedStr,
1020 pub raycast_block: unsafe extern "C" fn(
1022 ctx: *mut c_void,
1023 dim: YogStr,
1024 from: YogVec3,
1025 to: YogVec3,
1026 ) -> YogOwnedStr,
1027 pub raycast_entity: unsafe extern "C" fn(
1029 ctx: *mut c_void,
1030 dim: YogStr,
1031 from: YogVec3,
1032 to: YogVec3,
1033 exclude: YogStr,
1034 ) -> YogOwnedStr,
1035 pub block_info:
1037 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1038 pub break_block: unsafe extern "C" fn(
1039 ctx: *mut c_void,
1040 dim: YogStr,
1041 pos: YogBlockPos,
1042 drop: bool,
1043 breaker: YogStr,
1044 ) -> bool,
1045 pub place_block_from_slot: unsafe extern "C" fn(
1046 ctx: *mut c_void,
1047 player: YogStr,
1048 slot: u32,
1049 dim: YogStr,
1050 pos: YogBlockPos,
1051 ) -> bool,
1052 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1053 pub explode: unsafe extern "C" fn(
1054 ctx: *mut c_void,
1055 dim: YogStr,
1056 pos: YogVec3,
1057 power: f32,
1058 fire: bool,
1059 source: YogStr,
1060 ) -> bool,
1061 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1063 pub entity_damage: unsafe extern "C" fn(
1064 ctx: *mut c_void,
1065 uuid: YogStr,
1066 amount: f32,
1067 damage_type: YogStr,
1068 attacker: YogStr,
1069 ) -> bool,
1070 pub entity_set_fire_ticks:
1071 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1072 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1073 pub player_set_may_fly:
1074 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1075 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1077 pub spawn_item: unsafe extern "C" fn(
1079 ctx: *mut c_void,
1080 dim: YogStr,
1081 pos: YogVec3,
1082 vel: YogVec3,
1083 item_id: YogStr,
1084 count: u32,
1085 snbt: YogStr,
1086 ) -> YogOwnedStr,
1087 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1089 pub item_entity_set_stack: unsafe extern "C" fn(
1090 ctx: *mut c_void,
1091 uuid: YogStr,
1092 item_id: YogStr,
1093 count: u32,
1094 snbt: YogStr,
1095 ) -> bool,
1096 pub actionbar_json:
1099 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1100 pub use_item_on_block: unsafe extern "C" fn(
1102 ctx: *mut c_void,
1103 dim: YogStr,
1104 pos: YogBlockPos,
1105 face: u8,
1106 item_id: YogStr,
1107 player: YogStr,
1108 ) -> bool,
1109 pub pour_fluid: unsafe extern "C" fn(
1110 ctx: *mut c_void,
1111 dim: YogStr,
1112 pos: YogBlockPos,
1113 bucket_item_id: YogStr,
1114 ) -> bool,
1115 pub has_entity_tag:
1116 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1117 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1119 pub place_feature: unsafe extern "C" fn(
1120 ctx: *mut c_void,
1121 dim: YogStr,
1122 pos: YogBlockPos,
1123 feature_id: YogStr,
1124 ) -> bool,
1125
1126 pub set_item_cooldown:
1128 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1129 pub entity_teleport_with_passengers:
1130 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1131 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1133 pub set_redstone_output:
1134 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1135 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1137 pub set_block_state:
1138 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1139 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1140 pub world_set_thunder:
1141 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1142 pub fill_region: unsafe extern "C" fn(
1144 ctx: *mut c_void,
1145 dim: YogStr,
1146 from: YogBlockPos,
1147 to: YogBlockPos,
1148 state: YogStr,
1149 ) -> i32,
1150 pub scan_region:
1152 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1153}
1154
1155unsafe impl Send for YogServer {}
1157unsafe impl Sync for YogServer {}
1158
1159#[repr(C)]
1166#[derive(Copy, Clone)]
1167pub struct YogChunkWriterApi {
1168 pub chunk_x: i32,
1170 pub chunk_z: i32,
1172 pub min_y: i32,
1174 pub height: i32,
1176 pub ctx: *mut c_void,
1178 pub set_block:
1181 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1182}
1183
1184unsafe impl Send for YogChunkWriterApi {}
1185unsafe impl Sync for YogChunkWriterApi {}
1186
1187pub type YogChunkGeneratorFn =
1190 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1191
1192#[repr(C)]
1201pub struct YogApi {
1202 pub abi_version: u32,
1203 pub size: u32,
1205 pub ctx: *mut c_void,
1207 pub server: *const YogServer,
1209
1210 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1213 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1214 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1215 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1216 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1217 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1218 pub on_attack_entity:
1219 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1220 pub on_entity_damage:
1221 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1222 pub on_entity_death:
1223 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1224 pub on_entity_spawn:
1225 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1226 pub on_player_place_block:
1227 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1228 pub on_player_death:
1229 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1230 pub on_player_respawn:
1231 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1232 pub on_advancement:
1233 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1234 pub on_entity_interact:
1236 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1237 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1238 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1239 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1241 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1242 pub on_container_open:
1243 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1244 pub on_container_close:
1245 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1246 pub on_projectile_hit:
1247 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1248 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1249 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1250 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1251
1252 pub on_packet:
1254 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1255 pub on_client_packet:
1256 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1257
1258 pub register_command:
1260 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1261 pub register_typed_command: unsafe extern "C" fn(
1262 ctx: *mut c_void,
1263 name: YogStr,
1264 schema: YogStr,
1265 ud: *mut c_void,
1266 h: YogCommandFn,
1267 ),
1268
1269 pub register_recipe_json:
1273 unsafe extern "C" fn(ctx: *mut c_void, namespace: YogStr, name: YogStr, json: YogStr),
1274
1275 pub register_item: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogItemDef),
1277 pub register_block: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogBlockDef),
1278
1279 pub schedule_once: unsafe extern "C" fn(
1281 ctx: *mut c_void,
1282 delay_ticks: u64,
1283 ud: *mut c_void,
1284 h: YogScheduledFn,
1285 ),
1286 pub schedule_repeating: unsafe extern "C" fn(
1287 ctx: *mut c_void,
1288 period_ticks: u64,
1289 ud: *mut c_void,
1290 h: YogScheduledFn,
1291 ),
1292
1293 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1295 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1296 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1297 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1298 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1299
1300 pub on_world_render:
1305 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1306
1307 pub register_startup_grant:
1309 unsafe extern "C" fn(ctx: *mut c_void, grant: *const YogStartupGrantDef),
1310
1311 pub register_book: unsafe extern "C" fn(ctx: *mut c_void, book_id: YogStr, book_json: YogStr),
1313
1314 pub register_ui: unsafe extern "C" fn(
1319 ctx: *mut c_void,
1320 ui_id: YogStr,
1321 layout_json: YogStr,
1322 ud: *mut c_void,
1323 h: YogUIEventFn,
1324 ),
1325
1326 pub on_ui_render:
1333 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1334
1335 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1341
1342 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1349 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1352
1353 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1358
1359 pub register_inventory: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogInventoryDef),
1362
1363 pub interop_export:
1367 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1368 pub interop_import:
1371 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1372
1373 pub register_dimension_json: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, json: YogStr),
1379 pub register_chunk_generator:
1383 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1384
1385 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1390 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1394
1395 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1403
1404 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1409 pub client_play_sound: unsafe extern "C" fn(
1413 ctx: *mut c_void,
1414 sound_id: YogStr,
1415 volume: f32,
1416 pitch: f32,
1417 looping: bool,
1418 ) -> u32,
1419 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1421 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1424 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1426}
1427
1428pub mod ui_flags {
1430 pub const MODAL: u32 = 1;
1432 pub const PAUSE: u32 = 1 << 1;
1434 pub const NO_BACKGROUND: u32 = 1 << 2;
1436}
1437
1438unsafe impl Send for YogApi {}
1439unsafe impl Sync for YogApi {}