Help with adding potion effects on right click

Started by gleaml on Fri, 01/29/2016 - 17:57
Last seen on 23:46, 30. Jan 2016
Joined Jan 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Help with adding potion effects on right click
Fri, 01/29/2016 - 17:57

Basically I am trying to make a weapon where when you right click a potion effect come on you. I am using 1.7.10 version of MCreator and I dont know how to add that to the weapon. Please give me some assistance. 

Last seen on 23:46, 30. Jan 2016
Joined Jan 2016
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Can Anyone look at this code
Sat, 01/30/2016 - 01:28

Can Anyone look at this code and tell me what to fix?


static{
Item.ToolMaterial enumt = EnumHelper.addToolMaterial("NEOGRUNTSWORD", 4, 2000, 7F, 16, 5);block = (Item)(new ItemSword(enumt){public Set<String> getToolClasses(ItemStack stack){
HashMap<String, Integer> ret = new HashMap<String, Integer>();
ret.put("sword", 4);
return ret.keySet();
}
}).setUnlocalizedName("NeoGruntSword").setTextureName("neo grunt sword");
Item.itemRegistry.addObject(437, "NeoGruntSword", block);

}
{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entity){
float var4 = 1.0F;
int i = (int)(entity.prevPosX + (entity.posX - entity.prevPosX) * (double)var4);
int j = (int)(entity.prevPosY + (entity.posY - entity.prevPosY) * (double)var4 + 1.62D - (double)entity.yOffset);
int k = (int)(entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)var4);
 
 
if(true){
if(entity instanceof EntityLivingBase) ((EntityLivingBase)entity).addPotionEffect(new PotionEffect(1, 60, 1));
}
}

Last seen on 00:45, 14. Aug 2018
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
You must make new class that
Sat, 01/30/2016 - 13:40

You must make new class that extends ItemSword.
So remove the part that you added and remove all in static.
To static write this: 

Item.ToolMaterial enumt = EnumHelper.addToolMaterial("NEOGRUNTSWORD", 4, 2000, 7F, 16, 5);
block = new ItemNeogruntSword(enumt);

Item.itemRegistry.addObject(437, "NeoGruntSword", block);


Under the second from end "}" write this:

public static class ItemNeogruntSword extends ItemSword{
public ItemNeogruntSword(Item.ToolMaterial material) {
        super(material);
        this.setUnlocalizedName("NeoGruntSword").setTextureName("neo grunt sword");
        this.setCreativeTab(CreativeTabs.tabCombat);
        
}

There you can write your code.

}

I am not sure that it will works because i tested it only on 1.8.

Last seen on 10:33, 28. May 2017
Joined May 2017
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
With the newest Version
Sun, 05/28/2017 - 10:27

With the newest Version (currently 1.7.2) you can create an item instead of an sword and make it work like a sword.you have more functionality there.dont make an sword in tools,make it in items instead!

i actually wrote this for people that are seeking this problem right now