Jacknoshima Posted September 10, 2013 Posted September 10, 2013 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? Quote
Jacknoshima Posted September 10, 2013 Author Posted September 10, 2013 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 Quote
fhntv24 Posted September 10, 2013 Posted September 10, 2013 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 Quote
Jacknoshima Posted September 10, 2013 Author Posted September 10, 2013 yeah, I just got it before I saw your comment 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 Quote
fhntv24 Posted September 10, 2013 Posted September 10, 2013 heh,you didnt say what you have worldObj at you class,so i made it with player world Quote
GotoLink Posted September 10, 2013 Posted September 10, 2013 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. Quote
Recommended Posts
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.