Posted May 16, 20169 yr 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 = ?; } } }
May 16, 20169 yr 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.
May 17, 20169 yr 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
May 17, 20169 yr 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.