Jump to content

Getting the name of a certain entity


jomoetnt

Recommended Posts

Hello everyone!

I'm making a mod with a story line about a penguin war. The righteous penguins are at war with the evil penguins. You craft a dictionary to be able to understand the penguins so you can do quests for them and talk to them. I am trying to make it so that the penguins' names are consistent, as in the name tag is the same as the name it displays in chat when you talk to them. Inside the PenguinDictionary class:

@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
	{
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		
		Minecraft mc = Minecraft.getMinecraft();
		
		RayTraceResult objectMouseOver = mc.objectMouseOver;
				
		if (delay == 0) {
			if (itemstack.getItem() == themodtostartallmods.penguinDictionary)
			{
				if(mc.objectMouseOver != null && mc.objectMouseOver.entityHit != null) 
				{
					Entity Target = objectMouseOver.entityHit;
					
					if(Target instanceof EntityPenguinRighteous) 
					{
						if (EntityPenguinRighteous.trust >= 500)
						{
							if (Quest.hasQuest == false) 
							{
      							//This part gives me the error
								playerIn.sendMessage(new TextComponentString(EntityPenguinRighteous.getCustomNameTag() + ": " + Quest.getQuest()));
								Quest.hasQuest = true;
							} 
						} else
						{
      						//This part gives me the error
							playerIn.sendMessage(new TextComponentString(EntityPenguinRighteous.getCustomNameTag() + ": " + Quest.getDialogue()));
							EntityPenguinRighteous.trust += 10;
						}
					}
				}
			}
			if (Quest.checkIfQuestFinished()) 
			{
				playerIn.sendMessage(new TextComponentString(Quest.messageWhenDoneQuest()));
				playerIn.inventory.addItemStackToInventory(new ItemStack(Items.DIAMOND, 1));
				EntityPenguinRighteous.trust += 50;
				Quest.hasQuest = false;
			}
			if (Quest.hasQuest) 
			{
				playerIn.sendMessage(new TextComponentString(Quest.getName() + ": You already have a quest!"));
			}
			delay = 50;
		}
		return new ActionResult(EnumActionResult.SUCCESS, itemstack);
	}

(Sorry for the long code, I didn't want to leave it out of context)

EntityPenguinRighteous.getCustomNameTag() gives me an error because I did not instantiate EntityPenguinRighteous, and I can not instantiate EntityPenguinRighteous without running into the following problems:

 

If I instantiate EntityPenguinRighteous inside of this method it will generate a random name in chat every time you attempt to talk to the penguin. For example: Waddles: You are quite tall! and then if you talk to them again it will say Wiggles: You look funny! when the name tag displays Tux.

 

If I instantiate EntityPenguinRighteous at the top of this class, I need to write this line of code:

EntityPenguinRighteous epr = new EntityPenguinRighteous(World);

However, I need to pass in a World type, which it does not let me instantiate (It gives me the error World can not be instantiated) and I can only use it if I pass the parameters World worldIn inside a method, which I previously explained I can not do or it would generate a different name each time.

 

If I put the string penguinName inside of the constructor rather than at the top of the class it would not be publicly accessible.

 

Is there any way I could make the chat name display the same string as the name tag? Any help is appreciated!

Edited by jomoetnt
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.