Jump to content

[1.7.10] Need my item to get the players display name


HappyKiller1O1

Recommended Posts

Heyo! So, my question here today is how would I be able to right click a player with my item and then, grab the players display name to save the the itemstack NBT. Pretty simple so thanks for the input in advance. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

You can override the method itemInteractionForEntity() in your Item class to handle the right clicking of a player. You can use the method getDisplayName() in the EntityPlayer class to get a player's name, and you can save the name to nbt using the nbt methods in ItemStack.

Sample (Not tested):

@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase livingBase) {
    if (livingBase instanceof EntityPlayer) {
        NBTTagCompound tagCompound = new NBTTagCompound();
        tagCompound.setString("playerName", ((EntityPlayer) livingBase).getDisplayName());
        stack.setTagCompound(tagCompound);
        return true;
    }
    return false;
}

Link to comment
Share on other sites

Now see, I tried that but, when I right clicked a player (tested it on a server) it returned nothing as if it wasn't the player.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Sorry. xD I mean when I right clicked the player it didn't run the code. I'm not sure if you're suppose to use the EntityPlayer provided.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Well, I made a server and had my brother join. xD I did add this though:

 

if(entityLiving.worldObj.isRemote) {
    return false;
}

 

Would that break the code?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Well, basically I have it add information if the stack NBT tag is not null. The information on the item was not set so, it didn't run. I commented out my system print outs by accident before running the server and shit. DERP

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

If I understand you correctly, you're only letting the item be set if it has already been set before (Because an item's nbt tag, by default, is null). You probably want that the other way around.

 

Sorry, it occured to me that you probably aren't talking about setting the tag in itemInteractionForEntity(). Can I see your code for adding the information?

Link to comment
Share on other sites

Actually I am. xD I probably messed something up because I wrote it late at night. :P Here's the two methods:

 

public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity) {
    	if(entity.worldObj.isRemote) {
    		return false;
    	}
    	
        if(entity instanceof EntityPlayer) {
        	EntityPlayer victim = (EntityPlayer)entity;
        	
        	NBTTagCompound cmp = new NBTTagCompound();
        	
        	String displayName = victim.getDisplayName();
        	
        	cmp.setString("victim", displayName);
        	
        	stack.setTagCompound(cmp);
        	
        	System.out.println("ORIGINAL DISPLAY NAME: " + displayName);
        	System.out.println("SAVED DISPLAY NAME: " + cmp.getString("victim"));
        	
        	return true;
        }
    	
    	return false;
    }

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag) {
	String defaultDisplay = "No Victim Set";
	String victimDisplay = null;

	if(stack.stackTagCompound != null) {
		victimDisplay = stack.stackTagCompound.getString("victim");
	}

	list.add(EnumChatFormatting.DARK_AQUA + "When right clicked, it fires");
	list.add(EnumChatFormatting.DARK_AQUA + "lightning upon the bound player.");
	list.add("");
	list.add(EnumChatFormatting.RED + "Can only be used four times.");
	list.add("");
	list.add(victimDisplay != null ? victimDisplay : defaultDisplay);
	list.add("");
	list.add(EnumChatFormatting.GREEN + "Hold Shift and Right-Click to");
	list.add(EnumChatFormatting.GREEN + "open the victim set menu.");
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

I get the display name because of name changing not being implemented in 1.7.10. Once I update it I'll change the code. :P

No, it is implemented for all versions, if you change your name it will change everywhere. That's why you need to use uuid.

Link to comment
Share on other sites

What I read is that only 1.8 and above will see viewable changes to the display name. But might as well take your advice. How would I go about using UUID for the display name?

 

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Now see, I understand using the UUID for the player. But how would I get the display name? Would I do something like this?:

 

EntityPlayer player = entityLiving.worldObj.getEntityByID(//Player UUID).getDisplayName();

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

So, the reason why it's not displaying the name is because the stack compound tag is null. I'm not sure how considering the server console says it set the tag. Here's my code (Will use UUID after my testing is complete):

public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity) {
    	if(entity.worldObj.isRemote) {
    		return false;
    	}
    	
        if(entity instanceof EntityPlayer) {
        	System.out.println("ENTITY GOTTEN");
        	
        	EntityPlayer victim = (EntityPlayer)entity;
        	
        	NBTTagCompound cmp = new NBTTagCompound();
        	
        	String displayName = victim.getDisplayName();
        	
        	cmp.setString("victim", displayName);
        	
        	stack.setTagCompound(cmp);
        	
        	System.out.println("ORIGINAL DISPLAY NAME: " + displayName);
        	System.out.println("SAVED DISPLAY NAME: " + cmp.getString("victim"));
        	
        	return true;
        }else {
        	System.out.println("ENTITY WAS NOT PLAYER");
        }
    	
    	return false;
    }

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag) {
	String defaultDisplay = "No Victim Set";
	String victimDisplay = null;

	if(stack.getTagCompound() != null) {
		System.out.println("STACK COMPOUND WAS NOT NULL");
		victimDisplay = stack.getTagCompound().getString("victim");
	}else {
		System.out.println("STACK COMPOUND WAS NULL");
	}

	list.add(EnumChatFormatting.DARK_AQUA + "When right clicked, it fires");
	list.add(EnumChatFormatting.DARK_AQUA + "lightning upon the bound player.");
	list.add("");
	list.add(EnumChatFormatting.RED + "Can only be used four times.");
	list.add("");
	list.add(victimDisplay != null ? victimDisplay : defaultDisplay);
	list.add("");
	list.add(EnumChatFormatting.GREEN + "Hold Shift and Right-Click to");
	list.add(EnumChatFormatting.GREEN + "open the victim set menu.");
}

 

