1use std::os::raw::c_void;
13
14pub const ABI_MAJOR: u32 = 1;
17pub const ABI_MINOR: u32 = 3;
18pub const ABI_VERSION: u32 = ABI_MAJOR * 10_000 + ABI_MINOR;
20
21#[repr(C)]
26#[derive(Copy, Clone)]
27pub struct YogStr {
28 pub ptr: *const u8,
29 pub len: u32,
30}
31
32impl YogStr {
33 pub const EMPTY: Self = Self {
34 ptr: std::ptr::null(),
35 len: 0,
36 };
37
38 #[allow(clippy::should_implement_trait)]
40 #[inline]
41 pub fn from_str(s: &str) -> Self {
42 Self {
43 ptr: s.as_ptr(),
44 len: s.len() as u32,
45 }
46 }
47
48 #[inline]
49 pub fn is_empty(self) -> bool {
50 self.len == 0 || self.ptr.is_null()
51 }
52
53 #[inline]
58 pub unsafe fn as_str<'a>(self) -> &'a str {
59 unsafe {
60 if self.ptr.is_null() || self.len == 0 {
61 return "";
62 }
63 std::str::from_utf8_unchecked(std::slice::from_raw_parts(self.ptr, self.len as usize))
64 }
65 }
66}
67
68#[repr(C)]
72#[derive(Copy, Clone)]
73pub struct YogOwnedStr {
74 pub ptr: *mut u8,
75 pub len: u32,
76}
77
78impl YogOwnedStr {
79 pub const NONE: Self = Self {
80 ptr: std::ptr::null_mut(),
81 len: 0,
82 };
83
84 pub fn from_string(s: String) -> Self {
86 let len = s.len() as u32;
87 let ptr = Box::into_raw(s.into_bytes().into_boxed_slice()) as *mut u8;
88 Self { ptr, len }
89 }
90
91 #[inline]
92 pub fn is_none(self) -> bool {
93 self.ptr.is_null()
94 }
95}
96
97#[repr(C)]
99#[derive(Copy, Clone)]
100pub struct YogBlockPos {
101 pub x: i32,
102 pub y: i32,
103 pub z: i32,
104}
105
106#[repr(C)]
108#[derive(Copy, Clone)]
109pub struct YogVec3 {
110 pub x: f64,
111 pub y: f64,
112 pub z: f64,
113}
114
115#[repr(C)]
118pub struct YogBlockBreakEvent {
119 pub player: YogStr,
120 pub block: YogStr,
121 pub pos: YogBlockPos,
122 pub dimension: YogStr,
124}
125
126#[repr(C)]
127pub struct YogChatEvent {
128 pub player: YogStr,
129 pub message: YogStr,
130 pub dimension: YogStr,
131}
132
133#[repr(C)]
135pub struct YogPlayerEvent {
136 pub player: YogStr,
137 pub uuid: YogStr,
138 pub dimension: YogStr,
139}
140
141#[repr(C)]
142pub struct YogUseItemEvent {
143 pub player: YogStr,
144 pub item: YogStr,
145 pub sneaking: bool,
147 pub dimension: YogStr,
148}
149
150#[repr(C)]
151pub struct YogUseBlockEvent {
152 pub player: YogStr,
153 pub block: YogStr,
154 pub pos: YogBlockPos,
155 pub dimension: YogStr,
156}
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
711unsafe impl Send for YogGfxApi {}
712unsafe impl Sync for YogGfxApi {}
713
714#[repr(C)]
724pub struct YogServer {
725 pub ctx: *mut c_void,
726 pub abi_version: u32,
727 pub size: u32,
730
731 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
733
734 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
736
737 pub get_block:
739 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
740 pub set_block: unsafe extern "C" fn(
741 ctx: *mut c_void,
742 dim: YogStr,
743 pos: YogBlockPos,
744 block: YogStr,
745 ) -> bool,
746 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
747 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
748 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
749 pub set_weather:
750 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
751
752 pub give_item:
754 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
755 pub player_teleport:
756 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
757 pub send_to_player: unsafe extern "C" fn(
758 ctx: *mut c_void,
759 player: YogStr,
760 channel: YogStr,
761 data: *const u8,
762 len: u32,
763 ) -> bool,
764 pub send_to_server:
765 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
766 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
767 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
768 pub send_title: unsafe extern "C" fn(
769 ctx: *mut c_void,
770 player: YogStr,
771 title: YogStr,
772 sub: YogStr,
773 fi: i32,
774 stay: i32,
775 fo: i32,
776 ) -> bool,
777 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
778 pub play_sound: unsafe extern "C" fn(
779 ctx: *mut c_void,
780 dim: YogStr,
781 pos: YogVec3,
782 sound: YogStr,
783 vol: f32,
784 pitch: f32,
785 ) -> bool,
786 pub play_sound_player: unsafe extern "C" fn(
787 ctx: *mut c_void,
788 player: YogStr,
789 sound: YogStr,
790 vol: f32,
791 pitch: f32,
792 ) -> bool,
793
794 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
796 pub entity_position:
797 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
798 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
799 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
800 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
801 pub spawn_entity: unsafe extern "C" fn(
802 ctx: *mut c_void,
803 type_id: YogStr,
804 dim: YogStr,
805 pos: YogVec3,
806 ) -> YogOwnedStr,
807 pub entity_add_effect: unsafe extern "C" fn(
808 ctx: *mut c_void,
809 uuid: YogStr,
810 fx: YogStr,
811 dur: i32,
812 amp: u8,
813 particles: bool,
814 ) -> bool,
815 pub entity_remove_effect:
816 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
817 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
818 pub entity_velocity:
819 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
820 pub entity_set_velocity:
821 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
822 pub entity_add_velocity:
823 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
824
825 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
827 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
828 pub drop_loot:
829 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
830
831 pub scoreboard_get:
833 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
834 pub scoreboard_set:
835 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
836 pub scoreboard_add: unsafe extern "C" fn(
837 ctx: *mut c_void,
838 obj: YogStr,
839 player: YogStr,
840 delta: i32,
841 out: *mut i32,
842 ) -> bool,
843
844 pub bossbar_create: unsafe extern "C" fn(
846 ctx: *mut c_void,
847 id: YogStr,
848 title: YogStr,
849 color: YogStr,
850 style: YogStr,
851 ) -> bool,
852 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
853 pub bossbar_set_title:
854 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
855 pub bossbar_set_progress:
856 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
857 pub bossbar_set_color:
858 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
859 pub bossbar_add_player:
860 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
861 pub bossbar_remove_player:
862 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
863 pub bossbar_set_visible:
864 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
865
866 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
868
869 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
872
873 pub get_block_nbt:
876 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
877 pub set_block_nbt:
879 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
880
881 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
884 pub player_set_slot: unsafe extern "C" fn(
886 ctx: *mut c_void,
887 player: YogStr,
888 slot: u32,
889 item_id: YogStr,
890 count: u32,
891 ) -> bool,
892
893 pub get_inventory_slot: unsafe extern "C" fn(
897 ctx: *mut c_void,
898 dim: YogStr,
899 pos: YogBlockPos,
900 slot: u32,
901 ) -> YogOwnedStr,
902 pub set_inventory_slot: unsafe extern "C" fn(
906 ctx: *mut c_void,
907 dim: YogStr,
908 pos: YogBlockPos,
909 slot: u32,
910 item_id: YogStr,
911 count: u32,
912 ) -> bool,
913
914 pub player_teleport_dim:
916 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
917 pub entity_teleport_dim:
918 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
919
920 pub world_entity_count:
923 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
924
925 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
928 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
930
931 pub spawn_particles: unsafe extern "C" fn(
936 ctx: *mut c_void,
937 dim: YogStr,
938 pos: YogVec3,
939 particle_type: YogStr,
940 count: i32,
941 dx: f64,
942 dy: f64,
943 dz: f64,
944 speed: f64,
945 ) -> bool,
946
947 pub entity_attribute_get:
952 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
953 pub entity_attribute_set: unsafe extern "C" fn(
955 ctx: *mut c_void,
956 uuid: YogStr,
957 attribute_id: YogStr,
958 value: f64,
959 ) -> bool,
960
961 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
965 pub set_held_item_nbt:
968 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
969
970 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
973 pub set_offhand_item_nbt:
976 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
977 pub get_slot_item:
980 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
981 pub set_slot_item: unsafe extern "C" fn(
984 ctx: *mut c_void,
985 player: YogStr,
986 slot: u32,
987 item_id: YogStr,
988 count: u32,
989 snbt: YogStr,
990 ) -> bool,
991
992 pub entity_rotation:
996 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
997
998 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1003 pub entities_in_box: unsafe extern "C" fn(
1005 ctx: *mut c_void,
1006 dim: YogStr,
1007 min: YogVec3,
1008 max: YogVec3,
1009 ) -> YogOwnedStr,
1010 pub raycast_block: unsafe extern "C" fn(
1012 ctx: *mut c_void,
1013 dim: YogStr,
1014 from: YogVec3,
1015 to: YogVec3,
1016 ) -> YogOwnedStr,
1017 pub raycast_entity: unsafe extern "C" fn(
1019 ctx: *mut c_void,
1020 dim: YogStr,
1021 from: YogVec3,
1022 to: YogVec3,
1023 exclude: YogStr,
1024 ) -> YogOwnedStr,
1025 pub block_info:
1027 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1028 pub break_block: unsafe extern "C" fn(
1029 ctx: *mut c_void,
1030 dim: YogStr,
1031 pos: YogBlockPos,
1032 drop: bool,
1033 breaker: YogStr,
1034 ) -> bool,
1035 pub place_block_from_slot: unsafe extern "C" fn(
1036 ctx: *mut c_void,
1037 player: YogStr,
1038 slot: u32,
1039 dim: YogStr,
1040 pos: YogBlockPos,
1041 ) -> bool,
1042 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1043 pub explode: unsafe extern "C" fn(
1044 ctx: *mut c_void,
1045 dim: YogStr,
1046 pos: YogVec3,
1047 power: f32,
1048 fire: bool,
1049 source: YogStr,
1050 ) -> bool,
1051 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1053 pub entity_damage: unsafe extern "C" fn(
1054 ctx: *mut c_void,
1055 uuid: YogStr,
1056 amount: f32,
1057 damage_type: YogStr,
1058 attacker: YogStr,
1059 ) -> bool,
1060 pub entity_set_fire_ticks:
1061 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1062 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1063 pub player_set_may_fly:
1064 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1065 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1067 pub spawn_item: unsafe extern "C" fn(
1069 ctx: *mut c_void,
1070 dim: YogStr,
1071 pos: YogVec3,
1072 vel: YogVec3,
1073 item_id: YogStr,
1074 count: u32,
1075 snbt: YogStr,
1076 ) -> YogOwnedStr,
1077 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1079 pub item_entity_set_stack: unsafe extern "C" fn(
1080 ctx: *mut c_void,
1081 uuid: YogStr,
1082 item_id: YogStr,
1083 count: u32,
1084 snbt: YogStr,
1085 ) -> bool,
1086 pub actionbar_json:
1089 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1090 pub use_item_on_block: unsafe extern "C" fn(
1092 ctx: *mut c_void,
1093 dim: YogStr,
1094 pos: YogBlockPos,
1095 face: u8,
1096 item_id: YogStr,
1097 player: YogStr,
1098 ) -> bool,
1099 pub pour_fluid: unsafe extern "C" fn(
1100 ctx: *mut c_void,
1101 dim: YogStr,
1102 pos: YogBlockPos,
1103 bucket_item_id: YogStr,
1104 ) -> bool,
1105 pub has_entity_tag:
1106 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1107 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1109 pub place_feature: unsafe extern "C" fn(
1110 ctx: *mut c_void,
1111 dim: YogStr,
1112 pos: YogBlockPos,
1113 feature_id: YogStr,
1114 ) -> bool,
1115
1116 pub set_item_cooldown:
1118 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1119 pub entity_teleport_with_passengers:
1120 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1121 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1123 pub set_redstone_output:
1124 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1125 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1127 pub set_block_state:
1128 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1129 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1130 pub world_set_thunder:
1131 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1132 pub fill_region: unsafe extern "C" fn(
1134 ctx: *mut c_void,
1135 dim: YogStr,
1136 from: YogBlockPos,
1137 to: YogBlockPos,
1138 state: YogStr,
1139 ) -> i32,
1140 pub scan_region:
1142 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1143}
1144
1145unsafe impl Send for YogServer {}
1147unsafe impl Sync for YogServer {}
1148
1149#[repr(C)]
1156#[derive(Copy, Clone)]
1157pub struct YogChunkWriterApi {
1158 pub chunk_x: i32,
1160 pub chunk_z: i32,
1162 pub min_y: i32,
1164 pub height: i32,
1166 pub ctx: *mut c_void,
1168 pub set_block:
1171 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1172}
1173
1174unsafe impl Send for YogChunkWriterApi {}
1175unsafe impl Sync for YogChunkWriterApi {}
1176
1177pub type YogChunkGeneratorFn =
1180 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1181
1182#[repr(C)]
1191pub struct YogApi {
1192 pub abi_version: u32,
1193 pub size: u32,
1195 pub ctx: *mut c_void,
1197 pub server: *const YogServer,
1199
1200 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1203 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1204 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1205 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1206 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1207 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1208 pub on_attack_entity:
1209 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1210 pub on_entity_damage:
1211 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1212 pub on_entity_death:
1213 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1214 pub on_entity_spawn:
1215 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1216 pub on_player_place_block:
1217 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1218 pub on_player_death:
1219 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1220 pub on_player_respawn:
1221 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1222 pub on_advancement:
1223 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1224 pub on_entity_interact:
1226 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1227 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1228 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1229 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1231 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1232 pub on_container_open:
1233 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1234 pub on_container_close:
1235 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1236 pub on_projectile_hit:
1237 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1238 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1239 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1240 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1241
1242 pub on_packet:
1244 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1245 pub on_client_packet:
1246 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1247
1248 pub register_command:
1250 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1251 pub register_typed_command: unsafe extern "C" fn(
1252 ctx: *mut c_void,
1253 name: YogStr,
1254 schema: YogStr,
1255 ud: *mut c_void,
1256 h: YogCommandFn,
1257 ),
1258
1259 pub register_recipe_json:
1263 unsafe extern "C" fn(ctx: *mut c_void, namespace: YogStr, name: YogStr, json: YogStr),
1264
1265 pub register_item: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogItemDef),
1267 pub register_block: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogBlockDef),
1268
1269 pub schedule_once: unsafe extern "C" fn(
1271 ctx: *mut c_void,
1272 delay_ticks: u64,
1273 ud: *mut c_void,
1274 h: YogScheduledFn,
1275 ),
1276 pub schedule_repeating: unsafe extern "C" fn(
1277 ctx: *mut c_void,
1278 period_ticks: u64,
1279 ud: *mut c_void,
1280 h: YogScheduledFn,
1281 ),
1282
1283 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1285 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1286 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1287 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1288 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1289
1290 pub on_world_render:
1295 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1296
1297 pub register_startup_grant:
1299 unsafe extern "C" fn(ctx: *mut c_void, grant: *const YogStartupGrantDef),
1300
1301 pub register_book: unsafe extern "C" fn(ctx: *mut c_void, book_id: YogStr, book_json: YogStr),
1303
1304 pub register_ui: unsafe extern "C" fn(
1309 ctx: *mut c_void,
1310 ui_id: YogStr,
1311 layout_json: YogStr,
1312 ud: *mut c_void,
1313 h: YogUIEventFn,
1314 ),
1315
1316 pub on_ui_render:
1323 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1324
1325 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1331
1332 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1339 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1342
1343 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1348
1349 pub register_inventory: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogInventoryDef),
1352
1353 pub interop_export:
1357 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1358 pub interop_import:
1361 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1362
1363 pub register_dimension_json: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, json: YogStr),
1369 pub register_chunk_generator:
1373 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1374
1375 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1380 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1384
1385 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1393
1394 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1399 pub client_play_sound: unsafe extern "C" fn(
1403 ctx: *mut c_void,
1404 sound_id: YogStr,
1405 volume: f32,
1406 pitch: f32,
1407 looping: bool,
1408 ) -> u32,
1409 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1411 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1414 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1416}
1417
1418pub mod ui_flags {
1420 pub const MODAL: u32 = 1;
1422 pub const PAUSE: u32 = 1 << 1;
1424 pub const NO_BACKGROUND: u32 = 1 << 2;
1426}
1427
1428unsafe impl Send for YogApi {}
1429unsafe impl Sync for YogApi {}