⛏️ My First Minecraft Mod · Episode 3 of 6 · See All Episodes
🍪 Episode 3 · Custom Food · Potion Effects

Magic Cookie!
Custom Food & Effects

Add a Magic Cookie to Minecraft eat it and you'll zoom around with Speed II and leap with Jump Boost! Learn how food, hunger and status effects work in Fabric.

🧑 Ages 10+ ⏱️ ~1 Hour ⛏️ Fabric 1.21 ✓ Free
Your Progress0 / 9 steps
1
📖
How Food Works in Fabric
Understand FoodComponent before writing any code
Active
🎯
Goal for this step

Understand the three food properties we'll set: nutrition, saturation and status effects.

📖
Food in Minecraft has three key values:
Nutrition how many hunger bars it restores (each bar = 2 points, so 4 = 2 full bars)
Saturation hidden hunger that delays hunger loss (higher = stays full longer)
Status Effects potion effects applied when eaten, with a probability (1.0f = always)
💡
A golden apple gives 4 nutrition, 9.6f saturation and Regeneration + Absorption. Our Magic Cookie will give speed and jump boost much more fun for exploring!
I understand nutrition, saturation and status effects
2
💻
Add the Magic Cookie to ModItems.java
Register a food item with FoodComponent.Builder in Java
Locked
🎯
Goal for this step

Add the Magic Cookie item to ModItems.java with food properties and status effects.

  • 1Open ModItems.java. Add these imports at the top (use Alt+Enter on any red text to auto-import):
New imports for ModItems.java
import net.minecraft.component.type.FoodComponent; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffects;
  • 2Below your CRYSTAL_GEM field, add the Magic Cookie:
