i509VCB
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Fabric Loader The loader for mods under Fabric. Fabric Loader provides mod loading facilities and useful abstractions for other mods to use. ## License Fabric Loader is Licensed under the Apache License 2.0 ## Using Fabric Loader with vanilla launcher, MultiMC and other launchers TODO: Write section ## Creating mods This section details the creation of a mod. Registration of events, registry objects and other logic is version dependent any may vary by game version and physical environment. Details on version dependent logic and registration of said logic can be found on the Fabric wiki **(TODO: Link)** This section explains how to make a simple mod which prints a message to the console when initialized. For this tutorial, all the code is in Java. Much of this article is applicable to other JVM languages such as Kotlin, Scala, Groovy, etc. Specifics on using entrypoints with other JVM languages is detailed in the language provider mod for each language. **Note:** All code examples that contain `[...]` mean insert "other code here". These markers should be excluded from resulting files. ### What actually is a mod to Fabric Loader? A mod in fabric loader is loaded and detected via the precense of a `fabric.mod.json`. In a development environment, this should be placed in `/src/SOURCESET/resources`. Where `SOURCESET` refers to the current source set, typically `main`. The file must be named `fabric.mod.json` The JSON file specifies the id of a mod, the version and additional metadata. The current schema version is 1. This is specified via the `schemaVersion` field. | Field | Type | Description | | ----- | ---- | ----------- | | `schemaVersion` | Integer | Specifies the current version of the `fabric.mod.json` schema. If absent, it is assumed the specification version is 0. | In schema version 1 there are two **required** fields | Field | Type | Description | | -------- | ---- | ----------- | | `id` | String | Specifies the mod id. Must be 3-64 characters long and can only contain lowercase letters, numbers, dashes `-` and underscores `_`. | | `version` | String | Specifies the version of the mod. Encouraged to match the [Semantic Versioning 2.0.0](https://semver.org/) specification for versions. | Below is an example of the minimum required fields. ```json { "schemaVersion": 1, "id": "modid", "version": "0.1", [...] } ``` The `id` is the mod id of the mod. The mod id must be 3-64 characters long and can only contain lowercase letters, numbers, dashes `-` and underscores `_`. The specification of a `fabric.mod.json` file can be found here **(TODO: Link to spec/create one)** ### Entrypoints Fabric Loader uses an "entrypoint prototype" system for initializing mods. An entrypoint is typically an interface that specifies methods for mods to implement. These methods may be called during mod initialization or for other reasons. Entrypoints can be considered a more powerful implementation of Java's [Service Provider Interfaces](https://www.baeldung.com/java-spi). Entrypoints are declared in a mod's `fabric.mod.json`. Entrypoints are resolved via a "name" and must be a certain type. An example entrypoints block in a `fabric.mod.json`: ```json { [...] "entrypoints": { "main": [ "net.fabricmc.ExampleMod", "net.fabricmc.ExampleMod2" ], "client": [ "net.fabricmc.ExampleClientMod" ] } [...] } ``` The JSON file defines two entrypoint types, one called `main` and the other `client`. The `main` entrypoint refers to two classes. It is advised that side-specific entrypoints (`client` and `server`) be placed in seperate classes from each other and from the `main` entrypoint to prevent classloading issues. Mods may define their own entrypoints with custom names and types, however this is out of scope for this document. Further details on entrypoints such as defining entrypoints in alternative ways may be found here: **(TODO: Link)** ### Built-in entrypoints Fabric Loader defines 4 built-in entrypoints. - `main` - The first normal initialization entrypoint to run. - Uses the type `ModInitializer` and will call `onInitialize`. - `client` - Will run after main only in a physical client (`EnvType.CLIENT`). - Uses the type `ClientModInitializer` and will call `onInitializeClient`. - `server` - Will run after main only in a physical (dedicated) server (`EnvType.SERVER`). - Uses the type `DedicatedServerModInitializer` and will call `onInitializeServer`. - `preLaunch` - **Not recomended for general use** - The earliest possible entrypoint, which is called just before the game launches. Use with caution to not interfere with the game's initialization. - Uses the type `PreLaunchEntryPoint` and will call `onPreLaunch`. ### Creating a simple mod It is recomended to use the [fabric example mod](https://github.com/FabricMC/fabric-example-mod) to start with. The example mod includes a default development environment and an example of the example below. Further information on setting up the development environment may be found on the loom repository **(TODO: Link to loom and write a readme for using it)**. A mod is recoginized by the precense of a `fabric.mod.json`, and if present, the built artifact will considered a mod. However this is not very useful and does very little. In order to do things like register blocks, events and setup your mod, you need an entrypoint to invoke for initialization. Depending on the type of mod, the `client` or `server` entrypoints may be used, but for the simplicity, this example will use the `main` entrypoint but is applicable to both the `client` and `server` entrypoint. Firstly, define a class that the entrypoint will be ran in: ```java= public class ExampleMod { [...] } ``` Since the `main` entrypoint is being used, `ModInitializer` must be implemented by this class. The class must be: - public - not abstract (`abstract class` or `interface`) - contain a 0 argument constructor that is public ```java= package net.fabricmc.example; import net.fabricmc.api.ModInitializer; public class ExampleMod implements ModInitializer { [...] } ``` And then implement the `onInitialize` method in `ModInitializer`. Inside this method, ```java= package net.fabricmc.example; import net.fabricmc.api.ModInitializer; public class ExampleMod implements ModInitializer { [...] @Override public void onInitialize() { System.out.println("Hello Fabric Mod!"); // Run initialization code, register objects in registries, register events [...] } [...] } ``` Just because you created a class does not mean the entrypoint will be run when the game starts. In order to have an entrypoint load, you need to register it in your `fabric.mod.json` Since the entrypoint name is `main`, you will create a json entry where the key is `main` and the type is an array: ```json { "schemaVersion": 1 "id": "example-mod", "version": "0.1", [...] "entrypoints": { "main": [ "net.fabricmc.example.ExampleMod" ] } } ``` If done correctly, then the message should be printed to the log when the game is run. ## Fabric Loader's API Fabric loader contains an api to allow access to the current context in which a mod is loaded or running in. This is accessible via the `FabricLoader` interface (in the `api` package). To get the current instance of fabric loader, call `FabricLoader.getInstance();` The `FabricLoader` instance allows access to many things, such as getting the current game directory, the config directory, entrypoint instances, the mod list, the physical environment type and the mappings resolver. ### Mods in API Mods are represented in Fabric Loader's API as a `ModContainer`. A mod container contains mod metadata and methods to resolve files present inside of a mod's jar file. To get a list of all mods that are loaded, you may use `getAllMods`. This returns a Collection of `ModContainer`. Alternatively, checking for the precense of a mod may use `isModLoaded(String)`, where the string parameter is the mod id. To get the mod container of a specific mod, `getModContainer(String)`, where the string parameter is the mod id. This returns an Optional which may contain a `ModContainer`. The optional is empty if the mod is not loaded. ### Physical environment Fabric Loader's API spcifies the current "physical" environment Fabric Loader is running in. This is represented by an Enum called `EnvType`. The enum contains two values, `CLIENT` which refers to a physical client and `SERVER` which refers to a physical (dedicated) server. The can be checked by using `getEnvironmentType` using an instance of `FabricLoader`. ### Mapping resolver The mapping resolver is used to convert class names. Typically this is used by Fabric Loader in development to load classes using yarn mappings. This is a more complex topic and more information may be found here: **(TODO: Link)** ### Getting Entrypoints Entrypoints can be obtained via Fabric Loader. There are two methods, `getEntrypoints(T)` and `getEntrypointContainers(T)`. Usage of these methods is further documented here: **(TODO: Link)** ## Support TODO: Write section, explain support channels (Discord primarily, IRC is an option, Issues, etc.) ## Contributing See something Fabric Loader doesn't supply, a bug or something that may be useful? We welcome contributions to improve Fabric Loader. Check out [the Contributing guidelines](../CONTRIBUTING.md).

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully