To make it short and simple, I have an Item which lets the player jump when he rightclicks it. Now I also want it to give a saturation effect, because hunger is used when you jump. I have looked through the player.(name here) (/playerIn.(name here), I changed it to player) and not found anything that would do this. I thought about adding this via a potion effect, but that wouldn't work either, at least the way i did it.
Here's the code:
import java.util.List;
import knallerpse9.testmod.TestMod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class HealthItem extends Item
{
public int rare;
public int maxDamage;
public int maxStackAmount;
public HealthItem(String unlocalizedName, int rare, int maxDamage, int maxStackAmount)
{
super();
this.setCreativeTab(TestMod.tabTestTab);
this.setUnlocalizedName(unlocalizedName);
this.setMaxDamage(maxDamage);
this.setMaxStackSize(maxStackAmount);
//this.(Reference.MOD_ID + ":" + unlocalizedName);
this.rare = rare;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld)
{
//TODO need to change the names
if (this.rare == 0)
{
list.add(EnumChatFormatting.WHITE + "" + EnumChatFormatting.ITALIC + "Educt");
}
else if (this.rare == 1)
{
list.add(EnumChatFormatting.DARK_GREEN + "" + EnumChatFormatting.ITALIC + "Product");
}
else if (this.rare == 2)
{
list.add(EnumChatFormatting.AQUA + "" + EnumChatFormatting.ITALIC + "Radioactive");
}
else if (this.rare == 3)
{
list.add(EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.ITALIC + "Unstable");
}
else if (this.rare == 4)
{
}
else if (this.rare == 5)
{
list.add(EnumChatFormatting.DARK_BLUE + "" + EnumChatFormatting.ITALIC + "Material");
}
}
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World worldIn, EntityPlayer player)
{
player.jump();
player.addPotionEffect(23); //this gives an error
itemStack.damageItem(1, player);
player.fallDistance = 0F;
return itemStack;
}
}
Hello!
To make it short and simple, I have an Item which lets the player jump when he rightclicks it. Now I also want it to give a saturation effect, because hunger is used when you jump. I have looked through the player.(name here) (/playerIn.(name here), I changed it to player) and not found anything that would do this. I thought about adding this via a potion effect, but that wouldn't work either, at least the way i did it.
Here's the code:
Any help is greatly appreciated!
You need to pass a new instance of PotionEffect into addPotionEffect().
Please don't PM me asking for help, I will just redirect you to the appropriate forum, where there are others who are far more skilled than me.
This is not the signature you are looking for.
Banners and such things
And how exactly would I do this?
?
I'm sorry, I'm relatively new to java :/
player.addPotionEffect(new PotionEffect(id, effectDuration, effectAmplifier));
should do the trick.
ID = Effect id list: Minecraft Wiki (Saturation = 23)
Effect Duration: How long in seconds the effect would last.
Effect Amplifier: What level of effect (The higher the more hunger it would fill)
Oh, I get it now! *facepalm*
Thank you!
The duration isn't in seconds, it's in ticks.
It seems that it is in seconds when potion effects are added in the ItemFood constructor and in ticks otherwise.
Ah, I see. I noticed that I had to set my timer to ticks, now I know it's because it's in the item class. Cheers!