Jump to content

Trouble with adding chat message on interact


Jacknoshima

Recommended Posts

Okay, so, I wanted to add a chat message when interacting with an entity

I got it to send the chat message but, for some reason, it sends it twice

 

here is the code

 

 

    public boolean interact(EntityPlayer par1EntityPlayer)
    {
        ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();

        if (itemstack != null && itemstack.itemID == AdvZelda.bottleempty.itemID && !par1EntityPlayer.capabilities.isCreativeMode)
        {
            if (itemstack.stackSize-- == 1)
            {
                par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, new ItemStack(AdvZelda.lonlonmilk));
            }
            else if (!par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(AdvZelda.lonlonmilk)))
            {
                par1EntityPlayer.dropPlayerItem(new ItemStack(AdvZelda.lonlonmilk.itemID, 1, 0));
            }
            
    		par1EntityPlayer.addChatMessage("Moo");


            return true;
        }
        else
        {
            return super.interact(par1EntityPlayer);
        }
    }

 

 

can anyone tell me why it's sending the chat message twice?

Link to comment
Share on other sites

it seems to add the chat message twice even if I don't have it under the if statement

 

as in

 

 

    public boolean interact(EntityPlayer par1EntityPlayer)
    {
    	par1EntityPlayer.addChatMessage("moo");
        ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();

        if (itemstack != null && itemstack.itemID == AdvZelda.bottleempty.itemID && !par1EntityPlayer.capabilities.isCreativeMode)
        {
            if (itemstack.stackSize-- == 1)
            {
                par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, new ItemStack(AdvZelda.lonlonmilk));
            }
            else if (!par1EntityPlayer.inventory.addItemStackToInventory(new ItemStack(AdvZelda.lonlonmilk)))
            {
                par1EntityPlayer.dropPlayerItem(new ItemStack(AdvZelda.lonlonmilk.itemID, 1, 0));
            }

            return true;
        }
        else
        {
            return super.interact(par1EntityPlayer);
        }
    }

 

 

still adds it twice

Link to comment
Share on other sites

its sends message twice,beacos you need to check server side and client side.....message to player sending from both of them,so you need to check is it server or no.How to do it?

if (!mc.thePlayer.worldObj.isRemote) {
			  //client side
		  } else
		  {
			  //server side
		  }

if you want,you can add that simple message "moo" at client side,but if you want to make it "Moo my age is"+bla bla,then you need to make it server side,beacos that is better ;)

 

p.s. if you want,you can send message on client for first comment,that will work

Link to comment
Share on other sites

its sends message twice,beacos you need to check server side and client side.....message to player sending from both of them,so you need to check is it server or no.How to do it?

if (!mc.thePlayer.worldObj.isRemote) {
			  //client side
		  } else
		  {
			  //server side
		  }

if you want,you can add that simple message "moo" at client side,but if you want to make it "Moo my age is"+bla bla,then you need to make it server side,beacos that is better ;)

 

p.s. if you want,you can send message on client for first comment,that will work

You mixed up client and server side, but the idea is here. :P

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.