跳到正文

Mosberg API

作者:Mosberg

A comprehensive Fabric API library for Minecraft 1.21.10+ mod development, designed to eliminate boilerplate code and accelerate mod creation with powerful utilities, enhanced registries, streamlined commands, and advanced client-side systems.

收藏

介绍

中文介绍正在准备中,下面暂时显示原文。

🏗️ Mosberg API – Minecraft Fabric Library

A comprehensive Fabric API library for Minecraft 1.21.10 that eliminates boilerplate and accelerates mod development.


⚡ What is Mosberg API?

Mosberg API is a developer library mod that provides:

✅ 16+ Registry Classes – Register blocks, items, entities, enchantments, fluids, sounds, particles, and more with minimal code
✅ 25+ Utility Helpers – Production-ready helpers for inventory, entities, NBT, particles, world manipulation, and more
✅ 8 Built-in Commands – Block, item, entity, world, debug, config, registry, and help commands out of the box
✅ Advanced Client Systems – Entity rendering, model management, screen handlers, and 1.21+ render state support
✅ Fluent Data Generation – Auto-generate recipes, loot tables, and models with intuitive builders
✅ Event System – Custom events for block mining, player joining, entity spawning
✅ JSON Configuration – Built-in config management with automatic file generation
✅ Modern Java 21 – Records, pattern matching, sealed classes, and null safety annotations

No gameplay content is added to Minecraft. Mosberg API is purely a developer library for mod creators.


📥 Installation for Players

  1. Download Fabric Loader and install it
  2. Download Fabric API (required dependency)
  3. Download this mod from CurseForge
  4. Place all JARs in your .minecraft/mods/ folder
  5. Launch Minecraft with the Fabric profile

👨‍💻 For Mod Developers

Quick Setup

Add to gradle.properties:

# Dependencies
mosberg_api_1412900_version=7375365

Add to build.gradle:

repositories {
    maven {
        name = "CurseMaven"
        url = "https://cursemaven.com/"
        content {
            includeGroup "curse.maven"
        }
    }
}

dependencies {
    // Mosberg API
    modImplementation "curse.maven:mosberg-api-1412900:${project.mosberg_api_1412900_version}"
    // Optional: bundle with your mod
    include implementation("curse.maven:mosberg-api-1412900:${project.mosberg_api_1412900_version}")
}

Update fabric.mod.json:

{
  "depends": {
    "mosberg-api": "*"
  }
}

Create your mod initializer:

import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class YourMod implements ModInitializer {
    public static final String MOD_ID = "yourmod";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    @Override
    public void onInitialize() {
        LOGGER.info("YourMod initialized with Mosberg API!");

        // Register your content
        ModBlocks.initialize();
        ModItems.initialize();
        ModEntities.initialize();

        // Register events
        ModEvents.register();

        // Load config
        ModConfig.load();
    }
}

🎯 Key Features

Registry System

Simplify registration with one-liners:

// Block registration (auto-creates item)
public static final Block RUBY_BLOCK = MosbergBlocks.register(
    "ruby_block",
    new Block(AbstractBlock.Settings.create().strength(2.0f))
);

// Entity registration
public static final EntityType<CustomMob> CUSTOM_MOB = MosbergEntities.register(
    "custom_mob",
    EntityType.Builder.create(CustomMob::new, SpawnGroup.CREATURE)
        .dimensions(0.8f, 1.8f)
);

// Enchantment registration
public static final Enchantment CUSTOM_ENCH = MosbergEnchantments.register(
    "custom_ench",
    new Enchantment(...)
);

16 Registry Classes:

  • MosbergBlocks, MosbergItems, MosbergEntities, MosbergItemGroups
  • MosbergSounds, MosbergParticles, MosbergFluids, MosbergEnchantments
  • MosbergStatusEffects, MosbergPotions, MosbergBlockEntities
  • MosbergDataComponents, MosbergDamageTypes, MosbergGameEvents
  • MosbergScreenHandlerTypes, MosbergVillagers, MosbergWorldGen
  • MosbergTags, MosbergRegistries (master registry for 60+ types)

Utility Helpers

25+ helpers for common operations:

