Jump to content

[Solved][1.7.10] Healing Staff


DanielDawn

Recommended Posts

My staff is not healing the Entity, the System Print says that it is healing the entity but if I hit it after healing it to full health after it having 1 hp it dies, so that means it is not being healed. I took away my variable code and such, and it was working properly. Can I get some help with this?

 

 

 

 

 

 

SeEventHandler

package danieldawn.smallenhancements;

import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.EntityInteractEvent;

public class SeEventHandler {

private int healcooldown = 0;

@SubscribeEvent(priority = EventPriority.NORMAL)
public void Cooldowns(PlayerTickEvent e) {
	if(healcooldown > 0)
	healcooldown = healcooldown - 1;


}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onLivingUpdate(EntityInteractEvent e) {
	if (e.entityLiving instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) e.entityLiving;
		EntityLivingBase entity = (EntityLivingBase) e.target;

		if(healcooldown == 0){
	if(player.getCurrentEquippedItem().getItem() == SmallEnhancements.Heal_Staff){
		healcooldown = 200;
	player.getCurrentEquippedItem().damageItem(2, player);
	 entity.heal(entity.getMaxHealth() / 4);
	 System.out.println(entity.getHealth());
	 System.out.println(entity.getMaxHealth());
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
}
}
}
}}







Heal_Staff

package danieldawn.smallenhancements.item;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class Heal_Staff extends Item {

public Heal_Staff(){
	this.setFull3D();
	this.setMaxDamage(19);
}	
public boolean hitEntity(ItemStack itemstack, EntityLivingBase target, EntityLivingBase player){
	itemstack.damageItem(1, player);
	return true;


}
}

Link to comment
Share on other sites

1st of all - you can't save shared "healcooldown" like that. If Item is one healing - you need to assign ItemStack's NBT.

If player should have CD - use IExtendedEntityProperties or Capabilites on 1.8+.

 

2nd: Health manipulation (like any other regarding data) can only happen on server side. Use if (!entity.worldObj.isRemote) to sun code on server.

 

3rd: "healcooldown = healcooldown - 1;" - how about "--healcooldown;"

 

4th: TickEvents have Phase - pick one, otherwise code is ran twice (if (event.phase == Plase.END)).

 

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

So tried the !WorldObject if statement, but nothing was happening, except for the printin print out. So I decided to just try using the nbt, but I've never used NBT before and am a little confused...

SeEventHandler

package danieldawn.smallenhancements;

import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.EntityInteractEvent;

public class SeEventHandler {


@SubscribeEvent(priority = EventPriority.NORMAL)
public void onLivingUpdate(EntityInteractEvent e) {
	//if (e.entityLiving instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer) e.entityLiving;
		EntityLivingBase entity = (EntityLivingBase) e.target;
		ItemStack itemstack = e.entityPlayer.getCurrentEquippedItem();

		//if(healcooldown == 0){
	if(player.getCurrentEquippedItem().getItem() == SmallEnhancements.Heal_Staff){
		itemstack.stackTagCompound = new NBTTagCompound();
	if (itemstack.stackTagCompound.getInteger("word") == 0)
		System.out.println(itemstack.stackTagCompound.getInteger("word"));
	player.getCurrentEquippedItem().damageItem(2, player);
	itemstack.stackTagCompound.setInteger("word", 60);
	 entity.heal(entity.getMaxHealth() / 4);

	 System.out.println(entity.getHealth());
	 System.out.println(entity.getMaxHealth());
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	 entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);

	 }
}
}











}
}

The staff is not properly setting the int... It shows up as zero every time.

Edit: Because it keeps creating a new tag...

So how can I make it so that, if it were to be created by a command like /give it would still get that itemstack.stackTagCompound = new NBTTagCompound();

Link to comment
Share on other sites

You should really properly indent your code - it's very hard to read right now and probably not a small part of why you're having trouble. Really, it makes a difference:

if (itemstack.stackTagCompound.getInteger("word") == 0)
itemstack.stackTagCompound = new NBTTagCompound();
itemstack.stackTagCompound.setInteger("word", 60);

Look at that - the only thing you do if the 'word' value is 0 is completely wipe any data that may exist in the stack's current tag compound...

 

And then, whether the value was 0 or not, you continue on your merry way to heal the entity.

 

1. ALWAYS use brackets { } with if statements, even if they are one line. Yeah, some cool kids don't do it, but it can save you some facepalms.

 

2. NEVER overwrite an existing NBTTagCompound on an ItemStack - you have no idea what it contains, and it is probably important (e.g. enchantment info, etc.)

 

3. The only time you set a new tag compound on an ItemStack is when it doesn't have one, but if it didn't have one, your check will crash anyway:

if (itemstack.stackTagCompound. // right here, because you're trying to call a method on NULL
     getInteger("word") == 0)

Better to use:

if (!itemstack.hasTagCompound()) { // method name may vary based on version
    itemstack.setTagCompound(new NBTTagCompound());
}

 

4. I don't see anywhere where you decrement the cooldown timer on the stack... so I guess it's single-use? It's better to store the world time at which the stack can be used again anyway, as then you only check when the item is used, not every tick:

public static final int INTERVAL = 60; // cooldown interval

// when your item is used:
if (world.getTotalWorldTime() > stack.getTagCompound().getInteger("nextUse")) {
    // yay, enough time has passed to use the item again! now set the next time it will be available
   stack.getTagCompound().setInteger("nextUse", world.getTotalWorldTime() + INTERVAL);
}

