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 simple item documentation #37

Merged
merged 14 commits into from
Aug 30, 2022
2 changes: 2 additions & 0 deletions wiki/versions/1.19/item/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
group rootProject.group
version rootProject.version
1 change: 1 addition & 0 deletions wiki/versions/1.19/item/markdown/item.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Items
38 changes: 38 additions & 0 deletions wiki/versions/1.19/item/simple_item/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apply plugin: "org.quiltmc.loom"

archivesBaseName = project.archives_base_name
version = project.version
group = project.maven_group

repositories {
}

// All dependency versions are declared in the gradle.properties file
dependencies {
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings(loom.layered {
addLayer(quiltMappings.mappings("org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings_version}:v2"))
})
modImplementation "org.quiltmc:quilt-loader:${project.quilt_loader_version}"

// QSL is not yet a complete API. When released for this version, it's highly recommended to use Quilted Fabric API instead.
modImplementation "org.quiltmc:qsl:${qsl_version}+${minecraft_version}"
}

processResources {
inputs.property "version", version

filesMatching('quilt.mod.json') {
expand "version": version
}
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
14 changes: 14 additions & 0 deletions wiki/versions/1.19/item/simple_item/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Gradle Properties
org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

# Dependencies: Visit https://lambdaurora.dev/tools/import_quilt.html and the Quilt Community Discord (https://discord.com/invite/M7GpuyTBvy) for dependency version info.
minecraft_version = 1.19
quilt_mappings_version = 1
quilt_loader_version = 0.17.0
qsl_version = 2.0.0-beta.2

# Mod Properties
version = 1.0.0+1.19
maven_group = org.quiltmc.wiki
archives_base_name = simple_item
51 changes: 51 additions & 0 deletions wiki/versions/1.19/item/simple_item/markdown/simple_item.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Your First Item
Items are crucial to Minecraft, and almost any mod will make use of them. This tutorial will go through the basic steps for creating an item.

## Registering the Item
The first thing we need to do is register the item so that the game knows to add it in. First, we need to declare an instance of `net.minecraft.item.Item` with the parameters for our item.

In theory, we could do this directly in the registration line but having a separate variable allows us to reference it elsewhere for other purposes.

```file:src/main/java/org/quiltmc/wiki/simple_item/SimpleItemExample.java@Declaration
```

Here, the `public static final` ensures that we can access the item elsewhere but not change it, making sure that we don't accidentally alter it somewhere else.

Our new instance of `Item` takes in an instance of `QuiltItemSettings` as an argument. This is where we declare all of the settings for our item. There are a variety of these, but for now we only need `.group()`, which sets which creative tab the item will be found in. You can create your own, but here we use the Miscellaneous tab.

Now that we've declared the item, we need to tell the game registry to put it into the game. We do so by putting this into the mod's `onInitialize` method:

```file:src/main/java/org/quiltmc/wiki/simple_item/SimpleItemExample.java@Registration
```

`Registry.register()` takes three parameters:
- The `Registry` we want to add to. For items this is always `Registry.ITEM`.
- The `Identifier` used for the item. This must be unique. The first part is the namespace (which should be the mod id, but here it is `simple_item`) and the item name itself. Only lowercase letters, numbers, underscores, dashes, periods, and slashes are allowed.
- The `Item` to register. Here, we pass in the item we declared earlier.

Having done all of this, if we run the game we can see that our item appears in the Miscellaneous tab! But it doesn't have a texture, and its name isn't translated properly. How do we fix this?

## Textures
First we need to declare the model for the item. This tells the game how to render the item.

```file:src/main/resources/assets/simple_item/models/item/example_item.json
```

For most items, all you need to do here is replace `simple_item` with your mod ID and `example_item` with the item name you set earlier. This file should go to your assets folder under `/models/item`.

The texture file, as shown in the model, should match the identifier path, so in our case `textures/item/example_item.png`

# Language Translation

Finally, we need to add a translation. Put this in `lang/en_us.json` in your assets folder, replacing the same values as before:

```file:src/main/resources/assets/simple_item/lang/en_us.json
```

And that's it! Your item should be working fully.


## What's next?
This tutorial only covers the most basic of items. Check the other item tutorials for more advanced items.

If you want your item to have a recipe, generate one from [this website](https://crafting.thedestruc7i0n.ca/) (you may want to use a placeholder for the `output` item and then replace it with e.g. `simple_item:example_item`) and then put it in a JSON file under `src/main/resources/data/simple_item/recipes/` (replacing `simple_item` with your mod ID). Further details on item recipes can be found <abbr title="This documentation is not done yet, but it will be soon!">here</abbr>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.quiltmc.wiki.simple_item;

import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings;

public class SimpleItemExample implements ModInitializer {

// @start Declaration
public static final Item EXAMPLE_ITEM = new Item(new QuiltItemSettings().group(ItemGroup.MISC));
// @end Declaration

@Override
public void onInitialize(ModContainer mod) {
// @start Registration
Registry.register(Registry.ITEM, new Identifier("simple_item", "example_item"), EXAMPLE_ITEM);
// @end Registration
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"item.simple_item.example_item": "Example Item"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "simple_item:item/example_item"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"schema_version": 1,
"quilt_loader": {
"group": "org.quiltmc.wiki",
"id": "simple_item",
"version": "${version}",
"metadata": {
"name": "Simple Item Example",
"description": "Creation and registration of a simple item.",
"contributors": {
"bs3k": "Owner"
},
"contact": {
},
"icon": "assets/tutorial/icon.png"
},
"intermediate_mappings": "net.fabricmc:intermediary",
"entrypoints": {
"init": "org.quiltmc.wiki.tutorial.SimpleItemExample"
},
"depends": [
{
"id": "quilt_loader",
"versions": ">=0.16.0-"
},
{
"id": "minecraft",
"versions": ">=1.19"
}
]
}
}