Add block.getRelative() funcs and docs (#3)

This commit is contained in:
Jeffery Tolmie 2026-04-03 11:36:53 +13:00 committed by GitHub
parent ebc1d4c640
commit b97fe888d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -121,4 +121,46 @@ public class Block
return NativeBridge.BreakBlock(_world.getDimensionId(), _x, _y, _z) != 0;
return false;
}
/// <summary>
/// Gets the block at the given offsets
/// </summary>
/// <param name="modX">X offset</param>
/// <param name="modY">Y offset</param>
/// <param name="modZ">Z offset</param>
/// <returns>Block at the given offsets</returns>
public Block getRelative(int modX, int modY, int modZ)
{
return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ);
}
/// <summary>
/// Gets the block at the given face
/// <para>This method is equal to getRelative(face, 1)</para>
/// </summary>
/// <param name="face">BlockFace to get relative to</param>
/// <returns>Block at the given face</returns>
public Block getRelative(BlockFace face)
{
return getRelative(face, 1);
}
/// <summary>
/// Gets the block at the given distance of the given face
/// <para>For example, the following method places water at 100,102,100; two
/// blocks above 100,100,100.</para>
/// <code>
/// Block block = world.getBlockAt(100, 100, 100);
/// Block shower = block.getRelative(BlockFace.UP, 2);
/// shower.setType(Material.WATER);
/// </code>
/// </summary>
/// <param name="face">BlockFace to get relative to</param>
/// <param name="distance">Distance to get relative to</param>
/// <returns>Block at the given distance of the given face</returns>
public Block getRelative(BlockFace face, int distance)
{
return getRelative(face.getModX() * distance, face.getModY() * distance, face.getModZ() * distance);
}
}