-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved formatting off code references and command examples
- Loading branch information
Showing
1 changed file
with
13 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
Check failure on line 49 in develop/items/first-item.md GitHub Actions / markdownlintHeading levels should only increment by one level at a time
Check failure on line 49 in develop/items/first-item.md GitHub Actions / markdownlintCustom rule
|
||
|
||
@[code transcludeWith=:::3](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java) | ||
|
||
Your class that implements "ModInitializer" | ||
#### Your class that implements `ModInitializer` | ||
Check failure on line 53 in develop/items/first-item.md GitHub Actions / markdownlintCustom rule
|
||
|
||
@[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 <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. | ||
Make sure to replace `<mod-id>` 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. | ||
Check failure on line 67 in develop/items/first-item.md GitHub Actions / markdownlintCustom rule
|
||
|
||
## 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/<mod id here>/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} | ||
|