# Adjust X, Y, Z of block selected

Discussion in 'Plugin Development' started by Snowl, Jan 22, 2011.

Not open for further replies.
1. Offline

### Snowl

If I have a block
Code:
`Block block = event.getBlock();`
and I want to select the block above it
Code:
`Block block = event.getBlock().getY() + 1;`
How would I do this?

#1
2. Offline

### Timberjaw

If you can access the player for this event, you can do something like:
Code:
`Block block2 = event.getPlayer().getWorld().getBlockAt(block.getX(), block.getY()+1, block.getZ());`
I should mention I haven't done much with blocks/coordinates, so you'll want to double check that Y is in fact the vertical axis, if you haven't already.

#2
3. Offline

### Snowl

I have been doing that but it gives me wierd results in different angles:
If I face one way, it works correctly 100%, but if I move at a 90 degree angle it breaks, move another 90 degrees and its fine, another 90 degrees and it breaks again:

This portal was placed in the 'normal' position:

One on the left is normal, one on the right was at a different angle:

Another example:

#3
4. Offline

### NathanWolf

Hi- just thought I'd mention, there's a better way to do this

block.getFace(BlockFace.UP)

Navigating around blocks relatively is a lot easier if you use getFace.

#4
5. Offline

### Snowl

How could I do block.getFace(BlockFace.UP) && block.getFace(BlockFace.UP) && block.getFace(BlockFace.LEFT) && block.getFace(BlockFace.LEFT) for example?

#5
6. Offline

Try something like
event.getBlock().getRelative(2,2,0);
or
event.getBlock().getRelative(0,2,2);
where getRelative(x,y,z)
and y is up.
x and z are north or west. Don't know which was which

#6
7. Offline

### Snowl

YES! thank you

#7