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

Refactor "Creating Your First Item" page by removing SUSPICIOUS_FOOD_COMPONENT and add new Food Item #165

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions develop/items/food.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Unless you're making a mod with overpowered items, you should consider:

## Adding the Food Component {#adding-the-food-component}

To add a food component to an item, we can pass it to the `FabricItemSettings` instance:
To add a food component to an item, we can pass it to the `Item.Settings` instance:

```java
new FabricItemSettings().food(new FoodComponent.Builder().build())
new Item.Settings().food(new FoodComponent.Builder().build())
```

Right now, this just makes the item edible and nothing more.
Expand All @@ -36,12 +36,14 @@ The `FoodComponent.Builder` class has many methods that allow you to modify what
| `snack` | Declares your item as a snack. |
| `statusEffect` | Adds a status effect when you eat your item. Usually a status effect instance and chance is passed to this method, where chance is a decimal percentage (`1f = 100%`) |

When you've modified the builder to your liking, you can call the `build()` method to get the `FoodComponent`

Using the example created in the [Creating Your First Item](./first-item) page, I'll be using the following options for the builder:
When you've modified the builder to your liking, you can call the `build()` method to get the `FoodComponent`.

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

Similar to the example in the [Creating Your First Item](./first-item) page, I'll be using the above component:

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

This makes the item:

- Always edible, it can be eaten regardless of hunger level.
Expand Down
Binary file modified public/assets/develop/items/food_0.webm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,24 @@ public class ModItems {
.build();
// :::9
// :::5
public static final FoodComponent SUSPICIOUS_FOOD_COMPONENT = new FoodComponent.Builder()
public static final FoodComponent POISON_FOOD_COMPONENT = new FoodComponent.Builder()
.alwaysEdible()
.snack()
// The duration is in ticks, 20 ticks = 1 second
.statusEffect(new StatusEffectInstance(StatusEffects.POISON, 6 * 20, 1), 1.0f)
.build();
// :::5

// :::poisonous_apple
public static final Item POISONOUS_APPLE = register(
new Item(new Item.Settings().food(POISON_FOOD_COMPONENT)),
"poisonous_apple"
);
// :::poisonous_apple

// :::2
public static final Item SUSPICIOUS_SUBSTANCE = register(
// Ignore the food component for now, we'll cover it later in the food section.
new Item(new Item.Settings().food(SUSPICIOUS_FOOD_COMPONENT)),
new Item(new Item.Settings()),
"suspicious_substance"
);
// :::2
Expand Down Expand Up @@ -115,6 +121,7 @@ public static void initialize() {
// Register items to the custom item group.
ItemGroupEvents.modifyEntriesEvent(CUSTOM_ITEM_GROUP_KEY).register(itemGroup -> {
itemGroup.add(ModItems.SUSPICIOUS_SUBSTANCE);
itemGroup.add(ModItems.POISONOUS_APPLE);
itemGroup.add(ModItems.GUIDITE_SWORD);
itemGroup.add(ModItems.GUIDITE_HELMET);
itemGroup.add(ModItems.GUIDITE_BOOTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"item.minecraft.potion.effect.tater": "Tater Potion",
"death.attack.tater": "%1$s died from Tater damage!",
"item.fabric-docs-reference.suspicious_substance": "Suspicous Substance",
"item.fabric-docs-reference.poisonous_apple": "Poisonous Apple",
"item.fabric-docs-reference.guidite_sword": "Guidite Sword",
"item.fabric-docs-reference.guidite_helmet": "Guidite Helmet",
"item.fabric-docs-reference.guidite_chestplate": "Guidite Chestplate",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "fabric-docs-reference:item/poisonous_apple"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading