### Add specific Fabric API modules as dependencies Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/README.md Specify individual Fabric API modules to include only required functionality. Example shows a set of common modules and adds each via the fabricApi.module helper. Works with both Groovy and Kotlin DSL. ```Groovy DSL // Make a collection of all api modules we wish to use Set apiModules = [ "fabric-api-base", "fabric-command-api-v1", "fabric-lifecycle-events-v1", "fabric-networking-api-v1" ] // Add each module as a dependency apiModules.forEach { include(modImplementation(fabricApi.module(it, FABRIC_API_VERSION))) } ``` ```Kotlin DSL // Make a set of all api modules we wish to use setOf( "fabric-api-base", "fabric-command-api-v1", "fabric-lifecycle-events-v1", "fabric-networking-api-v1" ).forEach { // Add each module as a dependency modImplementation(fabricApi.module(it, FABRIC_API_VERSION)) } ``` -------------------------------- ### Apply License Headers with Gradle Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Automates the application of license headers to project files using a Gradle task. This ensures consistent licensing across the codebase. ```gradle gradlew spotlessApply ``` -------------------------------- ### Run Style Checks and Game Tests with Gradle Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Executes comprehensive style checks and game tests for the project using Gradle. This task verifies code quality and functionality. ```gradle gradlew check ``` -------------------------------- ### Add full Fabric API dependency with Gradle Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/README.md Include the complete Fabric API library in the mod's dependencies. Supports both Groovy and Kotlin DSL build scripts. Replace FABRIC_API_VERSION with the desired version string. ```Groovy DSL modImplementation "net.fabricmc.fabric-api:fabric-api:FABRIC_API_VERSION" ``` ```Kotlin DSL modImplementation("net.fabricmc.fabric-api:fabric-api:FABRIC_API_VERSION") ``` -------------------------------- ### Run Faster Code Style Checks with Gradle Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Performs a quicker check of code style for both main and testmod sources using Gradle. This is useful for rapid feedback during development. ```gradle gradlew checkstyleMain checkstyleTestmod ``` -------------------------------- ### Mark API classes as experimental in Java Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Shows how to properly mark API classes as experimental using @ApiStatus.Experimental annotation and javadoc comments. This is required for experimental modules to indicate their unstable status to users. ```java /** * (normal javadoc here) * *

