if (godMode != true)
{var meta = false; //Set to true if block uses subtypes.
var maxdist = 5; //Maximum distance to look when placing down a block.
var main = player.getInventory().getCurrentItem();
var offhand = player.getInventory().getOffhandItem();
var vec = player.getLookVec(); var pos = player.getPosition();
var lastAirPos = [pos.x,pos.y,pos.z]; var check = lastAirPos;

for (i = 0; i <= maxdist; i += 0.1) {check[0] = Math.floor(vec.x*i+pos.x);
check[1] = Math.floor(vec.y*i+pos.y); check[2] = Math.floor(vec.z*i+pos.z);
if (world.getBlockID(check[0],check[1],check[2]) != 0 ) { 
if (Math.floor(pos.x) == lastAirPos[0] && (Math.floor(pos.y) == lastAirPos[1]
|| Math.floor(pos.y - 1) == lastAirPos[1]) && Math.floor(pos.z) == lastAirPos[2]) {break;}
world.setBlockIDAndMetadata(lastAirPos[0],lastAirPos[1],lastAirPos[2],lastItemUsed.getItemID(),meta?lastItemUsed.getDamage():0);
if (lastItemUsed.quantity-- == 1) {for (j=0;j<=8;j++) {
if (player.getInventory().getItemInSlot(j) == lastItemUsed) { player.getInventory().emptySlot(j); break;}}}break;}
lastAirPos = [check[0],check[1],check[2]];}}