pub mod client;
mod interop;
mod lang;
mod registry;
pub use interop::Interop;
pub use lang::{format_translation, tr, tr_args, translation};
pub use registry::{
CServer, Mod, ModInfo, Registry, UiHandled, close_ui, installed_mods, open_ui, server,
};
pub use yog_gfx::{
GfxContext, core as gfx_core, draw2d as gfx_draw2d, gl as gfx_gl, image as gfx_image,
};
pub use yog_abi::{ABI_VERSION, YogApi};
pub use yog_interop::{bench, import, yog_export};
pub use rkyv;
pub use ctor;
#[doc(hidden)]
pub use std::os::raw::c_void as __c_void;
#[doc(hidden)]
pub use yog_abi::{YogGfxApi as __YogGfxApi, YogStr as __YogStr};
#[macro_export]
macro_rules! export_mod {
($mod_ty:ty) => {
#[unsafe(no_mangle)]
pub extern "C" fn yog_abi_version() -> u32 {
$crate::ABI_VERSION
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn yog_mod_register(
api: *const $crate::YogApi,
mod_id_ptr: *const ::std::os::raw::c_char,
) {
let mod_id: &str = if mod_id_ptr.is_null() {
"unknown"
} else {
match unsafe { ::std::ffi::CStr::from_ptr(mod_id_ptr) }.to_str() {
Ok(s) => s,
Err(_) => "unknown",
}
};
$crate::__set_current_mod_id(mod_id);
$crate::__set_current_api_ptr(api as usize);
let outcome = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| {
let mut registry = unsafe { $crate::Registry::from_raw(api) };
<$mod_ty as $crate::Mod>::register(&mut registry);
let content: ::std::vec::Vec<fn(&mut $crate::Registry)> =
$crate::__yog_content_registrars()
.lock()
.unwrap_or_else(|e| e.into_inner())
.clone();
for register in content {
register(&mut registry);
}
for entry in $crate::__yog_export_registry().lock().unwrap().iter() {
registry
.interop()
.export(entry.name, entry.ptr as *const ::std::os::raw::c_void);
}
$crate::__yog_resolve_pending_imports(®istry);
}));
if outcome.is_err() {
$crate::error!(
"mod {} panicked during register",
::core::stringify!($mod_ty)
);
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn __yog_resolve_imports_final(api: *const $crate::YogApi) {
let registry = unsafe { $crate::Registry::from_raw(api) };
$crate::__yog_resolve_pending_imports(®istry);
}
#[unsafe(no_mangle)]
pub extern "C" fn yog_ui_designer_abi() -> u32 {
$crate::ui::component::designer::ABI
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn yog_ui_designer(
request: $crate::__YogStr,
gfx: *const $crate::__YogGfxApi,
user_data: *mut $crate::__c_void,
write: $crate::ui::component::designer::WriteFn,
) -> bool {
unsafe { $crate::ui::component::designer::call(request, gfx, user_data, write) }
}
};
}
#[macro_export]
macro_rules! ui_component {
($($ty:ty),+ $(,)?) => {
const _: () = {
#[$crate::ctor::ctor(unsafe, crate_path = $crate::ctor)]
fn __yog_register_ui_components() {
$( $crate::ui::component::register::<$ty>(); )+
}
};
};
}
#[macro_export]
macro_rules! ui_components {
() => {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/generated/components.g.rs"
));
};
}
#[doc(hidden)]
pub fn __set_current_mod_id(id: &str) {
CURRENT_MOD_ID.with(|cell| cell.replace(Some(id.to_string())));
}
#[doc(hidden)]
pub fn __current_mod_id() -> Option<String> {
CURRENT_MOD_ID.with(|cell| cell.borrow().clone())
}
#[doc(hidden)]
pub fn __set_current_api_ptr(ptr: usize) {
API_PTR.store(ptr, std::sync::atomic::Ordering::Release);
}
#[doc(hidden)]
pub fn __current_api_ptr() -> usize {
API_PTR.load(std::sync::atomic::Ordering::Acquire)
}
static API_PTR: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
std::thread_local! {
static CURRENT_MOD_ID: std::cell::RefCell<Option<String>> = const { std::cell::RefCell::new(None) };
}
#[doc(hidden)]
pub struct YogExportEntry {
pub name: &'static str,
pub ptr: usize,
}
#[doc(hidden)]
pub struct YogImportEntry {
pub mod_id: &'static str,
pub symbol: &'static str,
pub bind_fn: usize,
}
#[doc(hidden)]
pub fn __yog_export_registry() -> &'static std::sync::Mutex<Vec<YogExportEntry>> {
static REG: std::sync::LazyLock<std::sync::Mutex<Vec<YogExportEntry>>> =
std::sync::LazyLock::new(|| std::sync::Mutex::new(Vec::new()));
®
}
#[doc(hidden)]
pub fn __yog_content_registrars() -> &'static std::sync::Mutex<Vec<fn(&mut Registry)>> {
static REG: std::sync::Mutex<Vec<fn(&mut Registry)>> = std::sync::Mutex::new(Vec::new());
®
}
#[doc(hidden)]
pub fn __yog_import_registry() -> &'static std::sync::Mutex<Vec<YogImportEntry>> {
static REG: std::sync::LazyLock<std::sync::Mutex<Vec<YogImportEntry>>> =
std::sync::LazyLock::new(|| std::sync::Mutex::new(Vec::new()));
®
}
#[doc(hidden)]
pub unsafe fn __yog_resolve_pending_imports(registry: &crate::Registry) {
unsafe {
let interop = registry.interop();
for entry in __yog_import_registry().lock().unwrap().iter() {
if let Some(ptr) = interop.import_raw(entry.mod_id, entry.symbol) {
let bind: unsafe extern "C" fn(*const std::ffi::c_void) =
std::mem::transmute(entry.bind_fn);
bind(ptr);
}
}
}
}
pub use yog_book::{Book, BookCategory, BookEntry, BookMacro, BookPage, BookRegistry};
pub use yog_book::{BookFontRegistry, BookRenderer};
pub use yog_book::{
crafting_page, entity_page, image_page, pattern_page, relations_page, smelting_page,
spotlight_page, text_page, text_page_titled,
};
pub use yog_command::CommandContext;
pub use yog_config::Config;
pub use yog_core::{BlockPos, Server};
pub use yog_dimensions::{ChunkWriter, YogDimensionDef, YogDimensionTypeDef};
pub use yog_entity::Entity;
pub use yog_event::{
AdvancementEvent, AttackEntityEvent, BlockBreakEvent, ChatEvent, ClientTickEvent,
ContainerCloseEvent, ContainerOpenEvent, CraftEvent, EntityDamageEvent, EntityDeathEvent,
EntityInteractEvent, EntitySpawnEvent, EventPhase, ExplosionEvent, ItemPickupEvent,
KeyPressEvent, PlaceBlockEvent, PlayerDeathEvent, PlayerJoinEvent, PlayerLeaveEvent,
PlayerMoveEvent, PlayerRespawnEvent, ProjectileHitEvent, ScreenEvent, UseBlockEvent,
UseItemEvent,
};
pub use yog_inventory::{InventoryDef, SlotLayout};
#[doc(inline)]
pub use yog_network::packet;
pub use yog_network::{Packet, PacketEvent, PacketField};
pub use yog_player::Player;
pub use yog_registry::{
AdvancementReward, BlockDef, BookRecipe, FoodDef, FurnaceRecipe, ItemDef, ItemModifier,
ShapedRecipe, ShapelessRecipe, StartupGrant,
};
pub use yog_storage::{Storage, StorageScope, Value};
pub use yog_ui::{
Align, Dock, FlexDir, FocusStyle, LayoutNode, Rect, Stretch, UiRoot, Units, widget,
};
pub use yog_world::World;
pub use yog_logging::{error, info, warn};
pub mod core {
pub use yog_core::*;
}
pub mod event {
pub use yog_event::*;
}
pub mod world {
pub use yog_world::*;
}
pub mod entity {
pub use yog_entity::*;
}
pub mod player {
pub use yog_player::*;
}
pub mod content {
pub use yog_registry::*;
}
pub mod network {
pub use yog_network::*;
}
pub mod command {
pub use yog_command::*;
}
pub mod dimension {
pub use yog_dimensions::*;
}
pub mod storage {
pub use yog_storage::*;
}
pub mod config {
pub use yog_config::*;
}
pub mod book {
pub use yog_book::*;
}
pub mod ui {
pub use yog_ui::*;
}
#[macro_export]
macro_rules! ui_include {
($name:literal) => {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/generated/",
$name,
".g.rs"
));
};
}
#[macro_export]
macro_rules! resources {
() => {
pub mod res {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/generated/resources.g.rs"
));
}
};
}
#[macro_export]
macro_rules! content {
() => {
pub mod content {
include!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/generated/yog-content.g.rs"
));
}
};
}
pub mod inventory {
pub use yog_inventory::*;
}