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!