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 3 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
19 changes: 16 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,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For example, you can create a new "Suspicious Substance" by adding this static field to your ModItems class.
In this example, we will create a "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
Copy link
Member

Choose a reason for hiding this comment

The 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap templates in `` please. Eg; {mod-id}: suspicious_substance.

You could alternatively have:

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!


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.
Copy link
Member

Choose a reason for hiding this comment

The 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 Open Inventory


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

::: info
Expand Down
Loading