[p] Hi, Im new to eclipse(But have coding knowledge, just wasnt using eclipse) And I was just wondering if it was possible to make a item heal a player. I have this code that spawns lightning on the item r-click but I also want it to either not deal damage to the player that uses the item or make the item heal the player right away. Also Im trying to give it a usage bar, I thought this could be done with this.setMaxDamage(); but is this correct?? Please help!! Heres the code I have for the item!![/p]
package com.leon.derkmod;[/p]
This code is a pain to read, upload it to Gist/GitHub or pastebin and link it here for proper formatting and syntax highlighting.
2nd:
in the Item#onItemRightClick() method either set the player's health directly or add a regeneration potion effect. You get the player as parameter from that method. Also add this as very first line to onITemRightClick():
if(world.isRemote) return;
It will make sure to only handle your code serverside, prevents i.e. chat messages from being displayed twice and also saves some resources on the client.
3rd:
Yeah, setMaxDamage() is for durability, but you have to damage the item by yourself using ItemStack#damageItem(int amount).
Oh and one last thing: Why are you still creating a mod for 1.7? It is outdated since about 2 years.
Also it'll be a pain to update to 1.8 or 1.9/1.10, believe me you don't wanna do that...
This code is a pain to read, upload it to Gist/GitHub or pastebin and link it here for proper formatting and syntax highlighting.
2nd:
in the Item#onItemRightClick() method either set the player's health directly or add a regeneration potion effect. You get the player as parameter from that method. Also add this as very first line to onITemRightClick():
if(world.isRemote) return;
It will make sure to only handle your code serverside, prevents i.e. chat messages from being displayed twice and also saves some resources on the client.
3rd:
Yeah, setMaxDamage() is for durability, but you have to damage the item by yourself using ItemStack#damageItem(int amount).
Oh and one last thing: Why are you still creating a mod for 1.7? It is outdated since about 2 years.
Also it'll be a pain to update to 1.8 or 1.9/1.10, believe me you don't wanna do that...
thanks alot, Ill be sure to use github next time. I felt like i was doing something wrong... Thanks anyways!! Also, I have no idea why its for 1.7.10.
package com.leon.derkmod;[/p]
import net.minecraft.client.Minecraft;[/p]
import net.minecraft.entity.effect.EntityLightningBolt;[/p]
import net.minecraft.entity.player.EntityPlayer;[/p]
import net.minecraft.item.Item;[/p]
import net.minecraft.item.ItemStack;[/p]
import net.minecraft.potion.Potion;[/p]
import net.minecraft.potion.PotionEffect;[/p]
import net.minecraft.util.MovingObjectPosition;[/p]
import net.minecraft.util.MovingObjectPosition.MovingObjectType;[/p]
import net.minecraft.util.Vec3;[/p]
import net.minecraft.world.World;[/p]
public class ItemDerkWand extends Item{[/p]
public ItemDerkWand(){[/p]
this.setFull3D();[/p]
this.setMaxStackSize(1);[/p]
this.setMaxDamage(30);[/p]
}[/p]
@Override[/p]
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer Entityplayer) {[/p]
Vec3 look = Entityplayer.getLookVec();[/p]
MovingObjectPosition Coord = Entityplayer.rayTrace(300, 1);[/p]
EntityLightningBolt Lightning = new EntityLightningBolt(world, 1, 1, 1);[/p]
Lightning.setPosition(Coord.blockX,Coord.blockY,Coord.blockZ);[/p]
world.spawnEntityInWorld(Lightning);[/p]
return itemStack;[/p]
}[/p]
}[/p]
well, first things first:
This code is a pain to read, upload it to Gist/GitHub or pastebin and link it here for proper formatting and syntax highlighting.
2nd:
in the Item#onItemRightClick() method either set the player's health directly or add a regeneration potion effect. You get the player as parameter from that method. Also add this as very first line to onITemRightClick():
It will make sure to only handle your code serverside, prevents i.e. chat messages from being displayed twice and also saves some resources on the client.
3rd:
Yeah, setMaxDamage() is for durability, but you have to damage the item by yourself using ItemStack#damageItem(int amount).
Oh and one last thing: Why are you still creating a mod for 1.7? It is outdated since about 2 years.
Also it'll be a pain to update to 1.8 or 1.9/1.10, believe me you don't wanna do that...
thanks alot, Ill be sure to use github next time. I felt like i was doing something wrong... Thanks anyways!! Also, I have no idea why its for 1.7.10.
Also you can use EntityPlayer#heal(int) to heal the player. Just make sure you do it server side.
I have an example of it being used in an item here.