Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions develop/items/first-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / markdownlint

Trailing spaces

develop/items/first-item.md:21:74 MD009/no-trailing-spaces Trailing spaces [Expected: 0; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md009.md

Check failure on line 21 in develop/items/first-item.md

View workflow job for this annotation

GitHub Actions / markdownlint

Custom rule

develop/items/first-item.md:21:74 search-replace Custom rule [no-multiple-spaces: Don't use multiple spaces] [Context: "column: 74 text:' '"] https://github.com/OnkarRuikar/markdownlint-rule-search-replace
(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}
Expand All @@ -36,18 +39,33 @@
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.
:::

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 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

Check failure on line 49 in develop/items/first-item.md

View workflow job for this annotation

GitHub Actions / markdownlint

Heading levels should only increment by one level at a time

develop/items/first-item.md:49 MD001/heading-increment Heading levels should only increment by one level at a time [Expected: h3; Actual: h4] https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md001.md

Check failure on line 49 in develop/items/first-item.md

View workflow job for this annotation

GitHub Actions / markdownlint

Custom rule

develop/items/first-item.md:49:1 search-replace Custom rule [missing-heading-anchor: Add anchors to headings. Use lowercase characters, numbers and dashes] [Context: "column: 1 text:'#### ModItems.java'"] https://github.com/OnkarRuikar/markdownlint-rule-search-replace

@[code transcludeWith=:::3](@/reference/latest/src/main/java/com/example/docs/item/ModItems.java)

#### Your class that implements `ModInitializer`

Check failure on line 53 in develop/items/first-item.md

View workflow job for this annotation

GitHub Actions / markdownlint

Custom rule

develop/items/first-item.md:53:1 search-replace Custom rule [missing-heading-anchor: Add anchors to headings. Use lowercase characters, numbers and dashes] [Context: "column: 1 text:'#### Your class that implements `ModInitializer`'"] https://github.com/OnkarRuikar/markdownlint-rule-search-replace

Check failure on line 53 in develop/items/first-item.md

View workflow job for this annotation

GitHub Actions / markdownlint

Titlecase rule

develop/items/first-item.md:53:1 titlecase-rule Titlecase rule [Title Case: 'Expected #### Your Class that Implements , found #### Your class that implements ']

@[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.

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
```

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

View workflow job for this annotation

GitHub Actions / markdownlint

Custom rule

develop/items/first-item.md:67:105 search-replace Custom rule [no-multiple-spaces: Don't use multiple spaces] [Context: "column: 105 text:' '"] https://github.com/OnkarRuikar/markdownlint-rule-search-replace

## Adding the Item to an Item Group {#adding-the-item-to-an-item-group}

::: info
Expand Down Expand Up @@ -98,6 +116,8 @@

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}
Expand Down
Loading