Skip to content

Commit

Permalink
Improved formatting off code references and command examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jwred5 committed Sep 15, 2024
1 parent 7bd7ff1 commit 899c6bc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions develop/items/first-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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"
#### 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.

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

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}

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 899c6bc

Please sign in to comment.