Jump to content

Recommended Posts

Posted

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;


}
}

Posted

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.

Posted

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();

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

Ah, I didn't scroll down on your post, wow. But, thanks this was very helpful. Your timer is great too. The nbt check is brilliant. Thank you! I will be uploading my final code when my staff is done.

Posted

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.

Posted

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.

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.