Jump to content

[1.6.4] addChatMessage on a custom event


Dispellz

Recommended Posts

I'm trying to simply show a message when a custom event fires.

 

@ForgeSubscribe
public void onPlayerPlaceFurnace(PlayerInteractEvent event) {
	EntityPlayer p = event.entityPlayer;
	if(event.action == Action.RIGHT_CLICK_BLOCK) {
		ItemStack s = p.inventory.getCurrentItem();
		if(s.itemID == Block.furnaceIdle.blockID) {
			this.mc.getNetHandler().getPlayer().addChatMessage("Furnace Placed");
		}
	}
}

 

The problem I'm running into is whenever I actually place a furnace, I see "Furnace Placed" twice in chat. I can't figure out why this fires twice. Is there something else I should be doing?

Link to comment
Share on other sites

I've added isRemote, however that did not help. I've noticed something different in the console. Whenever the event fires this happens:

 

2014-02-11 21:20:06 [iNFO] [Minecraft-Server] Saving and pausing game...
2014-02-11 21:20:06 [iNFO] [Minecraft-Server] Saving chunks for level 'TestCreative'/Overworld
2014-02-11 21:20:06 [iNFO] [Minecraft-Server] Saving chunks for level 'TestCreative'/Nether
2014-02-11 21:20:06 [iNFO] [Minecraft-Server] Saving chunks for level 'TestCreative'/The End
2014-02-11 21:20:11 [iNFO] [Minecraft-Client] [CHAT] Furnace Placed
2014-02-11 21:20:11 [iNFO] [Minecraft-Client] [CHAT] Furnace Placed
2014-02-11 21:20:12 [iNFO] [Minecraft-Server] Saving and pausing game...

 

So it looks like it's actually the client that fires twice.

Link to comment
Share on other sites

@ForgeSubscribe
public void onPlayerPlaceFurnaceOld(PlayerInteractEvent event) {
	EntityPlayer p = event.entityPlayer;
	if(event.action == Action.RIGHT_CLICK_BLOCK) {
		ItemStack s = p.inventory.getCurrentItem();
		if(s.itemID == Block.furnaceIdle.blockID) {
			if(!this.mc.theWorld.isRemote) {
				this.mc.getNetHandler().getPlayer().addChatMessage("Furnace Placed");
			}
		}
	}
}

 

In this case, I don't get any chat messages. if I change it to:

 

if(this.mc.theWorld.isRemote) {
				this.mc.getNetHandler().getPlayer().addChatMessage("Furnace Placed");
			}

 

I get the double message again. I don't know if this is worth noting, but I have another event that checks if player breaks a furnace.

 

@ForgeSubscribe
public void onPlayerDestroyFurnace(BreakEvent event) {
	Block b = event.block;
	if(b == Block.furnaceIdle || b == Block.furnaceBurning) {
		this.mc.getNetHandler().getPlayer().addChatMessage("Furnace Destroyed");
	}
}

 

And this displays correctly, single message.

Link to comment
Share on other sites

@ForgeSubscribe

public void onPlayerPlaceFurnace(PlayerInteractEvent event) {

EntityPlayer p = event.entityPlayer;

if(event.action == Action.RIGHT_CLICK_BLOCK) {

ItemStack s = p.inventory.getCurrentItem();

if(s.itemID == Block.furnaceIdle.blockID) {

this.mc.getNetHandler().getPlayer().addChatMessage("Furnace Placed");

}

}

}

TO

@ForgeSubscribe

public void onPlayerPlaceFurnace(PlayerInteractEvent event) {

EntityPlayer p = event.entityPlayer;

if(event.action == Action.RIGHT_CLICK_BLOCK) {

ItemStack s = p.inventory.getCurrentItem();

if(s.itemID == Block.furnaceIdle.blockID && !p.worldObj.isRemote) {

p.addChatMessage("Furnace Placed");

}

}

}

Link to comment
Share on other sites

MovingObjectPosition m = new MovingObjectPosition(e.entityPlayer);

if(!e.entityPlayer.worldOb.isRemote && (e.entityPlayer.worldObj.getBlock(m.blockX, m.blockY, m.blockZ) == Block.furnaceIdle ||e.entityPlayer.worldObj.getBlock(m.blockX, m.blockY, m.blockZ) == Block.furnaceActivated)){

//do your stuff

}

 

Edit if you want a smp mod..., send the messages on the furnace destroy event, the same way as i told you to use on the interact event.....

Link to comment
Share on other sites

My Bad

change the moving object position to

MovingObjectPosition m = Minecraft.getMinecraft().objectMouseOver;

 

Thank you for all the help. You are awesome!

 

Stop using the Minecraft client on server side, please.

 

I realize this is a simple mistake, but I just started to figure forge out a few days ago. I didn't know that calling addChatMessage would call it on both sides. How do I know when to check for isRemote?

Link to comment
Share on other sites

I realize this is a simple mistake, but I just started to figure forge out a few days ago. I didn't know that calling addChatMessage would call it on both sides. How do I know when to check for isRemote?

 

Every time you need to do something that alters the world, or objects within it (and checking not-remote).

Every time you need to do something that is specific to the person-who-is-playing (rendering, input, etc).

 

Also, never ever use Minecraft.getMinecraft() for any reason.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Also, never ever use Minecraft.getMinecraft() for any reason.

Why not? I use it all the time :P

 

Because you know what it's for.  All these newbs go and do stuff like this:

 

 

function someArbitraryFoo(World world, int x, int y, int z) {
    if(!Minecraft.getMinecraft().getWorld().isRemote) {
        //do stuff
    }
}

 

Because they think that's the only way to get access to a world object.  It's like, "hello, it's passed to you" or "hello, that object contains a reference to its own world object" or "hello, you're coding inside an entity, it has one already."

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • DAFTAR & LOGIN BIGO4D Bigo4D adalah situs togel online yang menjadi pilihan banyak pemain di Indonesia. Dengan berbagai keunggulan yang dimilikinya, Bigo4D mampu menjadi situs togel terbesar di pasaran saat ini. Dalam artikel ini, kami akan membahas secara lengkap tentang Bigo4d dan alasan-alasannya menjadi situs togel favorit banyak pemain.
    • Slot Gacor >> Mudah Maxwin Bersama Djarum4D   Slot gacor adalah salah satu jenis permainan judi online yang sangat populer di Indonesia. Bermain slot gacor berarti bermain permainan slot dengan kemungkinan keluaran yang lebih tinggi daripada slot tradisional. Dalam artikel ini, kami akan membahas secara lengkap tentang slot gacor, mulai dari pengertian dasar, cara bermain, strategi pemain, serta aspek keamanan dan etika dalam bermain.
    • DAFTAR & LOGIN TAYO4D   Slot gacor online adalah permainan yang menarik dan menghasilkan keuntungan untuk banyak pemain di seluruh dunia. Dalam artikel ini, kita akan membahas tentang cara memilih dan memainkan slot gacor online terbaik.
    • Tayo4D : Bandar Online Togel Dan Slot Terbesar Di Indonesia     Pemain taruhan Tayo4D yang berkualitas memerlukan platform yang aman, terpercaya, dan mudah digunakan. Dalam era teknologi ini, banyak situs online yang menawarkan layanan taruhan togel 4D, tetapi memilih yang tepat menjadi tuntas. Berikut adalah cara untuk membuat artikel yang membahas tentang situs online terpercaya untuk permainan taruhan togel 4D.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
  • Topics

×
×
  • Create New...

Important Information

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