Note: null checks not provided.

Link to comment
Share on other sites

Thank you for your wonderful reply! That would've helped me a ton earlier, but it still does. As for not having my code all organized, that's because I'm not an organized person xD. And I haven't implemented a timer yet, I'd planning on doing that once I've got everything else under control. If you look now at my recent edit, it's been fixed, and no longer crashes. I think all I need to know now is how to damage it, when a block is destroyed with it and how to give it that itemstack.stackTagCompound = new NBTTagCompound(); when a command is used to summon it. Because I can just use get sub types and on created for the rest. Thank you for a reply, it was still helpful since I didn't know I forgot the {} on the if statement.

Link to comment
Share on other sites

You don't need to worry about giving it an NBTTagCompound when summoned - the tag will be created the first time the player uses it. Unless, of course, you need to store other things in the tag, too?

 

I'm not sure if there are any hooks that allow you to change the outcome of /give and other commands, but I doubt it. If the player has /give permissions, they can set the NBT to whatever they want.

 

As for damaging it when destroying a block, check out ItemTool. I'm certain there is an Item (or ItemTool) method that does just that.

Link to comment
Share on other sites

I tested out what you had to say about it removing Enchantments, with my new code, it still removes enchantments though. Because everytime I right click it creates a new... Wait, I'll try something with another NBT... I'll look into ItemTool later. Thanks again! Ah, so what I thought I could do was put an if with a new int called Has it been used? Which would be 0 if it hasn't and I'd put the newnbt.... Yeah, lmao... But, I don't know what you said about it only resetting the nbt on first use, because there is nothing in my code that does that.

Link to comment
Share on other sites

In my earlier post, I mentioned this:

if (!itemstack.hasTagCompound()) { // method name may vary based on version
    itemstack.setTagCompound(new NBTTagCompound());
}

That is the ONLY way you should ever set an empty tag compound on an ItemStack, and that will guarantee that the ItemStack does in fact have an nbt tag.

 

You put that code as the first thing in your #onItemRightClick or #onItemUse method so that the first time the item is used, you will create the tag compound if it doesn't already have one. That way you can add / set your custom tag.

 

You don't need to check if it has the tag or not; integer tags return 0 if they do not exist:

if (stack.getInteger("abljeilahgahgeiah") == 0) {
    // either the tag didn't exist, or it is actually zero
}

Really, though, you shouldn't be too concerned with that if you follow my advice about using the world time + interval instead of a traditional cooldown timer. There is no reason to add yet another a ticking counter when you already have a perfectly good one.

Link to comment
Share on other sites

I've never extended ItemTool and the constructor seems complex... Can I get some help? I don't want my staff do deal any melee damage, or actually be efficient in breaking blocks, nor enchantable.

Basically want it to be an item, that can use this method onBlockDestroyed.

Link to comment
Share on other sites

THANK YOU! I remembered not being able to use that method on Item. Thanks CoolAlias.

 

Final Code: Beware, it isn't organized.

package danieldawn.smallenhancements;

import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.EntityInteractEvent;

public class SeEventHandler {
public static final int INTERVAL = 60;

@SubscribeEvent(priority = EventPriority.NORMAL)
public void onLivingUpdate(EntityInteractEvent e) {
	if(e.entityPlayer.getCurrentEquippedItem() != null){
		EntityPlayer player = (EntityPlayer) e.entityLiving;
		EntityLivingBase entity = (EntityLivingBase) e.target;
		ItemStack itemstack = e.entityPlayer.getCurrentEquippedItem();
		World world = e.entityPlayer.getEntityWorld();

	if(player.getCurrentEquippedItem().getItem() == SmallEnhancements.Heal_Staff){
		if (!itemstack.hasTagCompound()) {
		    itemstack.setTagCompound(new NBTTagCompound());
		}
		if (world.getTotalWorldTime() > itemstack.getTagCompound().getInteger("nextUse")) {
	player.getCurrentEquippedItem().damageItem(1, player);
	itemstack.getTagCompound().setInteger("nextUse", (int) (world.getTotalWorldTime() + INTERVAL));
	entity.heal(entity.getMaxHealth() / 4 + 2);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ + 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX + 0.6D, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.2D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.4D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	entity.worldObj.spawnParticle("happyVillager", entity.posX - 0.6D, entity.posY + 0.6D, entity.posZ - 0.6D, 1.0D, 1.0D, 1.0D);
	world.playSoundEffect(player.posX, player.posY, player.posZ, "random.orb", 4, 1);
	 }}
}
}
}

My Staff class is called Heal_Staff it extends Item, everything in it is pretty unimportant, the big stuff is done in my event handler.

 

Explanation: When an Entity is right clicked, checks if player has something in there hand, if it is a heal staff, it will then check if it doesn't have an nbt tag yet, and give it one if it doesn't have one already. Then, it checks to make sure that the cooldown isn't active, if the cooldown isn't active it damages the heal staff by 1 durability point, heals the entity 1/4 of its hp +2 extra hp, activates a 60 tick cooldown, spawns particles, and makes that ding sound.

Link to comment
Share on other sites

In general, you should only use event handlers when dealing with things from vanilla/other mods. For your own items, override the appropriate

Item

methods to perform whatever action is needed.

Item#itemInteractionForEntity

is called when a player right clicks on an entity with your

Item

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.