Jump to content

[SOLVED] Return item on right click?


P0rtal

Recommended Posts

Alright, so I'm trying to make a mod where blood is basically the essence of life, and the most important item is not working correctly.

What I'm trying to do is make it so that onItemRightClick the Item removes itself, hurts the player and gives itself an other Item.

 

My Item Class:

package p0rtal.items;

import p0rtal.main.Strings;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

public class needle extends Item {
{
	this.setUnlocalizedName("needle");
	this.setTextureName(Strings.modid + ":" + "needle");
	this.setMaxStackSize(1);
	setContainerItem(smItems.needle_use);
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
	if(stack != null){

		--stack.stackSize;
		getContainerItem();
		player.attackTargetEntityWithCurrentItem(player);
	}

return stack;

}
}

 

I've tried adding the setContainerItem() inside the if Statement (where the --stack.stackSize; and stuff is)and right before the return line, same thing with getContainerItem(). Each time I use the item though, it only damages me and gets rid of the item. Is there a way to do this?

 

Thanks in advance,

P0rtal.

Link to comment
Share on other sites

getContainerItem(); //this line is doing nothing

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Alright so I changed it from the container to a new itemstack:

 

package p0rtal.items;

import p0rtal.main.Strings;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

public class needle extends Item {
{
	this.setUnlocalizedName("needle");
	this.setTextureName(Strings.modid + ":" + "needle");
	this.setMaxStackSize(1);

}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
	if(stack != null){

		--stack.stackSize;
		player.attackTargetEntityWithCurrentItem(player);
		player.inventory.addItemStackToInventory(new ItemStack(smItems.needle_use));
	}
	return stack;
}
}

 

It spawns in the item now, yes, but it deletes it also at the same time. They don't share the same ID too...

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.