Custom code for Items with potion effects.

3 posts / 0 new
Last post
Offline
Last seen: 1 year 9 months ago
Joined: 09/01/2014 - 19:00
Gems: 0
Custom code for Items with potion effects.

XXXX = Item name

Find this:

Spoiler: Highlight to view
static class ItemsXXXX extends Item{

public ItemsXXXX(int par1){
setMaxDamage(0);
maxStackSize = 64;
setUnlocalizedName("XXXX");
GameRegistry.registerItem(this, "XXXX");
setCreativeTab(CreativeTabs.tabCombat);
}

And simply add this above "setUnlocalizedName("XXXX");" : setPotionEffect(Potion.regeneration.id, 6, 1, 1.0F);

So it will look like this now: 

Spoiler: Highlight to view
static class ItemsXXXX extends Item{

public ItemsXXXX(int par1){
setMaxDamage(0);
maxStackSize = 64;
setPotionEffect(Potion.regeneration.id, 6, 1, 1.0F);
setUnlocalizedName("XXXX");
GameRegistry.registerItem(this, "XXXX");
setCreativeTab(CreativeTabs.tabCombat);
}

Enjoy

 

P.S : Use the same method for food if you get a compile error when using the normal options to add potion effects.



Vegetto's picture
Offline
Last seen: 3 days 1 hour ago
Joined: 01/08/2015 - 22:55
Gems: 102
does it work will tools?

does it work will tools?

Kane's picture
Offline
Last seen: 9 hours 46 min ago
Joined: 08/16/2014 - 19:15
Gems: 183
Really nice! I'm gonna try it

Really nice! I'm gonna try it

What's if I want to create a poisoned sword? That gives poison effect to the entity I hit with?
I tried something like this: 
public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving) { 

 par2EntityLiving.addPotionEffect(new PotionEffect(Potion.poison.id, 20 * 5, 100)); System.out.println("Poisoned something."); return true;

}
But nothing works

 

Can you help me?

►And an Apocalypse shall befall the earth​♦