-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add verbosity and clarification to First Item tutorial page #161
base: main
Are you sure you want to change the base?
Changes from 3 commits
acbd3d6
739a0de
ef974ab
7bd7ff1
899c6bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,13 @@ | |
|
||
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. | ||
Check failure on line 21 in develop/items/first-item.md GitHub Actions / markdownlintTrailing spaces
Check failure on line 21 in develop/items/first-item.md GitHub Actions / markdownlintCustom rule
|
||
(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 +39,28 @@ | |
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 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. | ||
|
||
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. | ||
ModItems.java | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to label these code blocks, use h4 headings. |
||
|
||
@[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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap templates in `` please. Eg; You could alternatively have:
|
||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be more specific; It wont show up within the creative inventory... Keybinds aren't fixed, especially vanilla ones like |
||
|
||
## Adding the Item to an Item Group {#adding-the-item-to-an-item-group} | ||
|
||
::: info | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.