// Inventory operations
ItemStack leftovers = InventoryHelper.addItemToInventory(inv, stack);
int transferred = InventoryHelper.transferItems(source, dest, count);
boolean hasSpace = InventoryHelper.hasSpace(inv, stack);

// Entity manipulation
EntityHelper.teleportEntity(entity, world, pos);
EntityHelper.applyKnockback(entity, strength, direction);
EntityHelper.healEntity(entity, amount);

// World operations
WorldHelper.setRaining(world, duration);
WorldHelper.createExplosion(world, null, pos, power, true);
List<Entity> nearby = WorldHelper.getEntitiesInBox(world, box);

// NBT operations
NBTHelper.setString(nbt, "name", value);
NBTHelper.setInt(nbt, "level", 5);
String name = NBTHelper.getString(nbt, "name", "Default");

// Particle effects
ParticleHelper.spawnParticles(world, ParticleTypes.FLAME, pos, count, spread);

All 25 Helpers: AttributeHelper, BlockHelper, CommandHelper, DataComponentHelper, DamageTypeHelper, EnchantmentUtil, EntityHelper, FluidHelper, GameEventHelper, InventoryHelper, ItemGroupHelper, ItemHelper, MosbergEnchantmentHelper, MosbergHelper, NBTHelper, NetworkHelper, ParticleHelper, PotionHelper, RecipeHelper, SerializationHelper, SoundHelper, StatusEffectHelper, TagHelper, VillagerHelper, WorldHelper

Data Generation

Fluent builders for recipes and loot tables:

// Shaped crafting
createShaped(RecipeCategory.TOOLS, ModItems.SWORD)
    .pattern(" I ")
    .pattern(" I ")
    .pattern(" S ")
    .input('I', Items.IRON_INGOT)
    .input('S', Items.STICK)
    .criterion(hasItem(Items.IRON_INGOT), conditionsFromItem(Items.IRON_INGOT))
    .offerTo(exporter);

// Smelting
offerSmelting(exporter, List.of(ModBlocks.ORE),
    RecipeCategory.MISC, ModItems.INGOT, 1.0f, 200, "ingot");

// Stonecutting
createStonecutting(RecipeCategory.BUILDING_BLOCKS, ModBlocks.STAIRS, ModBlocks.BLOCK)
    .criterion(hasItem(ModBlocks.BLOCK), conditionsFromItem(ModBlocks.BLOCK))
    .offerTo(exporter);

// Loot tables
addBlockLootTable(ModBlocks.ORE,
    LootTable.builder()
        .pool(LootPool.builder()
            .rolls(ConstantLootNumberProvider.create(1))
            .with(ItemEntry.builder(ModItems.INGOT))));

Built-in Commands

8 production-ready commands:

  • /block – Inspect and modify block properties
  • /item – Manage items and NBT data
  • /entity – Spawn and manipulate entities
  • /world – Control weather, time, explosions
  • /debug – Performance profiling and analysis
  • /config – Manage configuration at runtime
  • /registry – Introspect registered content
  • /help – Command documentation

Client-Side Rendering

Easy entity and screen registration:

// Register entity renderer
MosbergRenderers.registerEntityRenderer(
    ModEntities.CUSTOM_MOB,
    CustomMobRenderer::new,
    ModModelLayers.CUSTOM_MOB,
    CustomMobModel::getTexturedModelData
);

// Register screen
ScreenRegistry.register(ModScreenHandlers.CUSTOM,
    CustomScreen::new);

Client utilities:

  • MosbergRenderers – Entity/block renderers
  • MosbergModels – Model layer management
  • MosbergModelLayers – Pre-defined layers
  • MosbergRenderStates – 1.21+ render state API
  • MosbergScreenHandlerTypes – Screen handler registration
  • RenderHelper, ModelHelper, TextureHelper, ScreenHelper, ScreenHandlerHelper

Events

Custom event callbacks:

MosbergEvents.BLOCK_MINED.register((player, world, pos, state) -> {
    if (state.isOf(Blocks.DIAMOND_ORE)) {
        player.sendMessage(Text.literal("You mined diamonds!"), false);
    }
});

