Jump to content

Issues with Item names & coding Food


Javada

Recommended Posts

Currently coding for 1.7.10 Minecraft.

 

Two issues I am facing right now.  First, when I test out my mod, the name of all the items shows as "item.itemname.name" when the item is held in the player's hand.  All the graphics show up fine, but the names do not.  Also, for some reason, the language files is showing up as it's own asset bundle in Eclipse, which I think is what is causing the issue but it will not let me add it to the main mod's asset package.

 

Secondly, I am having trouble getting the player to consume the foods.  I have examined the source code for food in the vanilla game and in a few other food mods, but it still isn't working.  A fellow modder said all I needed to do was create a new class, for example "ItemModFood", and then put a single line of code to get it to work, "public class ItemModFood extends ItemFood", but Eclipse threw a ton of errors at me when I tried to save that class.

 

This is the code as I have it now, sans the first two quotations marks;

 

"

public class ItemModFood extends ItemFood

{

private int itemUseDuration;

private int healAmount;

private int getMaxItemUseDuration;

private int setMaxStackSize;

private float saturationModifier;

private boolean isWolfsFavoriteMeat;

private boolean alwaysEdible;

 

 

public ItemModFood(int hunger, float sat, boolean wolf)

{

super(hunger, sat, wolf);

this.itemUseDuration=24;

this.healAmount=hunger;

this.saturationModifier=sat;

this.isWolfsFavoriteMeat=wolf;

this.setMaxStackSize=16;

this.setCreativeTab(CreativeTabs.tabFood);

 

}

 

 

public ItemStack onEaten(ItemStack food, World world, EntityPlayer player)

{

 

player.getFoodStats().func_151686_a(this, food);

world.playSoundAtEntity(player, "random burp", 0.5F, world.rand.nextFloat()*0.1F + 0.9F);

this.onFoodEaten(food, world, player);

return food;

 

}

 

 

public EnumAction getItemUseAction(ItemStack food)

{

return EnumAction.eat;

}

 

 

public ItemModFood setAlwaysEdible()

{

this.alwaysEdible=false;

return this;

}

 

 

public ItemStack onItemRightClick(ItemStack food, World world, EntityPlayer player)

{

if(player.canEat(this.alwaysEdible))

{

player.setItemInUse(food, this.getMaxItemUseDuration(food));

}

 

return food;

}

 

}"

 

Any suggestions would be appreciated.

Link to comment
Share on other sites

Look for any Tutorial to set the language file up properly.

And in the ItemFood just delete all the methods! What you are doing is extending the class of the vanilla food class, so u get all the methods and then u override them with the same code?

Just override if u want to change something

public class YourFood extends ItemFood{

public YourFood (int par1, float par2, boolean par3) {
	super(par1, par2, par3);
}

@Override
    public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
        return EnumAction.drink;
    }

For example the getItemUseAction is eating the food by default, so override the method ONLY if u want to actually take any changes like setting it to drinking.

Link to comment
Share on other sites

So, similarly, if I wanted at add the chance for an item to drop when the player hits a new block type, I would create a class, extend the block class and simply add the new drop event.  Because it is a new class, this added event will only affect it and not the blocks in the vanilla game but the new block will have all the regular features of the vanilla block from which it is extended.  Correct?

Link to comment
Share on other sites

Exact, only your new block would drop the item, but you should be careful cuz by overriding a method you loose all the "regular feastures" of that method, to get around that put super.theMethodYouAreOverriding in the method you are overriding, which basically does everything what the old method did (you dont have to do it in most cases)

Link to comment
Share on other sites

I placed the @Override item into my code and I got an error message.  Do I need to place it under a different heading, like super or private?

 

Second, best way to code an item's chance of being dropped is an if/then or simply EventHandle?

Link to comment
Share on other sites

With the item drop you mean to cklick your new block type? you can use

    
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
return false;
}

@Override is actually not doing anything, but checking if you are overriding properly, so if you for example use this:

@Override
public boolean onBlockActivated(World world, int x, int y, int z, int player, int side, float hitX, float hitY, float hitZ)
{
return false;
}

you get an error (you can change the names of the variables ofc. but not the type)

and for the future, always post your error message  ;)

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.