if (timing >= 5) {timing = 0;
if (pinv.getCurrentItem() != null)
{if (pinv.getCurrentItem().itemID == 2021) {var ent = pinv.getCurrentItem(); player.swingMainHand();}}
if (pinv.getOffhandItem() != null) 
{if (pinv.getOffhandItem().itemID == 2021) {var ent = pinv.getOffhandItem(); player.swingOffHand();}}
var power = 3+Math.sqrt(gardening_lvl); var damage;

time.sleep(0.05);
if (hitBlock != null) {target = player.lookVec.scale(5).add(player.position); results = player.rayTrace(player.position, target);
if (results[0] != null) {
ID = world.getBlockID(results[0].x - vec.x/10, results[0].y - vec.y/10, results[0].z - vec.z/10 - 1);
dmg = world.getMetadata(results[0].x - vec.x/10, results[0].y - vec.y/10, results[0].z - vec.z/10 - 1);} else {ID = 0;}
if (ID == 9 || ID == 8) {ent.damage = Math.max(ent.damage-3,0);}

var blockID = world.getBlockID(hitBlock.x,hitBlock.y,hitBlock.z);
var blockMD = world.getMetadata(hitBlock.x,hitBlock.y,hitBlock.z);

if (hitBlock.x != blockx || hitBlock.y != blocky || hitBlock.z != blockz) 
{blockx = hitBlock.x; blocky = hitBlock.y; blockz = hitBlock.z; blockHP = 0;
if (blockID == 60 && blockMD == 0) {blockHP = 30; blockName = "Farmland"; 
random_max = 30; changeID = 60; changeMD = 7;
function onDestroyed() {gardening_xp += 1;}}
if (blockID == 59 && blockMD <= 6) {blockHP = 20; blockName = "Wheat"; random_max = 30; 
changeID = 59; changeMD = Math.min(blockMD+1,7);
function onDestroyed() {gardening_xp += 1;}}
if (world.getBlockID(hitBlock.x,hitBlock.y+1,hitBlock.z) == 208 &&
world.getMetadata(hitBlock.x,hitBlock.y+1,hitBlock.z) == 2) 
{blockHP = 30; blockName = "Flower spore"; random_max = 30;
if (superGarden [actD] [1] [0] != hitBlock.x || superGarden [actD] [1] [1] != hitBlock.y || 
superGarden [actD] [1] [2] != hitBlock.z) 
{for (var i = 0; superGarden [i] != undefined && superGarden [i] [0] == true; i++) {
if (superGarden [i] [1] [0] == hitBlock.x && superGarden [i] [1] [1] == hitBlock.y+1 && superGarden [i] [1] [2] == hitBlock.z)
{blockx = superGarden [i] [1] [0]; blocky = superGarden [i] [1] [1]-1; blockz = superGarden [i] [1] [2];}}} else {i = actD;}
function onDestroyed() {gardening_xp += 2;}} blockMaxHP = blockHP;
if (world.getBlockID(hitBlock.x,hitBlock.y+1,hitBlock.z) == 208 &&
world.getMetadata(hitBlock.x,hitBlock.y+1,hitBlock.z) == 2) {blockHP -= superGarden [actD] [4];}}

else {if (ent.damage < 32) {if (world.getBlockID(hitBlock.x,hitBlock.y+1,hitBlock.z) == 208 &&
world.getMetadata(hitBlock.x,hitBlock.y+1,hitBlock.z) == 2) 
{superGarden [actD] [2] = Math.min(superGarden [actD] [2]+power, 100);}
else {blockHP = Math.max(blockHP-power,0);}  
if (Math.random()*32/Math.sqrt(gardening_lvl) > 3 && ID != 9 && ID != 8) {ent.damage += 1;}}
if (blockHP == 0 && blockMaxHP > 0) 
{var rand = Math.floor(Math.random() * random_max);
world.setBlockIDAndMetadata(hitBlock.x,hitBlock.y,hitBlock.z,changeID,changeMD);
blockx = 0; blocky = 0; blockz = 0; onDestroyed();}}}}