Jump to content

How do I make an item that when used gives another item?


martiblq

Recommended Posts

Basicly like mushroom stew. When it's used (eaten) to give the bowl back. I saw online to use "return new ItemStack(Items.BOWL);" but it says "Unreachable code". Here is the hole thing:

 

package com.martiblq.stew_mod.objects.items;

import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.World;

public class BabyYodaStew extends Item
{

    public BabyYodaStew(Properties properties) 
    {
        super(properties);
    }
    @Override
    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) 
    {
        return super.onItemUseFinish(stack, worldIn, entityLiving);
        return new ItemStack(Items.BOWL);
    }
}

Link to comment
Share on other sites

so it returns the bowl but now it doesn't feed you.

here is item init

Spoiler

event.getRegistry().register(new BabyYodaStew(new Item.Properties().group(stew_modItemGroup.instance).food(new Food.Builder().hunger(20).saturation(20f).build())).setRegistryName("baby_yoda_stew"));

and here is the class

Spoiler

package com.martiblq.stew_mod.objects.items;

import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.World;

public class BabyYodaStew extends Item
{

    public BabyYodaStew(Properties properties) 
    {
        super(properties);
    }
    @Override
    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) 
    {
        return super.onItemUseFinish(new ItemStack(Items.BOWL), worldIn, entityLiving);
    }
}
 

 

Link to comment
Share on other sites

You're misusing onItemUseFinish, the ItemStack is whatever item they're currently eating. By putting a stack of bowls in there, you're telling the game that the player is eating (or more accurately "using") a bowl.

Look at how SoupItem does it.

Edited by imacatlolol

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.