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 get the position of the placed block out of the PlaceEvent. How is this possible?

 

@SubscribeEvent
public void onBlockPlace(PlaceEvent e) {
if(e.player == plugin.getPlayer()) {
	if(e.placedBlock == Blocks.redstone_torch.getDefaultState()) {
		BlockPos bp = ?;
	}
}
}

Did you try looking at the source code of the

BlockEvent.PlaceEvent

class or the fields/methods you can access on the instance you've been provided? Use the

BlockEvent#pos

field (in 1.8.9 and earlier) or

BlockEvent#getPos

method (in 1.9) to get the

BlockPos

of any

BlockEvent

subclass (e.g.

BlockEvent.PlaceEvent

).

 

An

IBlockState

represents a specific state of a

Block

. If you only care about the

Block

itself, use

IBlockState#getBlock

to get the

Block

and compare that instead of the state.

 

Are you sure you want to compare the player with

==

? A new instance is created every time a player respawns, so

plugin

(whatever it is) will have to maintain a reference to the current player instance. You may want to store and compare the player's

UUID

instead: use

Entity#getUniqueID

to get it and

Object#equals

to compare it.

 

Edit: Always specify the Minecraft version you're using in the thread title.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

So I tried it without the player == player but not even this code works:

 

@SubscribeEvent
public void onBlockPlace(PlaceEvent e) {
plugin.sendMessage("ASDASDSd");
}

 

It seems like the Event doesn't get called once a player places a block. But all the other Events in this class get fired... I have a KeyInputEvent who works fine

Have you registered the handler on the right event bus? In 1.8 and earlier,

KeyInputEvent

is fired on the FML bus (

FMLCommonHandler#bus

) and

BlockEvent.PlaceEvent

is fired on the Forge bus (

MinecraftForge.EVENT_BUS

). In 1.8.8 and later, the FML bus has been merged with the Forge bus.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.