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

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?

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

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

@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");

}

}

}

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

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

My Bad

change the moving object position to

MovingObjectPosition m = Minecraft.getMinecraft().objectMouseOver;

  • 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?

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.

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.

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.

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.