MosbergEvents.PLAYER_JOINED.register((player) -> {
    LOGGER.info("Player joined: {}", player.getName().getString());
});

MosbergEvents.ENTITY_SPAWNED.register((entity, world) -> {
    LOGGER.debug("Entity spawned: {}", entity.getType());
});

Configuration

JSON-based config with defaults:

public class ModConfig {
    public static final ConfigManager CONFIG = new ConfigManager("yourmod");

    public static int SPAWN_RATE = 10;
    public static boolean ENABLE_FEATURE = true;
    public static double DAMAGE_MULTIPLIER = 1.5;

    public static void load() {
        SPAWN_RATE = CONFIG.getInt("spawn_rate", 10);
        ENABLE_FEATURE = CONFIG.getBoolean("enable_feature", true);
        DAMAGE_MULTIPLIER = CONFIG.getDouble("damage_multiplier", 1.5);
        CONFIG.save();
    }
}

📁 What’s Included

Registries (16 classes)

Register blocks, items, entities, enchantments, fluids, sounds, particles, status effects, potions, block entities, data components, damage types, game events, screen handlers, villagers, world generation, and tags.

Utilities (25 classes)

Inventory, entities, NBT, particles, world state, blocks, attributes, commands, enchantments, fluids, game events, item groups, networking, potions, recipes, serialization, sounds, status effects, tags, and villagers.

Commands (8 templates)

Block, item, entity, world, debug, config, registry, and help commands ready to use or extend.

Client Systems (11 classes)

Entity renderers, model management, screen handlers, render states (1.21+), and rendering utilities.

Data Generation

Fluent builders for recipes, loot tables, and models with full Minecraft 1.21.10 support.

Events

BlockMined, PlayerJoined, EntitySpawned, and more with simple registration.

Configuration

JSON-based config system with auto-generation and reload support.


🔧 System Requirements

  • Minecraft: 1.21.10
  • Fabric Loader: 0.18.3+
  • Fabric API: 0.138.4+1.21.10
  • Java: 21+

📚 Documentation

Full documentation available at:


🚀 Getting Started

  1. Add dependency to your build.gradle
  2. Update fabric.mod.json with Mosberg API dependency
  3. Create mod class implementing ModInitializer
  4. Register content using Mosberg API registry classes
  5. Use helpers to simplify common operations
  6. Build with ./gradlew build

Full examples and tutorials available on the GitHub Wiki.


💡 Why Choose Mosberg API?

✅ Zero Boilerplate – Register anything with one line
✅ Type-Safe – Modern Java 21 with full null safety
✅ Production-Ready – 25+ tested utility helpers
✅ Fluent APIs – Intuitive builder patterns
✅ Comprehensive – Covers 60+ Minecraft registry types
✅ Well-Documented – Every method has clear Javadoc
✅ Active Development – Regular updates and improvements
✅ Community-Driven – Open to feedback and contributions


📜 License

MIT License – Use in commercial projects, modify, distribute, or use for educational purposes. Attribution appreciated but not required.


🙏 Credits

  • Author: Mosberg
  • Framework: Fabric API & Fabric Loader
  • Mappings: Yarn community mappings
  • Game: Minecraft by Mojang Studios

📞 Support

Need help?

Want to contribute?

  • Fork on GitHub
  • Submit pull requests for improvements
  • Report issues and suggest features

🎯 Perfect For

✨ Mod developers who want to spend more time on gameplay and less on boilerplate
✨ Library mods that need a solid foundation
✨ Teams building content packs with custom mechanics
✨ Anyone using Fabric API 1.21.10+


Mosberg API – Write less boilerplate. Build better mods. Faster.

Made with ❤️ by Mosberg for the Minecraft modding community

常见问题

Mosberg API 支持哪些 Minecraft 版本?

Mosberg API 支持 Minecraft Java 版 1.21.10,可用的加载器:Fabric。下载时注意选择和你游戏版本一致的文件。

Mosberg API 怎么安装?

先用 PCL2 或 HMCL 启动器安装对应版本的 Fabric,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。

评论

登录后评论和评分

Mosberg 的其他作品

查看全部 →