1use std::os::raw::c_void;
13
14pub const ABI_MAJOR: u32 = 1;
17pub const ABI_MINOR: u32 = 5;
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 pub draw2d_text_scaled: unsafe extern "C" fn(
724 text: YogStr,
725 font: YogStr,
726 x: f32,
727 y: f32,
728 scale: f32,
729 color: u32,
730 shadow: bool,
731 ),
732 pub draw2d_blocks:
736 unsafe extern "C" fn(blocks: YogStr, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32),
737}
738
739unsafe impl Send for YogGfxApi {}
740unsafe impl Sync for YogGfxApi {}
741
742#[repr(C)]
752pub struct YogServer {
753 pub ctx: *mut c_void,
754 pub abi_version: u32,
755 pub size: u32,
758
759 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
761
762 pub broadcast: unsafe extern "C" fn(ctx: *mut c_void, msg: YogStr),
764
765 pub get_block:
767 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
768 pub set_block: unsafe extern "C" fn(
769 ctx: *mut c_void,
770 dim: YogStr,
771 pos: YogBlockPos,
772 block: YogStr,
773 ) -> bool,
774 pub world_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, out: *mut i64) -> bool,
775 pub set_time: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, time: i64) -> bool,
776 pub is_raining: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
777 pub set_weather:
778 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, raining: bool, dur: i32) -> bool,
779
780 pub give_item:
782 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item: YogStr, count: u32) -> bool,
783 pub player_teleport:
784 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, pos: YogVec3) -> bool,
785 pub send_to_player: unsafe extern "C" fn(
786 ctx: *mut c_void,
787 player: YogStr,
788 channel: YogStr,
789 data: *const u8,
790 len: u32,
791 ) -> bool,
792 pub send_to_server:
793 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, data: *const u8, len: u32) -> bool,
794 pub kick_player: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, reason: YogStr) -> bool,
795 pub set_gamemode: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, mode: YogStr) -> bool,
796 pub send_title: unsafe extern "C" fn(
797 ctx: *mut c_void,
798 player: YogStr,
799 title: YogStr,
800 sub: YogStr,
801 fi: i32,
802 stay: i32,
803 fo: i32,
804 ) -> bool,
805 pub send_actionbar: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, msg: YogStr) -> bool,
806 pub play_sound: unsafe extern "C" fn(
807 ctx: *mut c_void,
808 dim: YogStr,
809 pos: YogVec3,
810 sound: YogStr,
811 vol: f32,
812 pitch: f32,
813 ) -> bool,
814 pub play_sound_player: unsafe extern "C" fn(
815 ctx: *mut c_void,
816 player: YogStr,
817 sound: YogStr,
818 vol: f32,
819 pitch: f32,
820 ) -> bool,
821
822 pub entity_teleport: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, pos: YogVec3) -> bool,
824 pub entity_position:
825 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
826 pub entity_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut f32) -> bool,
827 pub entity_set_health: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, hp: f32) -> bool,
828 pub entity_kill: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
829 pub spawn_entity: unsafe extern "C" fn(
830 ctx: *mut c_void,
831 type_id: YogStr,
832 dim: YogStr,
833 pos: YogVec3,
834 ) -> YogOwnedStr,
835 pub entity_add_effect: unsafe extern "C" fn(
836 ctx: *mut c_void,
837 uuid: YogStr,
838 fx: YogStr,
839 dur: i32,
840 amp: u8,
841 particles: bool,
842 ) -> bool,
843 pub entity_remove_effect:
844 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, fx: YogStr) -> bool,
845 pub entity_clear_effects: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> bool,
846 pub entity_velocity:
847 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
848 pub entity_set_velocity:
849 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
850 pub entity_add_velocity:
851 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, vel: YogVec3) -> bool,
852
853 pub has_item_tag: unsafe extern "C" fn(ctx: *mut c_void, item: YogStr, tag: YogStr) -> bool,
855 pub has_block_tag: unsafe extern "C" fn(ctx: *mut c_void, block: YogStr, tag: YogStr) -> bool,
856 pub drop_loot:
857 unsafe extern "C" fn(ctx: *mut c_void, table: YogStr, dim: YogStr, pos: YogVec3) -> bool,
858
859 pub scoreboard_get:
861 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, out: *mut i32) -> bool,
862 pub scoreboard_set:
863 unsafe extern "C" fn(ctx: *mut c_void, obj: YogStr, player: YogStr, score: i32) -> bool,
864 pub scoreboard_add: unsafe extern "C" fn(
865 ctx: *mut c_void,
866 obj: YogStr,
867 player: YogStr,
868 delta: i32,
869 out: *mut i32,
870 ) -> bool,
871
872 pub bossbar_create: unsafe extern "C" fn(
874 ctx: *mut c_void,
875 id: YogStr,
876 title: YogStr,
877 color: YogStr,
878 style: YogStr,
879 ) -> bool,
880 pub bossbar_remove: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr) -> bool,
881 pub bossbar_set_title:
882 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, title: YogStr) -> bool,
883 pub bossbar_set_progress:
884 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, progress: f32) -> bool,
885 pub bossbar_set_color:
886 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, color: YogStr) -> bool,
887 pub bossbar_add_player:
888 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
889 pub bossbar_remove_player:
890 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, player: YogStr) -> bool,
891 pub bossbar_set_visible:
892 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, visible: bool) -> bool,
893
894 pub game_dir: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
896
897 pub online_players: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
900
901 pub get_block_nbt:
904 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
905 pub set_block_nbt:
907 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, snbt: YogStr) -> bool,
908
909 pub player_inventory: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
912 pub player_set_slot: unsafe extern "C" fn(
914 ctx: *mut c_void,
915 player: YogStr,
916 slot: u32,
917 item_id: YogStr,
918 count: u32,
919 ) -> bool,
920
921 pub get_inventory_slot: unsafe extern "C" fn(
925 ctx: *mut c_void,
926 dim: YogStr,
927 pos: YogBlockPos,
928 slot: u32,
929 ) -> YogOwnedStr,
930 pub set_inventory_slot: unsafe extern "C" fn(
934 ctx: *mut c_void,
935 dim: YogStr,
936 pos: YogBlockPos,
937 slot: u32,
938 item_id: YogStr,
939 count: u32,
940 ) -> bool,
941
942 pub player_teleport_dim:
944 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, dim: YogStr, pos: YogVec3) -> bool,
945 pub entity_teleport_dim:
946 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
947
948 pub world_entity_count:
951 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, entity_type: YogStr) -> i32,
952
953 pub entity_get_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
956 pub entity_set_nbt: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, snbt: YogStr) -> bool,
958
959 pub spawn_particles: unsafe extern "C" fn(
964 ctx: *mut c_void,
965 dim: YogStr,
966 pos: YogVec3,
967 particle_type: YogStr,
968 count: i32,
969 dx: f64,
970 dy: f64,
971 dz: f64,
972 speed: f64,
973 ) -> bool,
974
975 pub entity_attribute_get:
980 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, attribute_id: YogStr) -> f64,
981 pub entity_attribute_set: unsafe extern "C" fn(
983 ctx: *mut c_void,
984 uuid: YogStr,
985 attribute_id: YogStr,
986 value: f64,
987 ) -> bool,
988
989 pub get_held_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
993 pub set_held_item_nbt:
996 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
997
998 pub get_offhand_item_nbt: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1001 pub set_offhand_item_nbt:
1004 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, snbt: YogStr) -> bool,
1005 pub get_slot_item:
1008 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, slot: u32) -> YogOwnedStr,
1009 pub set_slot_item: unsafe extern "C" fn(
1012 ctx: *mut c_void,
1013 player: YogStr,
1014 slot: u32,
1015 item_id: YogStr,
1016 count: u32,
1017 snbt: YogStr,
1018 ) -> bool,
1019
1020 pub entity_rotation:
1024 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, out: *mut YogVec3) -> bool,
1025
1026 pub entity_info: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1031 pub entities_in_box: unsafe extern "C" fn(
1033 ctx: *mut c_void,
1034 dim: YogStr,
1035 min: YogVec3,
1036 max: YogVec3,
1037 ) -> YogOwnedStr,
1038 pub raycast_block: unsafe extern "C" fn(
1040 ctx: *mut c_void,
1041 dim: YogStr,
1042 from: YogVec3,
1043 to: YogVec3,
1044 ) -> YogOwnedStr,
1045 pub raycast_entity: unsafe extern "C" fn(
1047 ctx: *mut c_void,
1048 dim: YogStr,
1049 from: YogVec3,
1050 to: YogVec3,
1051 exclude: YogStr,
1052 ) -> YogOwnedStr,
1053 pub block_info:
1055 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1056 pub break_block: unsafe extern "C" fn(
1057 ctx: *mut c_void,
1058 dim: YogStr,
1059 pos: YogBlockPos,
1060 drop: bool,
1061 breaker: YogStr,
1062 ) -> bool,
1063 pub place_block_from_slot: unsafe extern "C" fn(
1064 ctx: *mut c_void,
1065 player: YogStr,
1066 slot: u32,
1067 dim: YogStr,
1068 pos: YogBlockPos,
1069 ) -> bool,
1070 pub bonemeal: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> bool,
1071 pub explode: unsafe extern "C" fn(
1072 ctx: *mut c_void,
1073 dim: YogStr,
1074 pos: YogVec3,
1075 power: f32,
1076 fire: bool,
1077 source: YogStr,
1078 ) -> bool,
1079 pub tellraw: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1081 pub entity_damage: unsafe extern "C" fn(
1082 ctx: *mut c_void,
1083 uuid: YogStr,
1084 amount: f32,
1085 damage_type: YogStr,
1086 attacker: YogStr,
1087 ) -> bool,
1088 pub entity_set_fire_ticks:
1089 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, ticks: i32) -> bool,
1090 pub player_add_xp: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, amount: i32) -> bool,
1091 pub player_set_may_fly:
1092 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, may_fly: bool) -> bool,
1093 pub player_info: unsafe extern "C" fn(ctx: *mut c_void, player: YogStr) -> YogOwnedStr,
1095 pub spawn_item: unsafe extern "C" fn(
1097 ctx: *mut c_void,
1098 dim: YogStr,
1099 pos: YogVec3,
1100 vel: YogVec3,
1101 item_id: YogStr,
1102 count: u32,
1103 snbt: YogStr,
1104 ) -> YogOwnedStr,
1105 pub item_entity_stack: unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr) -> YogOwnedStr,
1107 pub item_entity_set_stack: unsafe extern "C" fn(
1108 ctx: *mut c_void,
1109 uuid: YogStr,
1110 item_id: YogStr,
1111 count: u32,
1112 snbt: YogStr,
1113 ) -> bool,
1114 pub actionbar_json:
1117 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, json: YogStr) -> bool,
1118 pub use_item_on_block: unsafe extern "C" fn(
1120 ctx: *mut c_void,
1121 dim: YogStr,
1122 pos: YogBlockPos,
1123 face: u8,
1124 item_id: YogStr,
1125 player: YogStr,
1126 ) -> bool,
1127 pub pour_fluid: unsafe extern "C" fn(
1128 ctx: *mut c_void,
1129 dim: YogStr,
1130 pos: YogBlockPos,
1131 bucket_item_id: YogStr,
1132 ) -> bool,
1133 pub has_entity_tag:
1134 unsafe extern "C" fn(ctx: *mut c_void, entity_type: YogStr, tag_id: YogStr) -> bool,
1135 pub item_block: unsafe extern "C" fn(ctx: *mut c_void, item_id: YogStr) -> YogOwnedStr,
1137 pub place_feature: unsafe extern "C" fn(
1138 ctx: *mut c_void,
1139 dim: YogStr,
1140 pos: YogBlockPos,
1141 feature_id: YogStr,
1142 ) -> bool,
1143
1144 pub set_item_cooldown:
1146 unsafe extern "C" fn(ctx: *mut c_void, player: YogStr, item_id: YogStr, ticks: i32) -> bool,
1147 pub entity_teleport_with_passengers:
1148 unsafe extern "C" fn(ctx: *mut c_void, uuid: YogStr, dim: YogStr, pos: YogVec3) -> bool,
1149 pub redstone_power: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> i32,
1151 pub set_redstone_output:
1152 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, level: i32) -> bool,
1153 pub get_block_state: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos) -> YogOwnedStr,
1155 pub set_block_state:
1156 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, pos: YogBlockPos, state: YogStr) -> bool,
1157 pub world_is_thundering: unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr) -> bool,
1158 pub world_set_thunder:
1159 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, thundering: bool, duration_ticks: i32) -> bool,
1160 pub fill_region: unsafe extern "C" fn(
1162 ctx: *mut c_void,
1163 dim: YogStr,
1164 from: YogBlockPos,
1165 to: YogBlockPos,
1166 state: YogStr,
1167 ) -> i32,
1168 pub scan_region:
1170 unsafe extern "C" fn(ctx: *mut c_void, dim: YogStr, from: YogBlockPos, to: YogBlockPos) -> YogOwnedStr,
1171}
1172
1173unsafe impl Send for YogServer {}
1175unsafe impl Sync for YogServer {}
1176
1177#[repr(C)]
1184#[derive(Copy, Clone)]
1185pub struct YogChunkWriterApi {
1186 pub chunk_x: i32,
1188 pub chunk_z: i32,
1190 pub min_y: i32,
1192 pub height: i32,
1194 pub ctx: *mut c_void,
1196 pub set_block:
1199 unsafe extern "C" fn(ctx: *mut c_void, x: i32, y: i32, z: i32, block_id: YogStr) -> bool,
1200}
1201
1202unsafe impl Send for YogChunkWriterApi {}
1203unsafe impl Sync for YogChunkWriterApi {}
1204
1205pub type YogChunkGeneratorFn =
1208 unsafe extern "C" fn(ud: *mut c_void, writer: *const YogChunkWriterApi);
1209
1210#[repr(C)]
1219pub struct YogApi {
1220 pub abi_version: u32,
1221 pub size: u32,
1223 pub ctx: *mut c_void,
1225 pub server: *const YogServer,
1227
1228 pub on_block_break: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogBlockBreakFn),
1231 pub on_chat: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogChatFn),
1232 pub on_player_join: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1233 pub on_player_leave: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerFn),
1234 pub on_use_item: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseItemFn),
1235 pub on_use_block: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogUseBlockFn),
1236 pub on_attack_entity:
1237 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAttackEntityFn),
1238 pub on_entity_damage:
1239 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDamageFn),
1240 pub on_entity_death:
1241 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityDeathFn),
1242 pub on_entity_spawn:
1243 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntitySpawnFn),
1244 pub on_player_place_block:
1245 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlaceBlockFn),
1246 pub on_player_death:
1247 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerDeathFn),
1248 pub on_player_respawn:
1249 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerRespawnFn),
1250 pub on_advancement:
1251 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogAdvancementFn),
1252 pub on_entity_interact:
1254 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogEntityInteractFn),
1255 pub on_item_craft: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogCraftFn),
1256 pub on_explosion: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogExplosionFn),
1257 pub on_item_pickup: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogItemPickupFn),
1259 pub on_player_move: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogPlayerMoveFn),
1260 pub on_container_open:
1261 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerOpenFn),
1262 pub on_container_close:
1263 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogContainerCloseFn),
1264 pub on_projectile_hit:
1265 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogProjectileHitFn),
1266 pub on_server_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1267 pub on_server_started: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1268 pub on_server_stopping: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogServerFn),
1269
1270 pub on_packet:
1272 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1273 pub on_client_packet:
1274 unsafe extern "C" fn(ctx: *mut c_void, channel: YogStr, ud: *mut c_void, h: YogPacketFn),
1275
1276 pub register_command:
1278 unsafe extern "C" fn(ctx: *mut c_void, name: YogStr, ud: *mut c_void, h: YogCommandFn),
1279 pub register_typed_command: unsafe extern "C" fn(
1280 ctx: *mut c_void,
1281 name: YogStr,
1282 schema: YogStr,
1283 ud: *mut c_void,
1284 h: YogCommandFn,
1285 ),
1286
1287 pub register_recipe_json:
1291 unsafe extern "C" fn(ctx: *mut c_void, namespace: YogStr, name: YogStr, json: YogStr),
1292
1293 pub register_item: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogItemDef),
1295 pub register_block: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogBlockDef),
1296
1297 pub schedule_once: unsafe extern "C" fn(
1299 ctx: *mut c_void,
1300 delay_ticks: u64,
1301 ud: *mut c_void,
1302 h: YogScheduledFn,
1303 ),
1304 pub schedule_repeating: unsafe extern "C" fn(
1305 ctx: *mut c_void,
1306 period_ticks: u64,
1307 ud: *mut c_void,
1308 h: YogScheduledFn,
1309 ),
1310
1311 pub on_client_tick: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogClientFn),
1313 pub on_hud_render: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogHudRenderFn),
1314 pub on_key_press: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogKeyPressFn),
1315 pub on_screen_open: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1316 pub on_screen_close: unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogScreenFn),
1317
1318 pub on_world_render:
1323 unsafe extern "C" fn(ctx: *mut c_void, ud: *mut c_void, h: YogWorldRenderFn),
1324
1325 pub register_startup_grant:
1327 unsafe extern "C" fn(ctx: *mut c_void, grant: *const YogStartupGrantDef),
1328
1329 pub register_book: unsafe extern "C" fn(ctx: *mut c_void, book_id: YogStr, book_json: YogStr),
1331
1332 pub register_ui: unsafe extern "C" fn(
1337 ctx: *mut c_void,
1338 ui_id: YogStr,
1339 layout_json: YogStr,
1340 ud: *mut c_void,
1341 h: YogUIEventFn,
1342 ),
1343
1344 pub on_ui_render:
1351 unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, ud: *mut c_void, h: YogHudRenderFn),
1352
1353 pub register_menu_entry: unsafe extern "C" fn(ctx: *mut c_void, label: YogStr, ui_id: YogStr),
1359
1360 pub mods_list: unsafe extern "C" fn(ctx: *mut c_void) -> YogOwnedStr,
1367 pub free_str: unsafe extern "C" fn(ptr: *mut u8, len: u32),
1370
1371 pub ui_open: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, modal: bool, pause: bool),
1376
1377 pub register_inventory: unsafe extern "C" fn(ctx: *mut c_void, def: *const YogInventoryDef),
1380
1381 pub interop_export:
1385 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr, ptr: *const c_void),
1386 pub interop_import:
1389 unsafe extern "C" fn(ctx: *mut c_void, mod_id: YogStr, symbol: YogStr) -> *const c_void,
1390
1391 pub register_dimension_json: unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, json: YogStr),
1397 pub register_chunk_generator:
1401 unsafe extern "C" fn(ctx: *mut c_void, id: YogStr, ud: *mut c_void, h: YogChunkGeneratorFn),
1402
1403 pub ui_close: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr),
1408 pub ui_consume_event: unsafe extern "C" fn(ctx: *mut c_void),
1412
1413 pub translate: unsafe extern "C" fn(ctx: *mut c_void, key: YogStr) -> YogOwnedStr,
1421
1422 pub ui_open_flags: unsafe extern "C" fn(ctx: *mut c_void, ui_id: YogStr, flags: u32),
1427 pub client_play_sound: unsafe extern "C" fn(
1431 ctx: *mut c_void,
1432 sound_id: YogStr,
1433 volume: f32,
1434 pitch: f32,
1435 looping: bool,
1436 ) -> u32,
1437 pub client_stop_sound: unsafe extern "C" fn(ctx: *mut c_void, handle: u32),
1439 pub client_held_item: unsafe extern "C" fn(ctx: *mut c_void, off_hand: bool) -> YogOwnedStr,
1442 pub client_key_down: unsafe extern "C" fn(ctx: *mut c_void, key: i32) -> bool,
1444}
1445
1446pub mod ui_flags {
1448 pub const MODAL: u32 = 1;
1450 pub const PAUSE: u32 = 1 << 1;
1452 pub const NO_BACKGROUND: u32 = 1 << 2;
1454}
1455
1456unsafe impl Send for YogApi {}
1457unsafe impl Sync for YogApi {}