Experimental feature, may be removed or changed without further notice. */ ``` -------------------------------- ### Custom API Lookup Helpers Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/fabric-api-lookup-api-v1/README.md The `custom` subpackage offers helper classes for implementing `ApiLookup`s for custom objects, providing query parameters similar to `BlockApiLookup` but tailored for custom scenarios. ```APIDOC ## Custom API Lookup Helpers ### Description This package contains utility classes designed to simplify the creation of `ApiLookup` implementations for custom game objects. These helpers provide functionality analogous to `BlockApiLookup` but with customizable query parameters. ### Method Not applicable, this refers to a package of helper classes. ### Endpoint Not applicable. ### Parameters None ### Request Example Refer to `ApiLookupMap` and `ApiProviderMap` for specific usage examples. ### Response No direct API responses, as these are utility classes for implementation. ``` -------------------------------- ### Entity API Lookup Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/fabric-api-lookup-api-v1/README.md The standard interface for querying API instances from entities. It offers a `find` function for retrieving API instances and multiple `register*` functions for registering APIs based on entity types. ```APIDOC ## Entity API Lookup ### Description This class provides the mechanism to query for API instances associated with entities. It includes a `find` method for retrieval and registration methods to associate APIs with entity types. ### Method GET (or similar for retrieval) ### Endpoint Not applicable, this is a class-based API lookup. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Example of obtaining an instance EntityApiLookup lookup = EntityApiLookup.get(new Identifier("my_mod", "my_api"), MyApi.class); // Example of finding an API on an entity Optional apiInstance = lookup.find(entity, context); ``` ### Response #### Success Response (200) - **apiInstance** (Optional) - An optional containing the found API instance, if available. #### Response Example ```java // Response is handled via the Optional return type of the find method. ``` ``` -------------------------------- ### Block API Lookup Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/fabric-api-lookup-api-v1/README.md The primary way of querying API instances for blocks in the world. It exposes a `find` function to retrieve an API instance and multiple `register*` functions to register APIs for blocks and block entities. ```APIDOC ## Block API Lookup ### Description This class provides the primary mechanism for querying API instances associated with blocks in the game world. It allows for finding API instances and registering them for specific blocks or block entities. ### Method GET (or similar for retrieval) ### Endpoint Not applicable, this is a class-based API lookup. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Example of obtaining an instance BlockApiLookup lookup = BlockApiLookup.get(new Identifier("my_mod", "my_api"), MyApi.class); // Example of finding an API on a block state Optional apiInstance = lookup.find(world, blockPos, context); ``` ### Response #### Success Response (200) - **apiInstance** (Optional) - An optional containing the found API instance, if available. #### Response Example ```java // Response is handled via the Optional return type of the find method. ``` ``` -------------------------------- ### Item API Lookup Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/fabric-api-lookup-api-v1/README.md The designated method for querying API instances directly from item stacks. It provides a `find` function for retrieval and several `register*` functions for registering APIs associated with specific items. ```APIDOC ## Item API Lookup ### Description This class serves as the interface for retrieving API instances associated with item stacks. It includes a `find` method to get an API instance and registration methods to link APIs to specific items. ### Method GET (or similar for retrieval) ### Endpoint Not applicable, this is a class-based API lookup. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Example of obtaining an instance ItemApiLookup lookup = ItemApiLookup.get(new Identifier("my_mod", "my_api"), MyApi.class); // Example of finding an API on an item stack Optional apiInstance = lookup.find(itemStack, context); ``` ### Response #### Success Response (200) - **apiInstance** (Optional) - An optional containing the found API instance, if available. #### Response Example ```java // Response is handled via the Optional return type of the find method. ``` ``` -------------------------------- ### Block API Cache Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/fabric-api-lookup-api-v1/README.md A `BlockApiLookup` bound to a specific position and server world, enabling significantly faster repeated API queries for that location. ```APIDOC ## Block API Cache ### Description This class optimizes repeated API queries for a specific block position within a server world by caching the results of `BlockApiLookup`. This leads to improved performance when accessing APIs from the same block multiple times. ### Method GET (or similar for retrieval) ### Endpoint Not applicable, this is a class-based API lookup. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Obtain a BlockApiLookup instance first BlockApiLookup lookup = BlockApiLookup.get(new Identifier("my_mod", "my_api"), MyApi.class); // Create a cache for a specific position BlockApiCache cache = BlockApiCache.create(lookup, world, blockPos); // Query the API through the cache Optional apiInstance = cache.find(context); ``` ### Response #### Success Response (200) - **apiInstance** (Optional) - An optional containing the found API instance, if available. #### Response Example ```java // Response is handled via the Optional return type of the find method. ``` ``` -------------------------------- ### Java Event Declaration and Callback Interfaces Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Demonstrates the standard way to declare events using `public static final Event<>` fields and define associated functional interfaces for callbacks. Callback interfaces should be `@FunctionalInterface`s with uniquely named methods. ```java public final class FooEvents { public static final Event ALLOW = ...; public static final Event BEFORE = ...; public static final Event AFTER = ...; @FunctionalInterface public interface Allow { boolean allowFoo(/* relevant parameters */); } @FunctionalInterface public interface Before { void beforeFoo(/* relevant parameters */); } @FunctionalInterface public interface Two { void afterFoo(/* relevant parameters */); } // Holder class is not meant for instantiation. private ExampleEvents() { } } ``` -------------------------------- ### Specify Module Lifecycle in fabric.mod.json Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Defines the lifecycle stage for a Fabric API module within the `fabric.mod.json` file. Supported values include 'stable', 'experimental', and 'deprecated'. ```json { "custom": { "fabric-api:module-lifecycle": "" } } ``` -------------------------------- ### Thread-Safe Lazy Initialization Cache in Java Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md This pattern implements a lazily initialized cache for shared state accessed from multiple threads, such as Minecraft's render and server threads, using volatile fields to ensure visibility without locks. It depends on Java's memory model and assumes infrequent writes; inputs are null checks on the cache, outputting the computed value after initialization. Limitations include potential race conditions if compute() is expensive or non-atomic, recommending alternatives like locking for high-contention scenarios. ```java private volatile Stuff cachedStuff = null; private Stuff stuff() { Stuff stuff = this.cachedStuff; if (stuff == null) { this.cachedStuff = stuff = compute(); } return stuff; } ``` -------------------------------- ### Define default injected method for interface injection in Java Source: https://github.com/eclecticbelletrist/fabric/blob/1.21.10/CONTRIBUTING.md Provides a default implementation for an injected interface method to avoid compilation errors when the method is implemented via a mixin at runtime. This pattern is used in Fabric's interface injection mechanism and ensures that the method throws an informative exception if called before mixin application. ```Java default void injectedMethod() { throw new UnsupportedOperationException("Implemented via mixin"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.