Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • Author

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

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

  • Author

yeah, I just got it before I saw your comment :P

Though  I found just adding it into a

 

if (!worldObj.isRemote)
{
addChatMessage("moo")
}

 

seemed to work

 

but I'll keep in mind the code you've given me for future use if I need to do more complex stuff with it

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.