How to get Block position from BlockEvent in Minecraft - Spigot
java, minecraft
Solution
This will get you the `Location`of that block:
Location blockLocation = b.getLocation();
The `Location` class allows you to access the coordinates using `getBlockX()`, `getBlockY()` and `getBlockZ()` and also `getWorld()` and others (Reference).
And if you want to work with `RegionCoordinates` you can use this on your `blockLocation`:
RegionCoordinates regionCoords = RegionCoordinates.fromLocation(blockLocation);
Problem
Ok, so in the making of a plugin for Minecraft, I found a problem that I can't seem to be able to overcome. So the problem is, that I want to get the position of placed Diamond Block, so I can check around that block for other blocks. I want to make an automated farming plugin. 'Till now I've tried to do it with ``` public void OnDiaBlockPlace(BlockPlaceEvent e){ Block b = e.getBlock(); b.getPosition(); } ``` and with ``` public void onPlantGrow(BlockGrowEvent e){ Block b = e.getBlock(); b.getPosition(); } ``` But the `b.getPosition();` doesn't exist in spigot/craftbukkit API. I just want to know if there is any way around this problem and how I could solve this. TL/DR: How can I get a block position from the BlockPlaceEvent or BlockGrowEvent in an x,y,z format? Thanks to everyone in advance. EDIT: Working piece of code: ``` public void onPlantGrow(BlockGrowEvent e){ Block b = e.getBlock(); int x = b.getLocation().getBlockX(); int y = b.getLocation().getBlockY(); int z = b.getLocation().getBlockZ(); } ```