### Run Gradle Setup Task in IntelliJ IDEA Source: https://docs.minecraftforge.net/en/1.19.x/forgedev This describes how to execute the 'setup' Gradle task within IntelliJ IDEA for Minecraft Forge projects. This task is crucial for preparing the development environment. It can be accessed via the Gradle sidebar or by using a keyboard shortcut. ```text Forge -> Tasks -> other -> setup ``` ```text CTRL + CTRL, then type 'gradle setup' ``` -------------------------------- ### Check Java Version Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Verifies if a 64-bit JVM is installed, which is required for Forge. Running this command in a terminal will display the Java version information. ```bash java -version ``` -------------------------------- ### Setup Minecraft Forge Development Environment with Gradle (Eclipse) Source: https://docs.minecraftforge.net/en/1.19.x/forgedev These Gradle commands are used to set up and generate run configurations for Eclipse. Navigate to your cloned repository directory before executing them. This process prepares the project for use within Eclipse. ```bash ./gradlew setup ./gradlew genEclipseRuns ``` -------------------------------- ### Run Minecraft Forge Mod in Test Environment Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Launches Minecraft with your mod applied. Supports running the client or a dedicated server. ```bash gradlew runClient ``` ```bash gradlew runServer ``` -------------------------------- ### Generate Visual Studio Code Run Configurations Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted This command generates the necessary run configurations for Visual Studio Code, facilitating development within that IDE. ```bash gradlew genVSCodeRuns ``` -------------------------------- ### Run Forge Mod Configurations Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Allows direct execution of various Forge mod configurations like client, server, or data generation from the terminal. These can also be used within supported IDEs. ```bash gradlew runClient ``` ```bash gradlew runServer ``` ```bash gradlew runData ``` ```bash gradlew runGameTestServer ``` -------------------------------- ### Build Minecraft Forge Mod Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Builds your mod into a JAR file. The output JAR is located in the `build/libs` directory. ```bash gradlew build ``` -------------------------------- ### Generate Eclipse Run Configurations Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted This command generates specific run configurations for Eclipse IDE, allowing for easier debugging and execution of your Forge mod. ```bash gradlew genEclipseRuns ``` -------------------------------- ### Clone Minecraft Forge Repository using Git Source: https://docs.minecraftforge.net/en/1.19.x/forgedev This command clones your forked Minecraft Forge repository to your local machine. Replace `` with your GitHub username. Ensure Git is installed and configured on your system. ```git git clone https://github.com//MinecraftForge ``` -------------------------------- ### Set Mod Version in build.gradle Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Specifies the current version of your mod. It's recommended to follow Maven versioning conventions for consistency. ```gradle version = '1.19.4-1.0.0.0' ``` -------------------------------- ### Generate IntelliJ IDEA Run Configurations Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Executes the task to generate run configurations for IntelliJ IDEA. If a "module not specified" error occurs, you may need to set the 'ideaModule' property. ```bash gradlew genIntellijRuns ``` -------------------------------- ### Registering Client Setup Event Handler in Forge Source: https://docs.minecraftforge.net/en/1.19.x/concepts/events Example of how to register an event handler for `FMLClientSetupEvent` on the Mod Event Bus. This event is specific to the client environment. ```java import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fmlbus.api.EventBusManager; import net.minecraftforge.fmlbus.api.IEventBus; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; public class MyModInit { public MyModInit() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(this::onClientSetup); } private void onClientSetup(FMLClientSetupEvent event) { // Code to run during client setup System.out.println("Client setup is running!"); } } ``` -------------------------------- ### Run Forge Client Gradle Task Source: https://docs.minecraftforge.net/en/1.19.x/forgedev This describes how to run the 'forge_client' Gradle task to launch the Minecraft Forge client. This task is typically found under 'fg_runs' in the Gradle sidebar and can be executed by right-clicking and selecting 'Run' or 'Debug'. ```text Tasks -> fg_runs -> forge_client ``` -------------------------------- ### Create a Custom Loader Builder Example Source: https://docs.minecraftforge.net/en/1.19.x/datagen/client/modelproviders Provides an example of a custom loader builder class that extends `CustomLoaderBuilder`. It includes a static factory method `begin` and a protected constructor that initializes the superclass with a resource location. ```java public class ExampleLoaderBuilder> extends CustomLoaderBuilder { public static > ExampleLoaderBuilder begin(T parent, ExistingFileHelper existingFileHelper) { return new ExampleLoaderBuilder<>(parent, existingFileHelper); } protected ExampleLoaderBuilder(T parent, ExistingFileHelper existingFileHelper) { super(new ResourceLocation(MOD_ID, "example_loader"), parent, existingFileHelper); } } ``` -------------------------------- ### Pre-release Tagging Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/versioning Explains the use of '-betaX' suffix for pre-releasing work-in-progress features. ```text MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH-betaX ``` -------------------------------- ### AbstractContainerScreen Constructor and Label Positioning Source: https://docs.minecraftforge.net/en/1.19.x/gui/screens Example of initializing an AbstractContainerScreen subclass, setting label positions, and noting the dependency of inventoryLabelY on imageHeight. ```java public MyContainerScreen(MyMenu menu, Inventory playerInventory, Component title) { super(menu, playerInventory, title); this.titleLabelX = 10; this.inventoryLabelX = 10; /* * If the 'imageHeight' is changed, 'inventoryLabelY' must also be * changed as the value depends on the 'imageHeight' value. */ } ``` -------------------------------- ### Batching Game Tests with Setup and Teardown Source: https://docs.minecraftforge.net/en/1.19.x/misc/gametest Demonstrates how to group GameTests into batches and perform setup or teardown operations for these batches using `@BeforeBatch` and `@AfterBatch` annotations. These batch methods must match the batch string provided to the `@GameTest` annotation and accept a ServerLevel argument. ```java public class ExampleGameTests { @BeforeBatch(batch = "firstBatch") public static void beforeTest(ServerLevel level) { // Perform setup } @GameTest(batch = "firstBatch") public static void exampleTest2(GameTestHelper helper) { // Do stuff } } ``` -------------------------------- ### Update Licenses Task Source: https://docs.minecraftforge.net/en/1.19.x/forgedev This describes the 'updateLicenses' Gradle task, which can be helpful if you encounter licensing errors during the build process. This task is located under 'Forge -> Tasks -> other'. ```text Forge -> Tasks -> other -> updateLicenses ``` -------------------------------- ### Access Transformer Syntax Examples Source: https://docs.minecraftforge.net/en/1.19.x/advanced/accesstransformers These examples demonstrate the syntax for applying Access Transformers to classes, fields, and methods. They cover different access modifiers, targeting specific members, and using Java type descriptors for methods. ```cfg # Makes public the ByteArrayToKeyFunction interface in Crypt public net.minecraft.util.Crypt$ByteArrayToKeyFunction # Makes protected and removes the final modifier from 'random' in MinecraftServer protected-f net.minecraft.server.MinecraftServer f_129758_ #random # Makes public the 'makeExecutor' method in Util, # accepting a String and returns an ExecutorService public net.minecraft.Util m_137477_(Ljava/lang/String;)Ljava/util/concurrent/ExecutorService; #makeExecutor # Makes public the 'leastMostToIntArray' method in UUIDUtil, # accepting two longs and returning an int[] public net.minecraft.core.UUIDUtil m_235872_(JJ)[I #leastMostToIntArray ``` -------------------------------- ### IEEP to Capability Conversion Steps Source: https://docs.minecraftforge.net/en/1.19.x/datastorage/capabilities This snippet provides a step-by-step guide for converting existing IExtendedEntityProperties implementations to use the Forge Capability system. ```markdown Quick conversion guide: 1. Convert the IEEP key/id string into a `ResourceLocation` (which will use your MODID as a namespace). 2. In your handler class (not the class that implements your capability interface), create a field that will hold the Capability instance. 3. Change the `EntityConstructing` event to `AttachCapabilitiesEvent`, and instead of querying the IEEP, you will want to attach an `ICapabilityProvider` (probably `ICapabilitySerializable`, which allows saving/loading from a tag). 4. Create a registration method if you don’t have one (you may have one where you registered your IEEP’s event handlers) and in it, run the capability registration function. ``` -------------------------------- ### Feature Configuration Example (TOML) Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/modfiles Illustrates how to configure specific features a mod requires, such as a minimum Java version. This helps in ensuring the mod runs in a compatible environment. ```toml features = { java_version = "[17,)" } ``` -------------------------------- ### PartialNBTIngredient Example Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/recipes/ingredients Shows a PartialNBTIngredient example, which offers a more flexible NBT comparison. It allows matching against a single item or a list of items and only checks specified keys within the NBT data. ```json // For some input { "type": "forge:partial_nbt", // Either 'item' or 'items' must be specified // If both are specified, only 'item' will be read "item": "examplemod:example_item", "items": [ "examplemod:example_item", "examplemod:example_item2" // ... ], "nbt": { // Checks only for equivalency on 'key1' and 'key2' // All other keys in the stack will not be checked "key1": "data1", "key2": { // Data 2 } } } ``` -------------------------------- ### mods.toml Example Configuration Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/modfiles An example of a complete mods.toml file used to define a Minecraft Forge mod. It includes non-mod-specific properties like modLoader and loaderVersion, as well as mod-specific details like modId, displayName, and dependencies. ```toml modLoader="javafml" loaderVersion="[45,)" license="All Rights Reserved" issueTrackerURL="https://github.com/MinecraftForge/MinecraftForge/issues" showAsResourcePack=false [[mods]] modId="examplemod" version="1.0.0.0" displayName="Example Mod" updateJSONURL="https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json" displayURL="https://minecraftforge.net" logoFile="logo.png" credits="I'd like to thank my mother and father." authors="Author" description=''' Lets you craft dirt into diamonds. This is a traditional mod that has existed for eons. It is ancient. The holy Notch created it. Jeb rainbowfied it. Dinnerbone made it upside down. Etc. ''' displayTest="MATCH_VERSION" [[dependencies.examplemod]] modId="forge" mandatory=true versionRange="[45,)" ordering="NONE" side="BOTH" [[dependencies.examplemod]] modId="minecraft" mandatory=true versionRange="[1.19.4]" ordering="NONE" side="BOTH" ``` -------------------------------- ### Example Profiling Result Structure Source: https://docs.minecraftforge.net/en/1.19.x/misc/debugprofiler Demonstrates the hierarchical structure of data found in a Minecraft Debug Profiler result file, showing time spent in different game systems and custom sections. ```text [00] levels - 96.70%/96.70% [01] | Level Name - 99.76%/96.47% [02] | | tick - 99.31%/95.81% [03] | | | entities - 47.72%/45.72% [04] | | | | regular - 98.32%/44.95% [04] | | | | blockEntities - 0.90%/0.41% [05] | | | | | unspecified - 64.26%/0.26% [05] | | | | | minecraft:furnace - 33.35%/0.14% [05] | | | | | minecraft:chest - 2.39%/0.01% ``` -------------------------------- ### Update JSON Format Example Source: https://docs.minecraftforge.net/en/1.19.x/misc/updatechecker An example illustrating the expected structure for the `updateJSON` file used by Forge's update checker. This JSON should be hosted at a URL specified in `mods.toml`. ```JSON { "homepage": "", "": { "": "", "...": "// List all versions of your mod for the given Minecraft version, along with their changelogs" }, "promos": { "-latest": "", "// Declare the latest \"bleeding-edge\" version of your mod for the given Minecraft version" "-recommended": "", "// Declare the latest \"stable\" version of your mod for the given Minecraft version" "...": "// ..." } } ``` -------------------------------- ### Generate IntelliJ Run Configurations for Forge Source: https://docs.minecraftforge.net/en/1.19.x/forgedev This snippet explains how to generate run configurations within IntelliJ IDEA for the Minecraft Forge project. The 'genIntellijRuns' task is used for this purpose, ensuring that your project is correctly configured for running and debugging. ```text Forge -> Tasks -> forgegradle runs -> genIntellijRuns ``` -------------------------------- ### Example Condition Serializer Implementation and Registration Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/conditional Demonstrates the implementation of an example condition serializer, including its static instance declaration and registration using CraftingHelper during the RegisterEvent. ```java // In some serializer class public static final ExampleConditionSerializer INSTANCE = new ExampleConditionSerializer(); // In some handler class public void registerSerializers(RegisterEvent event) { event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, helper -> CraftingHelper.register(INSTANCE) ); } ``` -------------------------------- ### Set Mod Artifact Name in build.gradle Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Customizes the base name for your mod's artifact. While `archivesBaseName` is deprecated, `base.archivesName` is the recommended property for setting this value. ```gradle base.archivesName = 'mymod' ``` -------------------------------- ### IConditionBuilder Example Source: https://docs.minecraftforge.net/en/1.19.x/datagen/server/recipes Demonstrates how to use IConditionBuilder methods to construct complex conditions for conditional recipes, simplifying the manual creation of condition instances. ```java // In ConditionalRecipe$Builder#addCondition ( // If either 'examplemod:example_item' // OR 'examplemod:example_item2' exists // AND // NOT FALSE // Methods are defined by IConditionBuilder and( or( itemExists("examplemod", "example_item"), itemExists("examplemod", "example_item2") ), not( FALSE() ) ) ) ``` -------------------------------- ### Release Candidate Tagging Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/versioning Describes the use of '-rcX' suffix for release candidates before an official version change. ```text MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH-rcX ``` -------------------------------- ### Dispatch Codec Example (Java) Source: https://docs.minecraftforge.net/en/1.19.x/datastorage/codecs Demonstrates creating a dispatch codec that selects sub-codecs based on a type identifier. This is useful for registries. The example includes abstract and concrete object definitions, along with the dispatch logic using a registry's codec. ```java public abstract class ExampleObject { public abstract Codec type(); } public class StringObject extends ExampleObject { public StringObject(String s) { /* ... */ } public String s() { /* ... */ } public Codec type() { // A registered registry object // "string": // Codec.STRING.xmap(StringObject::new, StringObject::s) return STRING_OBJECT_CODEC.get(); } } public class ComplexObject extends ExampleObject { public ComplexObject(String s, int i) { /* ... */ } public String s() { /* ... */ } public int i() { /* ... */ } public Codec type() { // A registered registry object // "complex": // RecordCodecBuilder.create(instance -> // instance.group( // Codec.STRING.fieldOf("s").forGetter(ComplexObject::s), // Codec.INT.fieldOf("i").forGetter(ComplexObject::i) // ).apply(instance, ComplexObject::new) // ) return COMPLEX_OBJECT_CODEC.get(); } } // Assume there is an IForgeRegistry> DISPATCH public static final Codec = DISPATCH.getCodec() // Gets Codec> .dispatch( ExampleObject::type, // Get the codec from the specific object Function.identity() // Get the codec from the registry ); ``` -------------------------------- ### Set Mod Group ID in build.gradle Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted Defines the group ID for your mod, typically based on a domain you own or your email address. This structure should be reflected in your Java package names. ```gradle group = 'com.example' ``` -------------------------------- ### Create LootTable Builder Source: https://docs.minecraftforge.net/en/1.19.x/datagen/server/loottables This example shows how to start building a loot table using `LootTable#lootTable`. It demonstrates adding pools to the table via `#withPool` and applying functions via `#apply` to modify the generated items. The builder can also specify entries, conditions, and modifiers before being built. ```java LootTable#lootTable.withPool(...).apply(...) ``` -------------------------------- ### Work In Progress Versioning Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/versioning Describes versioning for mods in the initial development stage. MAJORMOD and MAJORAPI should be 0, with only MINOR and PATCH being updated. ```text Initial Development: MCVERSION-0.0.MINOR.PATCH First Official Release: MCVERSION-1.0.0.0 ``` -------------------------------- ### Final Release Tagging Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/versioning Details how to mark the final build for a specific Minecraft version using the '-final' suffix. ```text MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH-final ``` -------------------------------- ### Example Language File Structure (JSON) Source: https://docs.minecraftforge.net/en/1.19.x/concepts/internationalization Demonstrates the basic JSON structure for a Minecraft language file, mapping translation keys to their localized string values. ```json { "item.examplemod.example_item": "Example Item Name", "block.examplemod.example_block": "Example Block Name", "commands.examplemod.examplecommand.error": "Example Command Errored!" } ``` -------------------------------- ### Recipe Result ItemStack (JSON) Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/recipes This JSON example shows how to define the result of a recipe as a full ItemStack. It specifies the item, count, and optional NBT data for the resulting item. ```json { "item": "examplemod:example_item", "count": 4, "nbt": { } } ``` -------------------------------- ### Java Package Naming Convention Example Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/structuring Demonstrates how distinct Java packages with the same class name prevent loading conflicts. This is crucial for modding to avoid game crashes. ```text a.jar - com.example.ExampleClass b.jar - com.example.ExampleClass // This class will not normally be loaded ``` -------------------------------- ### Defining a List Config Value with ForgeConfigSpec.Builder Source: https://docs.minecraftforge.net/en/1.19.x/misc/config Shows how to define a configuration value that is a list of entries. This example uses `#defineList` to create a list that cannot be empty. ```java // For some ForgeConfigSpec$Builder builder builder.comment("A list of items") .defineList("items", Collections.singletonList("default_item"), item -> item instanceof String); ``` -------------------------------- ### Getting a Recipe with RecipeManager (Java) Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/recipes This Java code demonstrates how to retrieve a specific recipe using Forge's `RecipeManager`. It utilizes `getRecipeFor` with a `RecipeType`, a `RecipeWrapper` wrapping an `IItemHandler`, and the current level. ```java recipeManger.getRecipeFor(RecipeType.CRAFTING, new RecipeWrapper(handler), level); ``` -------------------------------- ### DifferenceIngredient Example Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/recipes/ingredients Demonstrates the DifferenceIngredient, which performs set subtraction (SUB). The input stack must match the 'base' ingredient but must not match the 'subtracted' ingredient. ```json // For some input { "type": "forge:difference", "base": { // Ingredient the stack is in }, "subtracted": { // Ingredient the stack is NOT in } } ``` -------------------------------- ### Custom Tag Provider Constructor - Java Source: https://docs.minecraftforge.net/en/1.19.x/datagen/server/tags Provides an example constructor for a custom `TagsProvider` subclass, specifically for `RecipeTypeTagsProvider`. It shows how to pass necessary parameters like `PackOutput`, `HolderLookup.Provider`, and `ExistingFileHelper`. ```java public RecipeTypeTagsProvider(PackOutput output, CompletableFuture registries, ExistingFileHelper fileHelper) { super(output, Registries.RECIPE_TYPE, registries, MOD_ID, fileHelper); } ``` -------------------------------- ### CompoundIngredient Example Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/recipes/ingredients Demonstrates the structure of a CompoundIngredient, which acts as an OR condition for a list of ingredients. At least one ingredient in the list must match for the input to be considered valid. ```json // For some input [ // At least one of these ingredients must match to succeed { // Ingredient }, { // Custom ingredient "type": "examplemod:example_ingredient" } ] ``` -------------------------------- ### Module Package Conflict Example Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/structuring Illustrates how conflicting package names across different modules can cause a mod loader to crash on startup due to exported modules. ```text module A - package X - class I - class J module B - package X // This package will cause the mod loader to crash, as there already is a module with package X being exported - class R - class S - class T ``` -------------------------------- ### Creating a KeyMapping with GUI Context and Mouse Input Source: https://docs.minecraftforge.net/en/1.19.x/misc/keymappings This Java example illustrates creating a KeyMapping that is only active when a GUI screen is open. It uses mouse input, specifically the left mouse button, and assigns it to a custom category. ```java new KeyMapping( "key.examplemod.example2", KeyConflictContext.GUI, // Mapping can only be used when a screen is open InputConstants.Type.MOUSE, // Default mapping is on the mouse GLFW.GLFW_MOUSE_BUTTON_LEFT, // Default mouse input is the left mouse button "key.categories.examplemod.examplecategory" // Mapping will be in the new example category ) ``` -------------------------------- ### Item Translation Key Example (Minecraft Forge) Source: https://docs.minecraftforge.net/en/1.19.x/concepts/internationalization Shows how an item's translation key in a language file corresponds to its registry name, typically generated by overriding `#getDescriptionId`. ```java // In your Item class, override getDescriptionId @Override public String getDescriptionId() { return "item.examplemod.example_item"; } ``` ```json { "item.examplemod.example_item": "Example Item Name" } ``` -------------------------------- ### Forge Mod Versioning Format Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/versioning Explains the custom versioning format used by Forge mods, which is MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH. This format differentiates between Minecraft compatibility and mod-specific changes. ```text MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH ``` -------------------------------- ### Multi-Minecraft Versioning Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/versioning Explains how to version mods that support multiple Minecraft versions. If a mod is upgraded for a new Minecraft version, the old version should also receive the same mod version update if it's still receiving bug fixes. ```text Example: Upgrading to 3.0.0.0 for a new Minecraft version. Old Version: 1.7.10-3.0.0.0 New Version: 1.8-3.0.0.0 ``` -------------------------------- ### sounds.json Structure Example Source: https://docs.minecraftforge.net/en/1.19.x/gameeffects/sounds Defines sound events, their subtitles, and the associated sound files. Supports random selection from multiple files and streaming for larger audio files like music. ```json { "open_chest": { "subtitle": "mymod.subtitle.open_chest", "sounds": [ "mymod:open_chest_sound_file" ] }, "epic_music": { "sounds": [ { "name": "mymod:music/epic_music", "stream": true } ] } } ``` -------------------------------- ### Forge Mod Class Naming Conventions Source: https://docs.minecraftforge.net/en/1.19.x/gettingstarted/structuring Examples of common class naming conventions in Minecraft Forge modding, where the class type is often suffixed to the class name for clarity. ```java PowerRingItem // For an Item called PowerRing NotDirtBlock // For a Block called NotDirt OvenMenu // For a menu related to an Oven ``` -------------------------------- ### Create SimpleChannel Instance (Java) Source: https://docs.minecraftforge.net/en/1.19.x/networking/simpleimpl Demonstrates the creation of a SimpleChannel instance, which is the core component of the SimpleImpl packet system. It includes setting up the channel name, protocol version supplier, and compatibility checkers. ```java private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation("mymodid", "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); ``` -------------------------------- ### Initialize Screen and Add Widgets (Java) Source: https://docs.minecraftforge.net/en/1.19.x/gui/screens Demonstrates the initialization process of a Minecraft Forge screen, including calling the superclass's init method and adding renderable widgets. The init method is called when a screen is first created or when the game window is resized. ```java import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.components.EditBox; import com.mojang.blaze3d.vertex.PoseStack; // In some Screen subclass public class MyCustomScreen extends Screen { public MyCustomScreen() { super(null); // Pass a title component, null is a placeholder } @Override protected void init() { super.init(); // Add widgets and precomputed values this.addRenderableWidget(new EditBox(this.font, 10, 10, 100, 20, null)); // Example EditBox } // Other methods like render, tick, onClose, removed would be here } ``` -------------------------------- ### Generate Patches for Code Changes Source: https://docs.minecraftforge.net/en/1.19.x/forgedev This explains how to generate patches for modifications made to the Minecraft code base within the Forge project. The 'genPatches' Gradle task is used to create these changesets, which are necessary for submitting pull requests. ```text Run the 'genPatches' Gradle task ``` -------------------------------- ### Attaching Capabilities Source: https://docs.minecraftforge.net/en/1.19.x/datastorage/capabilities Demonstrates how to attach capabilities to different game objects using AttachCapabilitiesEvent. ```APIDOC ## Attaching Capabilities Capabilities can be attached to `Entity`, `BlockEntity`, `ItemStack`, `Level`, and `LevelChunk` using the `AttachCapabilitiesEvent`. ### Event Types: - `AttachCapabilitiesEvent` - `AttachCapabilitiesEvent` - `AttachCapabilitiesEvent` - `AttachCapabilitiesEvent` - `AttachCapabilitiesEvent` ### Usage: Use the `#addCapability` method to attach capability providers. Implement `ICapabilityProvider` and optionally `ICapabilitySerializable` for persistent data. ```java // Example for attaching to an Entity @SubscribeEvent public void onAttachCapabilitiesEntity(AttachCapabilitiesEvent event) { if (event.getObject() instanceof Player) { // Attach capability provider for Player } } ``` ``` -------------------------------- ### Composite Model Visibility Example (JSON) Source: https://docs.minecraftforge.net/en/1.19.x/rendering/modelextensions/visibility An example demonstrating the 'visibility' property in a composite model JSON. It shows how to include or exclude specific parts from being baked. This example defines a composite model with two parts ('part_one', 'part_two') and sets 'part_two' to be not visible. ```json { "loader": "forge:composite", "children": { "part_one": { "parent": "mymod:mypartmodel_one" }, "part_two": { "parent": "mymod:mypartmodel_two" } }, "visibility": { "part_two": false } } ``` -------------------------------- ### IntersectionIngredient Example Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/recipes/ingredients Provides an example of an IntersectionIngredient, which functions as an AND condition. The input stack must satisfy all provided ingredients within the 'children' array to be considered valid. ```json // For some input { "type": "forge:intersection", // All of these ingredients must return true to succeed "children": [ { // Ingredient 1 }, { // Ingredient 2 } // ... ] } ``` -------------------------------- ### Registering a KeyMapping Source: https://docs.minecraftforge.net/en/1.19.x/misc/keymappings Demonstrates how to register a `KeyMapping` instance by listening to the `RegisterKeyMappingsEvent` on the mod event bus. ```APIDOC ## POST /register/keyMappings ### Description Registers a `KeyMapping` instance with the game. ### Method POST ### Endpoint `/register/keyMappings` ### Parameters #### Request Body - **keyMapping** (KeyMapping) - Required - The `KeyMapping` object to register. ### Request Example ```json { "keyMapping": { "translationKey": "key.examplemod.example1", "defaultInputType": "KEYSYM", "defaultInputCode": 80, // GLFW_KEY_P "categoryTranslationKey": "key.categories.misc" } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful registration. #### Response Example ```json { "status": "KeyMapping registered successfully" } ``` ``` -------------------------------- ### Creating a KeyMapping with Default Input Source: https://docs.minecraftforge.net/en/1.19.x/misc/keymappings Shows how to create a `KeyMapping` with a default keyboard input. ```APIDOC ## POST /create/keyMapping/defaultInput ### Description Creates a `KeyMapping` with a default keyboard input. ### Method POST ### Endpoint `/create/keyMapping/defaultInput` ### Parameters #### Request Body - **translationKey** (string) - Required - The translation key for the mapping's name. - **inputType** (string) - Required - The type of input (e.g., `KEYSYM`, `SCANCODE`, `MOUSE`). - **inputCode** (integer) - Required - The code for the input (e.g., `GLFW_KEY_P`, `GLFW_MOUSE_BUTTON_LEFT`). - **categoryTranslationKey** (string) - Required - The translation key for the mapping's category. ### Request Example ```json { "translationKey": "key.examplemod.example1", "inputType": "KEYSYM", "inputCode": 80, // GLFW_KEY_P "categoryTranslationKey": "key.categories.misc" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "KeyMapping created with default input" } ``` ``` -------------------------------- ### Creating and Registering Capabilities Source: https://docs.minecraftforge.net/en/1.19.x/datastorage/capabilities Explains two methods for creating and registering custom capabilities: RegisterCapabilitiesEvent and @AutoRegisterCapability. ```APIDOC ## Creating Your Own Capability Capabilities can be registered using `RegisterCapabilitiesEvent` or the `@AutoRegisterCapability` annotation. ### Method 1: RegisterCapabilitiesEvent Register a capability by supplying its class to the `#register` method. ```java @SubscribeEvent public void registerCaps(RegisterCapabilitiesEvent event) { event.register(IExampleCapability.class); } ``` ### Method 2: @AutoRegisterCapability Annotate the capability interface with `@AutoRegisterCapability`. ```java @AutoRegisterCapability public interface IExampleCapability { // Capability methods here } ``` ``` -------------------------------- ### JSON Tag Declaration Example Source: https://docs.minecraftforge.net/en/1.19.x/resources/server/tags Example of a JSON file used to declare a tag for items or blocks. It shows how to include specific items, optional items with requirements, and the 'replace' flag to control merging behavior. ```json { "replace": false, "values": [ "minecraft:gold_ingot", "mymod:my_ingot", { "id": "othermod:ingot_other", "required": false } ] } ``` -------------------------------- ### Creating a Basic Block with Properties Source: https://docs.minecraftforge.net/en/1.19.x/blocks Demonstrates how to instantiate a basic Block class without requiring a custom class. It shows the use of `BlockBehaviour.Properties` and its customizable methods for defining block characteristics like strength, sound, light emission, and friction. These properties can be chained for concise configuration. ```java BlockBehaviour.Properties.of(Material.STONE) .strength(1.5F, 6.0F) // Hardness, Resistance .sound(SoundType.STONE) // Sound type .lightLevel(state -> 15) // Light emission .friction(0.98F); // Slipperiness ``` -------------------------------- ### Ambient Occlusion Override Example (JSON) Source: https://docs.minecraftforge.net/en/1.19.x/rendering/modelextensions/facedata This JSON example illustrates a scenario where a top-level 'ambientocclusion' flag is set to false, and an element-level 'forge_data' attempts to enable it. Due to the precedence of the top-level flag, the element-level setting has no effect. ```json { "ambientocclusion": false, "elements": [ { "forge_data": { "ambient_occlusion": true // Has no effect } } ] } ``` -------------------------------- ### AbstractContainerScreen Constructor and Fields Source: https://docs.minecraftforge.net/en/1.19.x/gui/screens Details the constructor parameters and configurable fields for AbstractContainerScreen, including background dimensions and label positioning. ```APIDOC ## AbstractContainerScreen If a screen is directly attached to a menu, then an `AbstractContainerScreen` should be subclassed instead. An `AbstractContainerScreen` acts as the renderer and input handler of a menu and contains logic for syncing and interacting with slots. As such, only two methods typically need to be overridden or implemented to have a working container screen. Within here, a number of positioning fields can be set: ### Fields - **imageWidth** (int) - The width of the texture used for the background. Defaults to 176. - **imageHeight** (int) - The height of the texture used for the background. Defaults to 166. - **titleLabelX** (int) - The relative x coordinate of where the screen title will be rendered. - **titleLabelY** (int) - The relative y coordinate of where the screen title will be rendered. - **inventoryLabelX** (int) - The relative x coordinate of where the player inventory name will be rendered. - **inventoryLabelY** (int) - The relative y coordinate of where the player inventory name will be rendered. ### Constructor Parameters - **T menu**: The container menu being opened. - **Inventory playerInventory**: The player's inventory (for display name). - **Component title**: The title of the screen. ### Request Example ```java // In some AbstractContainerScreen subclass public MyContainerScreen(MyMenu menu, Inventory playerInventory, Component title) { super(menu, playerInventory, title); this.titleLabelX = 10; this.inventoryLabelX = 10; /* * If the 'imageHeight' is changed, 'inventoryLabelY' must also be * changed as the value depends on the 'imageHeight' value. */ } ``` ``` -------------------------------- ### IEEP to Capability Mapping Source: https://docs.minecraftforge.net/en/1.19.x/datastorage/capabilities This snippet outlines the direct mappings between IExtendedEntityProperties (IEEP) concepts and their corresponding Forge Capability system equivalents. ```markdown IEEP concepts and their Capability equivalent: * Property name/id (`String`): Capability key (`ResourceLocation`) * Registration (`EntityConstructing`): Attaching (`AttachCapabilitiesEvent`), the real registration of the `Capability` happens during `FMLCommonSetupEvent`. * Tag read/write methods: Does not happen automatically. Attach an `ICapabilitySerializable` in the event and run the read/write methods from the `serializeNBT`/`deserializeNBT`. ``` -------------------------------- ### ConfiguredModel Builder - Java Source: https://docs.minecraftforge.net/en/1.19.x/datagen/client/modelproviders Illustrates how to build a ConfiguredModel, including its model file, rotation, UV lock, and weight, and how to chain multiple models. ```java ConfiguredModel$Builder builder = ConfiguredModel.builder() .modelFile(new ModelFile("path/to/model")) .rotationX(90) .rotationY(180) .uvLock(true) .weight(2); // To create multiple models: builder.nextModel() .modelFile(new ModelFile("path/to/another/model")) .rotationY(90) .uvLock(false) .weight(1); ConfiguredModelList models = builder.build(); ``` -------------------------------- ### Child Model Visibility Override Example (JSON) Source: https://docs.minecraftforge.net/en/1.19.x/rendering/modelextensions/visibility This snippet illustrates how child models can override the visibility settings of their parent composite model. The first example shows a child model making only 'part_two' visible, and the second shows a child making both 'part_one' and 'part_two' visible. ```json // mycompositechild_one.json { "parent": "mymod:mycompositemodel", "visibility": { "part_one": false, "part_two": true } } ``` ```json // mycompositechild_two.json { "parent": "mymod:mycompositemodel", "visibility": { "part_two": true } } ``` -------------------------------- ### Creating a Configuration with ForgeConfigSpec.Builder Source: https://docs.minecraftforge.net/en/1.19.x/misc/config Demonstrates the typical pattern for creating a configuration class and a `ForgeConfigSpec` using `ForgeConfigSpec.Builder.configure`. This involves a static block and a class constructor that accepts the builder. ```java static { Pair pair = new ForgeConfigSpec.Builder() .configure(ExampleConfig::new); // Store pair values in some constant field } ``` -------------------------------- ### Synchronizing Capability Data with Clients Source: https://docs.minecraftforge.net/en/1.19.x/datastorage/capabilities Outlines the necessity and scenarios for sending capability data synchronization packets to clients. ```APIDOC ## Synchronizing Data with Clients Capability data is not sent to clients by default. Mods must implement custom packet logic for synchronization in three scenarios: 1. **Initialization**: Sending initial values when an entity spawns or a block is placed. 2. **Data Changes**: Notifying clients when stored capability data is modified. 3. **Client Joining**: Informing new clients about existing capability data. Refer to the Networking page for packet implementation details. ``` -------------------------------- ### Creating a KeyMapping with Conflict Context and Mouse Input Source: https://docs.minecraftforge.net/en/1.19.x/misc/keymappings Illustrates creating a `KeyMapping` that is context-specific (GUI only) and uses a mouse button as the default input. ```APIDOC ## POST /create/keyMapping/conflictContextMouse ### Description Creates a `KeyMapping` usable only in GUI contexts with a default mouse input. ### Method POST ### Endpoint `/create/keyMapping/conflictContextMouse` ### Parameters #### Request Body - **translationKey** (string) - Required - The translation key for the mapping's name. - **conflictContext** (string) - Required - The context in which the mapping is active (e.g., `GUI`, `IN_GAME`, `UNIVERSAL`). - **inputType** (string) - Required - The type of input (e.g., `KEYSYM`, `SCANCODE`, `MOUSE`). - **inputCode** (integer) - Required - The code for the input (e.g., `GLFW_KEY_P`, `GLFW_MOUSE_BUTTON_LEFT`). - **categoryTranslationKey** (string) - Required - The translation key for the mapping's category. ### Request Example ```json { "translationKey": "key.examplemod.example2", "conflictContext": "GUI", "inputType": "MOUSE", "inputCode": 0, // GLFW_MOUSE_BUTTON_LEFT "categoryTranslationKey": "key.categories.examplemod.examplecategory" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "KeyMapping created with GUI context and mouse input" } ``` ``` -------------------------------- ### AttributeTagsProvider Constructor Source: https://docs.minecraftforge.net/en/1.19.x/datagen/server/tags Demonstrates the constructor for AttributeTagsProvider, a subtype of IntrinsicHolderTagsProvider. It shows how to provide a function to get the ResourceKey for attributes. ```java public AttributeTagsProvider(PackOutput output, CompletableFuture registries, ExistingFileHelper fileHelper) { super( output, ForgeRegistries.Keys.ATTRIBUTES, registries, attribute -> ForgeRegistries.ATTRIBUTES.getResourceKey(attribute).get(), MOD_ID, fileHelper ); } ``` -------------------------------- ### Creating a KeyMapping with Default Input (Keyboard) Source: https://docs.minecraftforge.net/en/1.19.x/misc/keymappings This Java snippet shows how to create a KeyMapping instance. It specifies a translation key for the name, the default input type (keyboard), the default key (P), and the category for the controls menu. ```java new KeyMapping( "key.examplemod.example1", // Will be localized using this translation key InputConstants.Type.KEYSYM, // Default mapping is on the keyboard GLFW.GLFW_KEY_P, // Default key is P "key.categories.misc" // Mapping will be in the misc category ) ```