Any reason why this is caused?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Halo para penggemar slot online! Apakah Anda mencari pengalaman bermain slot yang seru dan menguntungkan? Apakah Anda ingin menikmati slot gacor dari server Thailand sambil melakukan deposit melalui Mandiri dengan kesempatan meraih kemenangan besar? Anda telah sampai di tempat yang tepat! Kami di WINNING303 siap memberikan Anda pengalaman bermain yang mengasyikkan dan menguntungkan. Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot dengan berbagai keunggulan yang kami tawarkan kepada para pemain kami. Berikut adalah beberapa alasan mengapa Anda harus memilih WINNING303: Slot Gacor dari Server Thailand Kami menyajikan koleksi slot gacor terbaik dari server Thailand yang pastinya akan memberikan Anda pengalaman bermain yang menarik dan menguntungkan. Nikmati berbagai jenis permainan slot dengan tingkat kemenangan yang tinggi dan jackpot yang menarik. Deposit Mudah Melalui Mandiri Kami memahami pentingnya kemudahan dalam bertransaksi bagi para pemain kami. Oleh karena itu, kami menyediakan layanan deposit melalui bank Mandiri, salah satu bank terbesar di Indonesia. Proses depositnya cepat, mudah, dan aman, sehingga Anda dapat langsung memulai petualangan bermain tanpa hambatan. Peluang Maxwin Besar Di WINNING303, kami selalu memberikan peluang untuk meraih kemenangan besar. Dengan berbagai promosi dan bonus menarik yang kami sediakan, Anda memiliki kesempatan untuk memenangkan hadiah-hadiah yang fantastis dan meraih maxwin dalam bermain slot.  
    • SLOT Ratubet77 adalah bocoran slot gacor rekomendasi dari Ratubet77 yang bisa anda temukan di SLOT Ratubet77. Situs SLOT Ratubet77 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ratubet77 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ratubet77 merupakan SLOT Ratubet77 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ratubet77. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ratubet77 hari ini yang telah disediakan SLOT Ratubet77. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ratubet77 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ratubet77 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ratubet77 di link SLOT Ratubet77. DAFTAR SEKARANG DAFTAR SEKARANG DAFTAR SEKARANG
    • I am currently running the 1.20.1 Occultcraft modpack in Curseforge and am having numerous troubles making a mob farm with the apotheosis mod. When trying to modify the stats of the spawners specific stats such as the range, spawn count, and max entities reset to default after every spawn. When the spawners spawn boss mobs with certain attributes, that I'm not sure of, the building it is in explode even with mob griefing turned off. This has happened multiple times with varying sizes for the explosions. I was wonder if there is any way to disable these explosions from happening or disable boss abilities with something in the game. I also wanted to know a fix for the resetting stats on spawners and why this is happening.
    • SLOT Bank BSI adalah pilihan terbaik untuk Anda yang ingin merasakan sensasi bermain slot dengan layanan dari Bank BSI. Dengan keamanan terjamin, beragam pilihan permainan, kemudahan deposit via Bank BSI, dan berbagai bonus menarik, kami siap memberikan Anda pengalaman bermain yang tak terlupakan. Bergabunglah dengan kami sekarang dan mulailah petualangan seru Anda!    
    • Mengapa Memilih WINNING303? WINNING303 telah dikenal sebagai salah satu platform terbaik untuk bermain slot Pragmatic di Indonesia. Apa yang membuat kami unggul? Kami memiliki sejumlah keunggulan yang akan membuat pengalaman bermain Anda lebih menyenangkan. Keamanan Terjamin Keamanan adalah prioritas utama kami di WINNING303. Kami menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan Anda. Dengan begitu, Anda dapat bermain dengan tenang tanpa perlu khawatir tentang keamanan informasi Anda. Beragam Pilihan Permainan Kami menyediakan berbagai macam permainan slot Pragmatic yang menarik dan menghibur. Mulai dari tema klasik hingga yang paling modern, Anda pasti akan menemukan permainan yang sesuai dengan selera Anda di WINNING303. Selain itu, kami juga secara teratur memperbarui koleksi permainan kami untuk memberikan pengalaman bermain yang segar dan menarik setiap saat. Kemudahan Deposit Via Bank Niaga 24 Jam Kami mengerti bahwa kenyamanan dalam bertransaksi sangatlah penting bagi para pemain. Oleh karena itu, kami menyediakan layanan deposit melalui Bank Niaga yang dapat diakses 24 jam sehari, 7 hari seminggu. Prosesnya cepat dan mudah, sehingga Anda dapat langsung memulai permainan tanpa menunggu waktu lama. Bonus dan Promosi Menarik Di WINNING303, kami selalu memberikan bonus dan promosi yang menggiurkan bagi para pemain setia kami. Mulai dari bonus selamat datang hingga bonus deposit, ada banyak penawaran menarik yang dapat Anda manfaatkan untuk meningkatkan peluang kemenangan Anda.         
  • Topics

×
×
  • Create New...

Important Information

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