From acbd3d67488784f6cf58ab978acceb434629826d Mon Sep 17 00:00:00 2001 From: jwred5 Date: Sun, 4 Aug 2024 16:32:06 -0700 Subject: [PATCH 1/3] Update first-item.md Add more wording to fill in gaps in tutorial --- develop/items/first-item.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/develop/items/first-item.md b/develop/items/first-item.md index d424845ce..1afaed1eb 100644 --- a/develop/items/first-item.md +++ b/develop/items/first-item.md @@ -18,10 +18,12 @@ To simplify the registering of items, you can create a method that accepts an in This method will create an item with the provided identifier and register it with the game's item registry. -You can put this method in a class called `ModItems` (or whatever you want to name the class). +You can put this method in a new class next to your ModInitializer class. +(We will assume this class is called `ModItems` for the rest of this page, but you can call it whatever you want). Mojang does this with their items as well! Check out the `Items` class for inspiration. +Make sure to replace "FabricDocsReference.MOD_ID" with a reference to the MOD_ID in your "ModInitializer" class @[code transcludeWith=:::1](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) ## Registering an Item {#registering-an-item} @@ -36,18 +38,25 @@ If you want to change your item's stack size, you can use the `maxCount` method This will not work if you've marked the item as damageable, as the stack size is always 1 for damageable items to prevent duplication exploits. ::: +For example, you can create a new "Suspicious Substance" by adding this static field to your ModItems class. @[code transcludeWith=:::2](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) -However, when you go in-game, you can see that our item doesn't exist! This is because you don't statically initialize the class. +However, when you go in-game, you can see that our item doesn't exist! This is because there are no references to the ModItem class which would initialize it when Minecraft starts. -To do this, you can add a public static initialize method to your class and call it from your `ModInitializer` class. Currently, this method doesn't need anything inside it. +To force initialization of the static field, you can add a public static initialize method to your class and call it from your `ModInitializer` class. Currently, this method doesn't need anything inside it. +ModItems.java @[code transcludeWith=:::3](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) +Your class that implements "ModInitializer" @[code transcludeWith=:::1](@/reference/latest/src/main/java/com/example/docs/item/FabricDocsReferenceItems.java) Calling a method on a class statically initializes it if it hasn't been previously loaded - this means that all `static` fields are evaluated. This is what this dummy `initialize` method is for. +With that added, running your mod will now allow you to /give yourself your {mod-id}:suspicious_substance. + +But it still won't show up when you press 'E', for that, you will need to register the item to an Item Group, described next. + ## Adding the Item to an Item Group {#adding-the-item-to-an-item-group} ::: info From 739a0de3f40b852fe845b698ee5e3e9570f85a12 Mon Sep 17 00:00:00 2001 From: Jonathan Woo Date: Sun, 11 Aug 2024 15:18:23 -0700 Subject: [PATCH 2/3] Fix spacing for code references --- develop/items/first-item.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/develop/items/first-item.md b/develop/items/first-item.md index 1afaed1eb..158166b68 100644 --- a/develop/items/first-item.md +++ b/develop/items/first-item.md @@ -24,6 +24,7 @@ You can put this method in a new class next to your ModInitializer class. Mojang does this with their items as well! Check out the `Items` class for inspiration. Make sure to replace "FabricDocsReference.MOD_ID" with a reference to the MOD_ID in your "ModInitializer" class + @[code transcludeWith=:::1](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) ## Registering an Item {#registering-an-item} @@ -39,6 +40,7 @@ This will not work if you've marked the item as damageable, as the stack size is ::: For example, you can create a new "Suspicious Substance" by adding this static field to your ModItems class. + @[code transcludeWith=:::2](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) However, when you go in-game, you can see that our item doesn't exist! This is because there are no references to the ModItem class which would initialize it when Minecraft starts. @@ -46,9 +48,11 @@ However, when you go in-game, you can see that our item doesn't exist! This is b To force initialization of the static field, you can add a public static initialize method to your class and call it from your `ModInitializer` class. Currently, this method doesn't need anything inside it. ModItems.java + @[code transcludeWith=:::3](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) Your class that implements "ModInitializer" + @[code transcludeWith=:::1](@/reference/latest/src/main/java/com/example/docs/item/FabricDocsReferenceItems.java) Calling a method on a class statically initializes it if it hasn't been previously loaded - this means that all `static` fields are evaluated. This is what this dummy `initialize` method is for. From 899c6bcf09dc9f0204e9d1a16cc69e24066c896f Mon Sep 17 00:00:00 2001 From: Jonathan Woo Date: Sun, 15 Sep 2024 15:53:31 -0700 Subject: [PATCH 3/3] Improved formatting off code references and command examples --- develop/items/first-item.md | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/develop/items/first-item.md b/develop/items/first-item.md index 158166b68..0a3632716 100644 --- a/develop/items/first-item.md +++ b/develop/items/first-item.md @@ -39,27 +39,32 @@ If you want to change your item's stack size, you can use the `maxCount` method This will not work if you've marked the item as damageable, as the stack size is always 1 for damageable items to prevent duplication exploits. ::: -For example, you can create a new "Suspicious Substance" by adding this static field to your ModItems class. - +Following this example, we will create a new "Suspicious Substance" item, by adding this static field to your `ModItems` class. @[code transcludeWith=:::2](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) However, when you go in-game, you can see that our item doesn't exist! This is because there are no references to the ModItem class which would initialize it when Minecraft starts. To force initialization of the static field, you can add a public static initialize method to your class and call it from your `ModInitializer` class. Currently, this method doesn't need anything inside it. -ModItems.java +#### ModItems.java @[code transcludeWith=:::3](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) -Your class that implements "ModInitializer" +#### Your class that implements `ModInitializer` @[code transcludeWith=:::1](@/reference/latest/src/main/java/com/example/docs/item/FabricDocsReferenceItems.java) Calling a method on a class statically initializes it if it hasn't been previously loaded - this means that all `static` fields are evaluated. This is what this dummy `initialize` method is for. -With that added, running your mod will now allow you to /give yourself your {mod-id}:suspicious_substance. +Once you've added this method, you can run your mod and use the following command to give you the suspicious substance item. + +```command +/give @s :suspicious_substance +``` -But it still won't show up when you press 'E', for that, you will need to register the item to an Item Group, described next. +Make sure to replace `` with your mod's ID! + +Though you will be able to give yourself the item, it still won't show up within the creative inventory. For that, you will need to register the item to an Item Group, described next. ## Adding the Item to an Item Group {#adding-the-item-to-an-item-group} @@ -111,6 +116,8 @@ You're going to create a simple `item/generated` model, which takes in an input Create the model JSON in the `assets//models/item` folder, with the same name as the item; `suspicious_substance.json` +Note: Ensure you put your mod-id in place of "fabric-docs-reference" + @[code](@/reference/latest/src/main/resources/assets/fabric-docs-reference/models/item/suspicious_substance.json) ### Breaking Down the Model JSON {#breaking-down-the-model-json}