Posted February 12, 201411 yr 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?
February 12, 201411 yr Author 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.
February 12, 201411 yr Author @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.
February 12, 201411 yr @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"); } } }
February 12, 201411 yr Author Thank you a lot for the help guys! This last piece works perfectly! One more thing. Is there a way to restrict this, so it only works when user places the block? At this moment it also shows "Block Placed" when I use the furnace.
February 12, 201411 yr 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.....
February 12, 201411 yr Author That last piece of code doesn't seem to be working, "m" returns 0 on x, y and z.
February 12, 201411 yr My Bad change the moving object position to MovingObjectPosition m = Minecraft.getMinecraft().objectMouseOver;
February 12, 201411 yr Author 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?
February 12, 201411 yr 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.
February 12, 201411 yr Also, never ever use Minecraft.getMinecraft() for any reason. Why not? I use it all the time 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.
February 13, 201411 yr 2 of his classes were using client thing on server side, he was checking with a worldclient instance to see if was instancieded to worldserver so 99% sure that he does other bad things so i just showed him the most easy way '-'
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.