ModItems.java add after CRYSTAL_GEM
public static final Item MAGIC_COOKIE = registerItem( "magic_cookie", new Item(new Item.Settings() .food(new FoodComponent.Builder() .nutrition(4) // restores 2 hunger bars .saturationModifier(0.6f) // saturation multiplier .statusEffect( new StatusEffectInstance( StatusEffects.SPEED, 400, // duration in ticks (400 = 20 seconds) 1 // amplifier (0=level I, 1=level II) ), 1.0f // probability (1.0 = always applies) ) .statusEffect( new StatusEffectInstance( StatusEffects.JUMP_BOOST, 400, 1 ), 1.0f ) .build()) ) );
  • 3In registerModItems(), add: entries.add(MAGIC_COOKIE); inside the lambda.
  • 4Save the file.
📖
Ticks: Minecraft runs at 20 ticks per second. So 400 ticks = 20 seconds. 600 = 30 seconds. 2400 = 2 minutes. Change the duration to whatever feels fun!
MAGIC_COOKIE field added to ModItems.java
entries.add(MAGIC_COOKIE) added to registerModItems()
No red errors in the file
🎓 Teacher Note Step 2The chained builder pattern (.nutrition().saturationModifier().statusEffect()...) is new syntax for most students. Remind them every line except the last ends in a dot, and the final line is .build() with no dot after it. Missing a dot or adding an extra one is the most common compile error here.
🚨 Stuck? Food item won't compile
  • Cannot find symbol: FoodComponent Alt+Enter → Import → net.minecraft.component.type.FoodComponent.
  • Cannot find symbol: StatusEffects Alt+Enter → Import → net.minecraft.entity.effect.StatusEffects.
  • Cannot find symbol: StatusEffectInstance Import → net.minecraft.entity.effect.StatusEffectInstance.
  • Builder chain has a red squiggle on one line check every line except the last ends with a dot (not a semicolon) and the final line is .build(). Missing or extra dots break the whole chain.
  • Cookie appears but doesn't give effects the second parameter in statusEffect(instance, probability) is 1.0f = 100% chance. If you put 0.0f it never applies!
3
🎨
Draw the Magic Cookie Texture
Create a 16×16 cookie sprite for your food item
Locked
🎯
Goal for this step

Create a glowing cookie texture and add the model + language files.

  • 1Use Pixel Studio to draw a 16×16 cookie. Brown base, darker chips, maybe some sparkly cyan/purple pixels to show it's magical!
  • 2Save as magic_cookie.png in assets/crystalmod/textures/item/.
  • 3Create magic_cookie.json in assets/crystalmod/models/item/:
models/item/magic_cookie.json
{ "parent": "item/generated", "textures": { "layer0": "crystalmod:item/magic_cookie" } }
  • 4Add to en_us.json: "item.crystalmod.magic_cookie": "Magic Cookie"
magic_cookie.png texture created
magic_cookie.json model created
en_us.json updated
4
🔨
Add a Crafting Recipe
Let players craft the Magic Cookie using wheat, sugar and a Crystal Gem
Locked
🎯
Goal for this step

Create a shapeless crafting recipe any arrangement of ingredients will work.

  • 1In data/crystalmod/recipe/, create magic_cookie.json:
data/crystalmod/recipe/magic_cookie.json
{ "type": "minecraft:crafting_shapeless", "ingredients": [ { "item": "minecraft:wheat" }, { "item": "minecraft:sugar" }, { "item": "crystalmod:crystal_gem" } ], "result": { "id": "crystalmod:magic_cookie", "count": 4 } }
📖
Shapeless means the items can go in any slot the player doesn't have to arrange them in a specific pattern. Great for simple recipes like this!
data/crystalmod/recipe/magic_cookie.json created
5
🏃
Run Minecraft & Eat Your Cookie!
Test Speed II and Jump Boost in a survival world
Locked
🎯
Goal for this step

Launch Minecraft, eat your Magic Cookie and zoom around with speed and jump boost!

  • 1Launch Minecraft Client from IntelliJ.
  • 2Create a world in Survival mode so hunger is active (food only works in survival!).
  • 3Use /give @p crystalmod:magic_cookie to get some cookies.
  • 4Eat the cookie and watch the speed and jump boost effects appear in the top-right corner!
  • 5Try jumping you should be able to jump much higher than normal.
  • 6Check the crafting recipe works: gather wheat, sugar and a Crystal Gem and open a crafting table.
💡
You can also test by searching "Magic Cookie" in the creative inventory it appears under the Ingredients tab. In creative mode, eat it with right-click while not full.
Magic Cookie appears in creative inventory
Eating it gives Speed II and Jump Boost
Crafting recipe works correctly
6
⚗️
Add More Status Effects
Stack more potion effects onto your cookie — night vision, strength, or even bad luck!
Locked
🎯
Goal for this step

Experiment with adding more status effects to the Magic Cookie's FoodComponent.

🎨
You can chain as many .statusEffect(...) calls as you want! Here are some fun ones to try:
More effects to try in ModItems.java
// Night Vision see in the dark for 60 seconds .statusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 1200, 0), 1.0f) // Strength II deal extra melee damage .statusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, 400, 1), 1.0f) // Fire Resistance don't take fire damage .statusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 600, 0), 1.0f) // Poison 50% chance to get poisoned! A cursed cookie? .statusEffect(new StatusEffectInstance(StatusEffects.POISON, 100, 0), 0.5f) // Levitation float into the air for 5 seconds! .statusEffect(new StatusEffectInstance(StatusEffects.LEVITATION, 100, 0), 1.0f)
  • 1Add one or two more effects to your Magic Cookie. Pick ones that sound fun to you!
  • 2Relaunch Minecraft and test them.
At least one extra status effect added
Tested in-game and working
7
🍖
Make It Always Edible
Add .alwaysEdible() so you can eat the cookie even when full
Locked
🎯
Goal for this step

Add the alwaysEdible() modifier so the Magic Cookie can be eaten any time even with a full hunger bar.

📖
By default, food can only be eaten when you're hungry. Adding .alwaysEdible() lets you eat it any time just like golden apples! This is useful for utility food that gives effects rather than just restoring hunger.
  • 1In ModItems.java, find your Magic Cookie's FoodComponent. After .nutrition(4), add .alwaysEdible():
ModItems.java — FoodComponent update
new FoodComponent.Builder() .nutrition(4) .saturationModifier(0.6f) .alwaysEdible() // ← add this line .statusEffect(...) .build()
  • 2Relaunch Minecraft. Try eating the cookie with a completely full hunger bar it should work now!
.alwaysEdible() added to the FoodComponent
Cookie can be eaten with a full hunger bar
8
🍕
Challenge: Create a Second Food Item
Use the same pattern to add any food you can imagine
Locked
🎯
Goal for this step

Add a second food item using the same FoodComponent pattern. Make it your own invention!

💡
Ideas for a second food:
Crystal Stew high nutrition, Regeneration and Resistance
Cursed Cake low nutrition, Weakness + Blindness (funny joke item!)
Speed Candy Speed III for 10 seconds, tiny nutrition
Gem Pie very high nutrition like a golden carrot
  • 1Add a new item field in ModItems.java with its own FoodComponent.
  • 2Create the texture, model JSON and language entry.
  • 3Add a crafting recipe.
  • 4Test it in-game!
A second food item registered and working in game
9
🌟
What You Learned Looking Ahead
Review this episode and preview Episode 4: Custom Tools
Locked
🎯
Goal for this step

Review what you built and understand what's coming next.

What you learned this episode

  • How to use FoodComponent.Builder to define hunger, saturation and effects
  • How StatusEffectInstance sets the effect, duration and level
  • How to use a shapeless crafting recipe
  • How .alwaysEdible() overrides hunger requirements
📖
Up next Episode 4: Custom Tools! We'll create a Crystal Pickaxe and Crystal Sword using a custom tool material. You'll set mining speed, attack damage, durability and enchantability all in Java.
I understand how FoodComponent works
I have at least 2 food items working in my mod
🎉🍪⚡🎊✨
You Made a Magic Cookie!

You added a real food item with potion effects to Minecraft and learned about FoodComponent, StatusEffects and shapeless recipes. Episode 4 builds custom tools!

⚒️ Episode 4: Super Pickaxe → ⭐ View My Progress & Certificates

This workshop was free and took many hours to build. If it helped you learn something new, consider supporting the project.

☕ Support on Ko-fi