if (!player.isAlive() && death == 0 && dead == 0) {death = 1; pinv.dropAllItems(); pHealth = player.maxHealth; if (handfull == 1) {dead = 1;}}
if (player.isAlive() && death == 1 && dead == 1) {
	 world.triggerArea(-240, 97, -147, -240, 97, -146); pinv.addItem(Item(4)); handfull = 0;
	death = 0; hunger = 0; energy = maxEnergy; dailyEnergy = 100; player.health = pHealth = player.maxHealth; 
}
if (player.isAlive() && death == 0 && dead == 1) {if (pinv.getSlotContainingItem(4) == -1) {player.health = 0;}}
if (godMode == true) {hunger = 0; energy = maxEnergy; dailyEnergy = 100;}
if (dead == 1 && time.time != 6000) {time.setTime(6000); time.rate = 0;}
if (dead%2 == 0 && time.rate == 0) {time.rate = 0.5;}
if (player.isFlying) {godMode = true;}
if (godMode == true) {hunger = 0; energy = maxEnergy; dailyEnergy = 100;}
if (hitBlock != null) {
	blockID = world.getBlockID(hitBlock.x, hitBlock.y, hitBlock.z); blockIDcheck = blockID;
	blockMD = world.getMetadata(hitBlock.x, hitBlock.y, hitBlock.z); blockMDcheck = blockMD;
}

timing += 1; sTiming += 1; realTiming += 1; gameTiming += 0.5; xpGain(); 
if (intence_repair > 0) {intence_repair -= intence_repair/100 + 0.1;}
if (intence_repair < 0 || intence_repair >= 150) {intence_repair = 0;}
if (areaUPcheck != areaUP) {
	areaUPcheck = areaUP;
	for (i = 0; areaUP > i; i++) {world.triggerBlock(91 + i%8*4, 67, -177 - Math.floor(i/8)*9);}
	if (areaUP > 9) {world.triggerArea(91, 67, -186, 92, 67, -186);}
}

if ((gameTiming > 200 || godMode) && playerFirstTeleport == false) {
	playerFirstTeleport = true; if (godMode) {pos = player.getPosition();}
	world.triggerArea(69, 70, -86, 70, 70, -86); 
	if (godMode) {player.setPosition(pos); pinv.addItem(Item(556)); 
	pinv.addItem(Item(560)); pinv.addItem(Item(2038)); pinv.addItem(Item(2101));}
}

i = (burden/maxBurden < 0.75) ? (burden/maxBurden)/2 : 0;
player.setMoveSpeed(Math.min(Math.max((3.3*Math.sqrt(speed))*(Math.sqrt(1 - i)), 0.2), 100)); 
player.gravity = 0.08*Math.min(burden/maxBurden + 1, 3); 
player.jumpVelocity = 0.5*Math.min(Math.max(2.4*Math.sqrt(speed),1.0), 2);
if (keyboard.isKeyDown(29) && (keyboard.isKeyDown(17) || keyboard.isKeyDown(31) || 
keyboard.isKeyDown(30) || keyboard.isKeyDown(32))) {dash();}
if (Math.round((player.getVelocity().y+player.gravity)*3 - player.jumpVelocity*3) == 0)
	{energy -= player.gravity*Math.sqrt(1+i)/2;}
if (pos.distance(player.getPosition()) > 0.1 && !godMode)
	{i = player.getPosition(); energy -= (energyGenerate*i.distance(pos)*3.5)*(burden/maxBurden + 0.75); pos = i;}

if (wasKeyPressed(19)) {chat.print("NPC paths " + ((pathing) ? "disabled" : "enabled")); pathing = !pathing;}

if ((time.getTime() >= 0 && time.getTime() <= 13000) || 
(time.getTime() == 22500 && time.getTime() <= 24000)) {dailyEnergy -= 0.4/(20+complAchievCount)/10;}
if (time.getTime() > 13000 && time.getTime() <= 22500) {dailyEnergy -= 0.6/(20+complAchievCount)/10;}
if (eCheck > energy) {dailyEnergy -= (eCheck - energy)/(10+complAchievCount)/maxEnergy; eCheck = energy;}

speed = Math.max(0.2*energy/maxEnergy*dailyEnergy/100, 0.1)
energy = Math.min(Math.max(energy, 0), maxEnergy);
if (hunger < maxHunger && Math.random()*15 > 10) {hunger += 0.004; hungerTime += 1;}
if (height != ui.getHeight() || width != ui.getWidth()) {uilabels();}

ii = energy/maxEnergy*100;
if (!keyboard.isKeyDown(17) && !keyboard.isKeyDown(31) && !keyboard.isKeyDown(30) && !keyboard.isKeyDown(32)) {
	if (ii <= maxEnergy + energyGenerate) {energy += energyGenerate*dailyEnergy/100;
	if (hungerTime > (120 + hunger - ii)/10 && player.getHealth() == player.getMaxHealth()) 
		{energy += energyGenerate/500*dailyEnergy - (player.getMaxHealth() - player.getHealth() + Math.sqrt(hunger))*energyGenerate/10;}}
}
if (player.insideOfWater == true) {energy -= energyGenerate;}


if (Math.floor(pHealth) > player.health) {pHealth = player.health;}
if (hungerTime > (280 + hunger - ii - dailyEnergy/2)/40 && (hunger - Math.sqrt(ii*4)) < 30 && player.getHealth() < player.getMaxHealth())
	{healing = 1; pHealth += 0.04+Math.sqrt((100-hunger)/2+ii/1.5+dailyEnergy/1.5)/20; hungerTime = 0;}
if (hunger > Math.sqrt(ii)) {
	if (hungerTime > (100 - hunger + ii/2)/20 && (hunger - ii) > -90 && player.getHealth() + 
	Math.sqrt(hunger - Math.sqrt(ii+dailyEnergy))/10*player.getMaxHealth() >= player.getMaxHealth())
		{healing = -1; pHealth += -0.1-Math.pow(hunger,2)/32000; hungerTime = 0;}
}
if (Math.round(pHealth) != player.health) {player.health = pHealth;}

wholeA = helmetA + chestA + leggingsA + bootsA;
if (healthCheck != pHealth && healing != -1 && healthCheck - pHealth > 0 && player.getAir() > 0) {
	pHealth = Math.max(pHealth - (healthCheck - pHealth)*(3/Math.sqrt(Math.max(wholeA/15, 1))),0);
	for (i = 0; i < 4; i++) if (pinv.getItemInSlot(36+i) != null) {
		armorItem = pinv.getItemInSlot(36+i);
		mdmgA = armorItem.maxDamage; dmgA = armorItem.damage;
		armorItem.damage += Math.round(Math.random()*Math.sqrt(healthCheck - pHealth));
		if (armorItem.damage >= armorItem.maxDamage) {pinv.emptySlot(36+i);}
		for (ii = 0; armorV [ii] != undefined; ii++) if (armorItem.itemID == armorV [ii] [0]) {
			light_xp += Math.sqrt(healthCheck - pHealth)*armorV [ii] [2];
			heavy_xp += Math.sqrt(healthCheck - pHealth)*armorV [ii] [3];
		}
	}
	healthCheck = pHealth;
} 
helmetA = 0; chestA = 0; leggingsA = 0; bootsA = 0;
for (i = 0; i < 4; i++) if (pinv.getItemInSlot(36+i) != null) {
	armorItem = pinv.getItemInSlot(36+i); mdmgA = armorItem.maxDamage; dmgA = armorItem.damage
	for (ii = 0; armorV [ii] != undefined; ii++) if (armorItem.itemID == armorV [ii] [0]) {
		armorPT = Math.round((mdmgA - dmgA)/mdmgA*armorV [ii] [1]*(light_lvl/10*armorV [ii] [2]+heavy_lvl/10*armorV [ii] [3]+1));
		if (armorV [ii] [4] == 1) {helmetA = armorPT;} if (armorV [ii] [4] == 2) {chestA = armorPT;}
		if (armorV [ii] [4] == 3) {leggingsA = armorPT;} if (armorV [ii] [4] == 4) {bootsA = armorPT;}
	}
}
if (healthCheck != pHealth) {healthCheck = pHealth;} 

if (pinv.getItemInSlot(36) != null || pinv.getItemInSlot(37) != null || 
pinv.getItemInSlot(38) != null || pinv.getItemInSlot(39) != null) {
	for (i = 1; i < 13; i++) {armorBody [i].alpha = 0;} armorCase.alpha = 1;
	for (i = 0; i < 4; i++) if (pinv.getItemInSlot(39-i) != null) {
		armorItem = pinv.getItemInSlot(39-i);
		if (armorItem.damage*2 < armorItem.maxDamage) {armorBody [1+i*3].alpha = 1;}
		if (armorItem.damage*2 >= armorItem.maxDamage && armorItem.damage*1.5 < armorItem.maxDamage) {armorBody [2+i*3].alpha = 1;}
		if (armorItem.damage*1.5 >= armorItem.maxDamage) {armorBody [3+i*3].alpha = 1;}
	}
} 
else {for (i = 1; i < 13; i++) {armorBody [i].alpha = 0;} armorCase.alpha = 0;}

if (healing == -1 && player.getHealth() < player.getMaxHealth()*0.9) 
{rand = Math.round(Math.random()*600); switch (rand) {
case 0: case 1: case 2: chat.print("Feeling hungry... Is there any food left?"); break;
case 3: case 4: case 5: chat.print("I could eat even a raw porkchop"); break;
case 6: case 7: case 8: chat.print("I am so tired, could use a rest"); break;
case 9: case 10: case 11: chat.print("So hard to walk with this hunger and fatigue"); break;
case 12: case 13: case 14: if (energy/maxEnergy < hunger/100) {chat.print("I better get home and rest. Could use some food too"); break;}
case 15: case 16: case 17: if (energy < maxEnergy*0.2) {chat.print("I can not feel my legs! Must sit down for a second"); break;}
case 18: case 19: case 20: if (dailyEnergy < 20) {chat.print("In condition like this - I should sleep right now!"); break;}}}

if (healing == 1 && player.getHealth() < player.getMaxHealth()*0.9) 
{rand = Math.round(Math.random()*500); switch (rand) {
case 0: case 1: case 2: chat.print("Never felt better"); break;
case 3: case 4: case 5: chat.print("Oh! That wound is gone. Cool"); break;
case 6: case 7: case 8: chat.print("I will never be damaged that easily"); break;
case 9: case 10: case 11: chat.print("It was hard, but I am feeling good so far"); break;
case 12: case 13: case 14: if (energy > maxEnergy*0.8) {chat.print("Do I have the stamina of a bull or what?"); break;}
case 15: case 16: case 17: if (hunger < 20) {chat.print("I feel the power food gives me right now!"); break;}}}

if (healing != 0) {healing = 0;}
// GAMECODE CALCULATION //
gameCode = "."; for (i = 0; i < mS; i++) {if (skillVar [i] [1] < 10) {gameCode += "0" + skillVar [i] [1];} 
else {gameCode += skillVar [i] [1];}} gameCode = "" + gameCode; ii = parseInt(gameCode.split(".") [1])*37;
// GAMECODE RESTORE //
if (gameRestore != 0) {ii = ii/37; for (i = 0; ii [i*2] != undefined; i++) {}}

vel = player.getVelocity(); 
coinAmount.text = Math.floor(coins);
currentSpeed = Math.sqrt(vel.x*vel.x)+Math.sqrt(vel.z*vel.z);
sleepLabel.v = 55/2*Math.floor(6-dailyEnergy/100*6);
energyLabelHP.u = 25 + (1-energy/maxEnergy-0.25) * 83; energyLabelHP.green = energy/maxEnergy;
energyLabelHP.red = 1-energy/maxEnergy; energyLabelHP.blue = 0; energyLabelHP.x = width - 95 + (1-energy/maxEnergy-0.25) * 83; 
energyAmount.text = "%" + Math.round(energy/maxEnergy*100); energyAmount.x = width - 72 - ui.getStringWidth(energyAmount.text)/2;
hungerLabelHP.width = 25 + hunger/100 * 83; hungerLabelHP.green = 1-hunger/100;
hungerLabelHP.red = hunger/100; hungerLabelHP.blue = 0;
hungerAmount.text = Math.round(hunger) + "%"; hungerAmount.x = 70 - ui.getStringWidth(hungerAmount.text)/2;
if (keyboard.isKeyDown(42) && wasKeyPressed(46)) {chat.print(gameCode);}
else if (wasKeyPressed(46)) {timing = 0; statusShow = !statusShow; if (statusShow) {rotCheck = player.getRotation();}}
if (LVLup == true && statusShow == true) {statusShow = false;}
if (statusShow) {
	achievName.text = ""; player.setStunned(1); rot = player.getRotation(); 
	achievName.y = (levelAchiev) ? (height/2 + 40) : (height - 90); achievBonusLabel.y = achievName.y + 10;
	//ROTATE SKILL'S LIST
	if (rot.yaw != rotCheck.yaw) {moveXby += (rotCheck.yaw - rot.yaw); rotCheck = player.getRotation();}
	if (moveXby != 0) {moveXby /= 1.2;}
	if (Math.abs(moveXby) < 0.3) {moveXby = 0;}
	if (isKeyActive(30, 5)) {moveXby += (levelAchiev) ? 12 : 9;}
	if (isKeyActive(32, 5)) {moveXby -= (levelAchiev) ? 12 : 9.5;}
	
	if (wasKeyPressed(31) || wasKeyPressed(17)) {levelAchiev = (!levelAchiev);}
	//SKILLS
	for (var i = 0; i < mS; i++) {
		if (levelAchiev) for (var ii = 0; ii < 3; ii++) {skillShow [i] [ii].x += moveXby;}
		if (skillShow [i] [0].x > 70*mS-100) {skillShow [i] [0].x -= 70*mS;} 
		if (skillShow [i] [0].x < -100) {skillShow [i] [0].x += 70*mS;}
		if (skillShow [i] [0].x > width/2 - 85 && skillShow [i] [0].x < width/2 - 15) {
			if (skillShow [i] [0].texture != skillShow [i] [4]) 
				{skillShow [i] [0].texture = skillShow [i] [4]; skillShow [i] [1].texture = "gui/skillBar2.png";} 
			skillShow [i] [5] = skillVar [i] [0]/skillVar [i] [2]*65+18;
			if (levelAchiev) {achievName.text = skillVar [i] [4] + ": " + Math.floor(skillVar [i] [0]) + "/" + skillVar [i] [2];}
		}
		if (skillShow [i] [0].x < width/2 - 85 || skillShow [i] [0].x > width/2 - 15 || !levelAchiev) {
			if (skillShow [i] [0].texture == skillShow [i] [4]) 
				{skillShow [i] [0].texture = skillShow [i] [3]; skillShow [i] [1].texture = "gui/skillBar.png";} 
			skillShow [i] [5] = skillVar [i] [0]/skillVar [i] [2]*60+22;
		}
		skillShow [i] [1].x = skillShow [i] [0].x; skillShow [i] [1].y = skillShow [i] [0].y;
		skillShow [i] [2].text = skillVar [i] [1]; skillShow [i] [1].width = skillShow [i] [5];
		skillShow [i] [2].x = skillShow [i] [0].x + 52 - ui.getStringWidth(skillShow [i] [2].text)/2;
		skillShow [i] [2].y = skillShow [i] [0].y + 13;
		for (var ii = 0; ii < 3; ii++) {skillShow [i] [ii].alpha = 0.9-ii/10; skillShow [mS] [ii].alpha = 0.9;}
	}
	//ACHIEVEMETS
	achievBonusLabel.x = width - 20 - ui.getStringWidth(achievBonusLabel.text); 
	achievBonusLabel.text = (!levelAchiev) ? "Bonus xp - " + achievCompleted + "%" : "";
	for (var j = achievShowID; j < achievCount + achievShowID; j++) {i = j%achievCount;
	if (!levelAchiev) for (var ii = 0; ii < 2; ii++) {achievLabel [i] [ii].x += moveXby/2;}
	if (achievLabel [i] [0].x < width/2 && achievLabel [i] [0].x + achievLabel [i] [0].width > width/2) { //in
		if (achievLabel [i] [0].v != 32+Math.floor(i/8)*64) {
			achievLabel [i] [0].v = 32+Math.floor(i/8)*64; achievLabel [i] [0].height = achievLabel [i] [0].width = 32;
			achievLabel [i] [1].u = 32;
		}
		if (!levelAchiev) {achievName.text = achievLabel [i] [4] + "\n" + achievLabel [i] [3];}
	}
	if (achievLabel [i] [0].x > width/2 || achievLabel [i] [0].x + achievLabel [i] [0].width < width/2 || levelAchiev) { //out
		if (achievLabel [i] [0].v == 32+Math.floor(i/8)*64) {
			if (Math.abs(achievLabel [i] [0].x - width/2) < Math.abs(achievLabel [i] [0].x + achievLabel [i] [0].width - width/2)) 
				for (var k = 0; k < achievCount; k++) {achievLabel [k] [0].x -= 6; achievLabel [k] [1].x -= 6;}
			achievLabel [i] [0].v = 64+Math.floor(i/8)*64; achievLabel [i] [0].height = achievLabel [i] [0].width = 24;
			achievLabel [i] [1].u = 64; 
		}
	} 
	achievLabel [i] [0].y = height - 50 - achievLabel [i] [0].height/2; 
	if (i != achievShowID) {
		if (i == 0) {achievLabel [i] [0].x = achievLabel [achievCount-1] [0].x + achievLabel [achievCount-1] [0].width;} 
		else {achievLabel [i] [0].x = achievLabel [i-1] [0].x + achievLabel [i-1] [0].width;}
	}
	if (achievLabel [i] [0].x > achievCount*12 + width/2)	{achievLabel [i] [0].x -= achievCount*24 + 8; achievShowID = i;} 
	if (achievLabel [i] [0].x < - achievCount*12 - 12 + width/2) {achievLabel [i] [0].x += achievCount*24; achievShowID = (i+1)%achievCount;}
	achievLabel [i] [1].x = achievLabel [i] [0].x; achievLabel [i] [1].y = achievLabel [i] [0].y;
	achievLabel [i] [0].alpha = 0.9; achievLabel [i] [1].alpha = achievLabel [i] [2];}
	//MAIN SOURCES
	skillShow [mS] [3].alpha = 0.9; skillShow [mS] [1].width = skillVar [mS] [0]/skillVar [mS] [2]*115; 
	skillShow [mS] [2].text = player.health + "/" + player.maxHealth; 
	skillShow [mS] [2].x = width/2 - 84 - ui.getStringWidth(skillShow [mS] [2].text)/2; 
	skillShow [mS] [0].x = width/2 - 3 - ui.getStringWidth(skillShow [mS] [0].text)/2; skillShow [mS] [0].text = skillVar [mS] [1];
	skillShow [mS] [3].x = width/2 - 69 - ui.getStringWidth(skillShow [mS] [3].text); skillShow [mS] [3].text = wholeA;
	skillShow [mS] [4].x = width/2 + 72 - ui.getStringWidth(skillShow [mS] [4].text)/2; 
	skillShow [mS] [4].text = Math.round(burden*10)/10 + "/" + maxBurden; skillShow [mS] [4].alpha = 0.9;
	skillShow [mS] [5].x = width/2 + 63 - ui.getStringWidth(skillShow [mS] [5].text)/2; 
	skillShow [mS] [5].text = complAchievCount; skillShow [mS] [5].alpha = 0.9;
	levelAmount.alpha = 1;
} else {
	achievBonusLabel.text = achievName.text = "";
	for (ii = 0; ii < 6; ii++) {skillShow [mS] [ii].alpha = 0;}
	for (i = 0; i < achievCount; i++) for (ii = 0; ii < 2; ii++) {achievLabel [i] [ii].alpha = 0;}
	for (i = 0; i < mS; i++) for (ii = 0; ii < 3; ii++) {skillShow [i] [ii].alpha = 0;} levelAmount.alpha = 0;
}
hb2.width = pHealth/player.getMaxHealth()*90+20;

checkList = 0; for (i = 0; i < mS; i++) {checkList += skillVar [i] [0];}
if (checkList > checkMain) {skillVar [mS] [0] += checkList - checkMain; checkMain = checkList;}
if (skillVar [mS] [0] >= skillVar [mS] [2]) {
	sound.playSoundUI("sound.levelUP"); skillVar [mS] [1] += 1; skillVar [mS] [0] -= skillVar [mS] [2]; skillVar [mS] [3] = true; skill_inc = 100;
	skillVar [mS] [2] = Math.floor(Math.pow(skillVar [mS] [1] * mS, 1.1))*10; LVLup = true;
}

for (i = 0; i < mS; i++) if (skillVar [i] [0] >= skillVar [i] [2]) {
	sound.playSoundUI("sound.level_up"); checkMain -= skillVar [i] [0];
	skillVar [i] [1] += 1; skillVar [i] [0] -= skillVar [i] [2]; skillVar [i] [3] = true; skill_inc = 100;
	skillVar [i] [2] = Math.floor(Math.pow(skillVar [i] [1]*1.2, 1.5) + 1)*5;
}
//chat.print(timing + ": " + Math.round(timing * Math.sqrt(timing*2 + 4/timing) + 2/timing)*5);

if (skill_inc > 0) {
	skill_inc = Math.max(skill_inc - ((skill_inc > 90) ? 0.15 : 10), 0); 
	sb.y = height/2 - 180 + skill_inc; sb2.alpha = sb.alpha = Math.sqrt(skill_inc/100);
	for (i = 0; i <= mS; i++) if (skillVar [i] [3] == true) {
		if (skill_inc == 0) {skillVar [i] [3] = false;} 
		sb.texture = "gui/" + skillVar [i] [4] + "_skill.png"; 
		sb2.text = "Your current " + skillVar [i] [4] + ((i == mS) ? " skill" : "") + " level is " + skillVar [i] [1];
	}
	sb2.x = width/2 - ui.getStringWidth(sb2.text)/2; sb2.y = sb.y + 60;
}

able_effect = (effect.getOverlay() != "light.png" && effect.getOverlay() != "") 
if ((keyboard.isKeyDown(57) || keyboard.isKeyDown(1)) && able_effect == true) 
	{effect.clearOverlay(); player.setVelocity(0, 0.1, 0);}

if (blind > 0) {blind -= 1;} 
if (blind == 0 && effect.getOverlay() == "light.png") {effect.clearOverlay();} 
// ACHIEVEMENT CALCULATION
for (i = 0; i < achievCount && achievShow == 0; i++) if (achievLabel [i] [2] == 1) {
	sound.playSoundUI("sound.level_up");
	achievSet [i] = 1; achievLabel [i] [2] = 2; achievShow = 0.01; 
	achievClone [3].text = achievLabel [i] [4] + "\n" + achievLabel [i] [3];
	achievClone [1].u = (i%8)*32; achievClone [1].v = 32+Math.floor(i/8)*64;
}
if (achievShow < 2 && achievShow > 0) {achievShow += 0.01;}
if (achievShow < 0.1 && achievShow > 0) {
	achievClone [1].y = 70*achievShow*10 - 52; achievClone [2].y = achievClone [1].y;
	achievClone [3].y = achievClone [1].y + 14; achievClone [4].y = achievClone [1].y + 4;
	achievClone [0].y = achievClone [1].y - 25;
}
if (achievShow < 1 && achievShow > 0.9) {
	achievClone [1].y = 70*(10-achievShow*10) - 52; achievClone [2].y = achievClone [1].y;
	achievClone [3].y = achievClone [1].y + 14; achievClone [4].y = achievClone [1].y + 4;
	achievClone [0].y = achievClone [1].y - 25;
}
if (achievShow > 1) {achievShow = 0;}

// FISH AND PORK CONVERT //
if (pinv.getSlotContainingItem(319) != -1) {pinv.consumeItem(319); pinv.addItem(Item(2019,1));}
if (pinv.getSlotContainingItem(349) != -1) {pinv.consumeItem(349); k = Math.random()*15;
	if (k > 15.2 - fishing_lvl/4) 			{pinv.addItem(Item(2015,1)); fishing_xp += 15;}
	else if (k > 14.0 - fishing_lvl/3.5) 	{pinv.addItem(Item(2014,1)); fishing_xp += 10;}
	else if (k > 13.2 - fishing_lvl/3) 		{pinv.addItem(Item(2013,1)); fishing_xp += 7;}
	else 									{pinv.addItem(Item(2011,1)); fishing_xp += 3;}
}
// SLEEPING //
if (sleeping == undefined || sleeping == 0) 
{if (time.getTime() <= 23300) {waitingTime = 23300 - time.getTime();} 
else {waitingTime = 24000 - time.getTime() + 23300;} sleeping = -1; startTime = gameTiming; slept = 1;}
// HAND_FIX //
if ((pinv.getOffhandItem() != null && offHandFix != pinv.getOffhandItem().itemID)
|| (pinv.getCurrentItem() != null && handFix != pinv.getCurrentItem().itemID)) {
	if (pinv.getOffhandItem() != null) {offHandFix = pinv.getOffhandItem().itemID;}
	if (pinv.getCurrentItem() != null) {handFix = pinv.getCurrentItem().itemID;}
	eatMeter = 0; pinv.consumeItem(468); torchLight();
} 
if ((pinv.getOffhandItem() == null || (slot != null && slot.itemID != pinv.getOffhandItem().itemID))
&& (pinv.getCurrentItem() == null || (slot != null && slot.itemID != pinv.getCurrentItem().itemID))) {eatMeter = 0;}
eatingLabel.alpha = (eatMeter != 0) ? 1 : 0;
//MONEY CONVERTER//
for (ii = 0; godMode != true && ii < pinv.getSizeInventory(); ii++) 
if (pinv.getItemInSlot(ii) != null && pinv.getItemInSlot(ii).quantity > 0) {
	itemInSlot = pinv.getItemInSlot(ii); itemWasTaken = false;
	if (itemInSlot.itemID == 2003) {coins += itemInSlot.quantity; itemWasTaken = true; sound.playSoundUI("sound.money");}
	if (itemInSlot.itemID == 2004) {coins += itemInSlot.quantity*10; itemWasTaken = true; sound.playSoundUI("sound.money");}
	if (itemInSlot.itemID == 2005) {coins += itemInSlot.quantity*100; itemWasTaken = true; sound.playSoundUI("sound.money");}
	if (itemInSlot.itemID == 2041) {hasSchemBook = true; itemWasTaken = true; chat.print("You gained ability to craft items");}
	if (itemInSlot.itemID == 2045) {hasRecipeBook = true; itemWasTaken = true; chat.print("You gained ability to craft food");}
	if (itemWasTaken) {pinv.consumeItemAmount(itemInSlot.itemID, 0, itemInSlot.quantity); break;}
}

//ANTI WOODCUTTING AREA//
for (i = 0; blockHP + blockMaxHP > 0 && hitBlock != null && i < antiKill.length; i++)
	if (blockID == antiKill [i] [2] && blockMD == antiKill [i] [3] && 
		checkPointInBounds(hitBlock, antiKill [i] [0], antiKill [i] [1])) {blockHP = 0; blockMaxHP = 0;}

//CUSTOM COOKING//
cookMaxPG = Math.max(cmpg, Math.round(libraryUP*0.9+kitchenUP*0.1)+1); craftMaxPG = Math.max(ctmpg, libraryUP*3+2);

//CUSTOM COOKING AND CRAFTING//
if (recipe_over || schem_over) {
	scriptRun = (recipe_over) ? "customCooking.js" : "customCrafting.js";
	maxPage = (recipe_over) ? cookMaxPG : craftMaxPG;
	craftFrame.red = 0; craftFrame.green = 1; craftFrame.blue = 1;
	if (craftItemPNG.alpha == 0) {
		if (recipe_over) {activePG = activeCookPG; craftingLevel = cooking_lvl;} else {activePG = activeCraftPG; craftingLevel = crafting_lvl;}
		script.runScript(scriptRun); readItems(); for (i = 0; i < 3; i++) {craftPG[i].alpha = 0;}
		craftFrame.alpha = 1; pageShow.alpha = 1; craftItemPNG.alpha = 1; mainPageShow.alpha = 1;
	}
	if (recipe_over) {activeCookPG = activePG;} else {activeCraftPG = activePG;}
	if (activePG < 1) {activePG = 1;}
	player.setStunned(1);
	
	helpCraft.alpha = (help) ? 1 : 0;
	if (wasKeyPressed(57)) {get_items(); blockID = -1;}
	if ((wasKeyPressed(1) || wasKeyPressed(18) || wasKeyPressed(57)) && actionTime(1))
		{effect.clearOverlay(); recipe_over = false; schem_over = false;}
	mainPageShow.texture = "customCrafting/" + ((recipe_over) ? "cookPage.png" : "craftPage.png");
	 
	craftFrame.x = width/2 - 100 + collumnShow*70; craftPG[0].text = "<" + (activePG - 1); 
	craftPG[2].text = (activePG + 1) + ">"; craftPG[1].text = activePG + "/" + maxPage;
	for (i = 0; i < 3; i++) {
		for (ii = 0; ii < craftCase [i].length; ii++)
			if (craftCase [collumnShow] [ii].green == 0 || craftCase [collumnShow] [4].green == 0)
				{craftFrame.red = 1; craftFrame.green = 0; craftFrame.blue = 0;}
		for (ii = 0; ii < 5; ii++) {
			craftCase [i] [ii].x = width/2 - 61 + i*70 - ui.getStringWidth(craftCase [i] [ii].text)/2; 
			craftCase [i] [ii].alpha = 0.5;
			if (ii == 4) craftCase [i] [ii].x += 6;
		}
	}

	if ((collumnShow < 2 || activePG < maxPage) && isKeyActive(32, 5)) {collumnShow += 1; script.runScript(scriptRun);}
	if ((collumnShow > 0 || activePG > 1) && isKeyActive(30, 5)) {collumnShow -= 1; script.runScript(scriptRun);}
	if (activePG < maxPage && isKeyActive(31, 5)) {activePG += 1; script.runScript(scriptRun); readItems();}
	if (activePG > 1 && isKeyActive(17, 5)) {activePG -= 1; script.runScript(scriptRun); readItems();}
	craftPG[2].alpha = (activePG == maxPage) ? 0 : 1; craftPG[0].alpha = (activePG == 1) ? 0 : 1;
	
	if (collumnShow > 2) {collumnShow -= 3; activePG += 1; script.runScript(scriptRun); readItems();}
	if (collumnShow < 0) {collumnShow += 3; activePG -= 1; script.runScript(scriptRun); readItems();}
	pageShow.texture = "customCrafting/" + ((recipe_over) ? "cookPage" : "craftPage") +activePG+".png"; 
	craftItemPNG.x = width/2 - 8 - ui.getStringWidth(craftItem.text)/2;
} else if (craftFrame.alpha != 0) {
	craftFrame.alpha = 0; pageShow.alpha = 0; helpCraft.alpha = 0; craftItem.text = ""; craftItemPNG.alpha = 0;
	mainPageShow.alpha = 0; for (i = 0; i < 3; i++) {craftPG[i].alpha = 0; for (ii = 0; ii < 5; ii++) craftCase [i] [ii].alpha = 0;}
}
// GRENADE, NET, ARROW//
script.runScript("u_grenade.js"); script.runScript("u_net.js"); script.runScript("u_arrow.js");
// BOOK ENGINE //
script.runScript("u_books.js"); script.runScript("u_crafting.js");
// UPGRADE BOARD //
if (build_over == true) {helpBuild.alpha = (help) ? 1 : 0;
if (keyboard.isKeyDown(57)) {build_over = false; effect.clearOverlay(); script.runScript("customBuilding.js"); get_items();}
if (effect.getOverlay() != null) {player.setStunned(1);}
if (keyboard.isKeyDown(1) || keyboard.isKeyDown(18)) {build_over = false; effect.clearOverlay();}
if (buildMainPage.alpha == 0) {script.runScript("customBuilding.js"); readItems();}
buildMainPage.alpha = 1; buildCase.alpha = 1; buildCase.x = width/2 - 129 + buildShow*35.5
buildHouse.alpha = 1; for (i = 0; i < 4; i++) {buildNeed [i].alpha = 1;}
buildHouse.texture = buildCurrent; 
if (buildShow < 5 && isKeyActive(32, 5)) {buildShow += 1; script.runScript("customBuilding.js"); readItems();}
if (buildShow > 1 && isKeyActive(30, 5)) {buildShow -= 1; script.runScript("customBuilding.js"); readItems();}}
else {buildMainPage.alpha = 0; buildCase.alpha = 0; helpBuild.alpha = 0;
buildHouse.alpha = 0; for (i = 0; i < 4; i++) {buildNeed [i].alpha = 0;}}
// SHOP //
script.runScript("u_shop.js");
// CLOCK //
if (pinv.getSlotContainingItem(2056) != -1) {
	clockLabel.alpha = 1; clockAmount.alpha = 1;
	hours = Math.floor(time.time/1000+8); if (hours < 10) {hours = "0" + hours;}
	minutes = Math.round(time.time%1000/1000*60); if (minutes < 10) {minutes = "0" + minutes;}
	clockAmount.text = hours + ":" + minutes;
} else {clockLabel.alpha = 0; clockAmount.alpha = 0;}
// POISON //
if (poison > 0) {poison -= 0.05; hb2.texture = "gui/poisonbar.png"; if (godMode != true) {pHealth -= 0.01*poisonP;}} 
else {hb2.texture = "gui/healthbar.png";}
// ACTIVE SET //
vec = player.getLookVec(); pos = player.getPosition(); maxdist = 4;
target = player.lookVec.scale(maxdist).add(pos); getBlock = player.rayTrace(pos, target) [1];
if (getBlock == null || hitBlock == null || hitBlock.x != getBlock.x || hitBlock.y != getBlock.y || hitBlock.z != getBlock.z) 
	{blockx = blocky = blockz = blockHP = blockMaxHP = 0;} 

if (getBlock != null && getBlock != undefined) {
	lookBlockID = world.getBlockID(getBlock.x, getBlock.y, getBlock.z);
	lookBlockMD = world.getMetadata(getBlock.x, getBlock.y, getBlock.z);

	for (i = 0; fireArray [i] != undefined; i++)
	if (fireArray [i] != undefined && fireArray [i] [1] [0] == getBlock.x && 
	fireArray [i] [1] [1] == getBlock.y && fireArray [i] [1] [2] == getBlock.z) {
		actArray [3] = i; firepower = fireArray [i] [4]; fireburn = fireArray [i] [6]; 
		fireHP = fireArray [i] [2]; fireMaxHP = fireArray [i] [3]; break;
	} else {fireHP = 0; fireMaxHP = 0; firepower = 0;}
	
	for (i = 0; superGarden [i] != undefined; i++)
	if (superGarden [i] != undefined && superGarden [i] [1] [0] == getBlock.x && 
	superGarden [i] [1] [1]-1 == getBlock.y && superGarden [i] [1] [2] == getBlock.z) {
		actArray [3] = i; blockName = superGarden [i] [7];
		sunpower = superGarden [i] [3]; waterpower = superGarden [i] [2]; break;
	} else {sunpower = 0; waterpower = 0; if (gardenLabel.alpha != 0) {blockHP = 0; blockMaxHP = 0;}} 
	actD = actArray [3];
	
	//if (hitBlock != null && gardenLabel.alpha == 0 && (hitBlock.x != getBlock.x || hitBlock.y != getBlock.y || hitBlock.z != getBlock.z))
	//	{blockHP = 0; blockMaxHP = 0; blockx = 0; bloxky = 0; blockz = 0; sunpower = 0; waterpower = 0; hb5.alpha = 0;}
} else {
	fireHP = 0; fireMaxHP = 0; firepower = 0; sunpower = 0; waterpower = 0;
	blockHP = 0; blockMaxHP = 0; blockx = 0; bloxky = 0; blockz = 0;
} repairSource();

/* FIREPOWER ENGINE */ 	script.runScript("u_firepower.js");
/* GARDENING ENGINE */	script.runScript("u_flowerGrow.js"); script.runScript("u_cactus.js");
/* TORCH ENGINE */ 		script.runScript("u_torch.js"); script.runScript("u_achievements.js");

if (blockHP > 0) {hb4.width = blockHP/blockMaxHP*174; hb3.alpha = 1; hb4.alpha = 1; blockLabel.text = blockName;}
else {hb3.alpha = 0; hb4.alpha = 0; blockLabel.text = "";}
if (firepower > 0 || fireHP > 0) {fp.alpha = 1; firepowerLabel.text = firepower;}
else {firepowerLabel.text = ""; fp.alpha = 0;}
if (fireHP > 0) {fp2.width = fireHP/fireMaxHP*180 + 20; fireItem.alpha = fp2.alpha = 1; fireburnLabel.text = fireburn;}
else {fireMaxHP = 0; fp2.alpha = 0; fireburnLabel.text = ""; fireItem.alpha = 0;}
//ANTI CHEATING ENGINE//
if (godMode != true) {
	if (cheated == 0 && (pinv.getCursorItem() != null && pinv.getCursorItem().quantity < 0) ||
	(keyboard.isKeyDown(20) && debugMode == true)) 
		{cheated = 1; chat.print("CHEATED"); world.triggerBlock(203, 35, -180);}
	if (wasKeyPressed(62)) {debugMode = !debugMode;}
}
if (godMode == true && cheated == 1) {cheated = 0; chat.print("Sorry sir"); world.triggerBlock(203, 34, -180);}
cheatingSign.alpha = cheated;
// SAVE ARRAYS //
saveArrays();
// H_BUTTON //
if (wasKeyPressed(35)) {chat.print((help) ? "HELP disabled" : "HELP enabled"); help = (!help);}
// WAITING //
if (timeWaited != 1) {timeWaited = 1;}
if (waitingTime == 0) {
	if (keyboard.isKeyDown(20)) {
		waitingValue = Math.min(waitingValue + 0.4 + waitingValue/350, 165); 
		player.setStunned(1); sleepLabelB.alpha = Math.min(waitingValue/10, 1); sleepAmount.alpha = 0;
		if (waitingValue >= 5 && waitingValue < 13) 
			{sleepAmount.alpha = Math.min(waitingValue/10, 1); sleepAmount.text = "Wait?";}
		if (waitingValue >= 13 && waitingValue < 17) {sleepAmount.alpha = 1; sleepAmount.text = "3";} 
		if (waitingValue >= 17 && waitingValue < 21) {sleepAmount.alpha = 1; sleepAmount.text = "2";}
		if (waitingValue >= 21 && waitingValue < 25) {sleepAmount.alpha = 1; sleepAmount.text = "1";}
		if (waitingValue >= 25) {
			sleepAmount.alpha = 1;
			hours = Math.floor((waitingValue-25)*100/1000); if (hours < 10) {hours = "0" + hours;}
			minutes = Math.round((waitingValue-25)*100%1000/1000*60); 
			if (waitingValue <= 55) 		{minutes -= minutes%10;}
			else if (waitingValue <= 85) 	{minutes -= minutes%20;}
			else if (waitingValue <= 115)	{minutes -= minutes%30;}
			else {minutes = 0;} if (minutes == 0) {minutes = "00";}
			sleepAmount.text = hours + ":" + minutes;
		}
	} else { 
		if (waitingValue >= 25) {sleeping = -1; waitingTime = (waitingValue - 25)*100; waitingValue = 0; startTime = gameTiming;}
		else {waitingValue = 0; sleepLabelB.alpha = 0; sleepAmount.alpha = 0;}
	}
} else if (sleeping < 0) {
	player.setStunned(1); sleepAmount.alpha = 1;
	hours = Math.floor(waitingTime/1000); if (hours < 10) {hours = "0" + hours;}
	minutes = Math.round(waitingTime%1000/1000*60); if (minutes < 10) {minutes = "0" + minutes;}
	sleepAmount.text = hours + ":" + minutes; ii = gameTiming - startTime;
	if (sleeping == -1) {
		if (keyboard.isKeyDown(20)) {waitingTime -= 200;}
		time.setTime(time.getTime() + 20); gameTiming += 20; waitingTime -= 20;
		if (ii/(ii+waitingTime)*100 < 30) {
			j = ii/(ii+waitingTime)*2; sleepEffect.height = j*height; 
			sleepEffect.alpha = j*2; sleepEffect2.y = height-j*height; sleepEffect2.height = j*height; sleepEffect2.alpha = j*2;
		} else if (ii/(ii+waitingTime)*100 >= 80) {
			j = Math.pow(ii/(ii+waitingTime),3); sleepEffect.height = height-j*height; 
			sleepEffect.alpha = 2-j*2; sleepEffect2.y = j*height; 
			sleepEffect2.height = height-j*height; sleepEffect2.alpha = 2-j*2;
		} 
		if (ii/(ii+waitingTime)*100 >= 99) {
			sleeping = 0.1; effect.clearOverlay(); waitingTime = 0; timeWaited = ii;
			dailyEnergy = Math.min(dailyEnergy + timeWaited/200*((slept == 1) ? (2+houseUP) : 1), 100);
			energy = Math.min(energy + timeWaited/200*((slept == 1) ? (7+houseUP*1.5) : 5)*maxEnergy/100, maxEnergy);
			hunger = Math.min(hunger + timeWaited/200/2, 100); slept = 0;			
		}
	}
}
// HOLDING A TORCH //
function torchLight() {
	for (i = -2; i <= 2; i++) for (ii = -2; ii <= 2; ii++) for (j = -2; j <= 2; j++) 
	if (world.getBlockID(pos.x+i, pos.y+1+ii, pos.z+j) == 171) {world.setBlockID(pos.x+i, pos.y+1+ii, pos.z+j, 0);}
	if (pinv.getOffhandItem() != null && pinv.getOffhandItem().itemID == 2099) {
		if (Math.random()*10 > 9) {pinv.getOffhandItem().damage += 1;}
		if (pinv.getOffhandItem().damage >= pinv.getOffhandItem().maxDamage) {pinv.consumeItem(2099);} pos.z -= 1; 
		if (world.getBlockID(pos.x, pos.y, pos.z) == 0) {world.setBlockIDAndMetadata(pos.x, pos.y, pos.z, 171, 14);}
	}
	if (pinv.getCurrentItem() != null && pinv.getCurrentItem().itemID == 2099) {
		if (Math.random()*10 > 9) {pinv.getCurrentItem().damage += 1;} 
		if (pinv.getCurrentItem().damage >= pinv.getCurrentItem().maxDamage) {pinv.consumeItem(2099);} pos.z -= 1;
		if (world.getBlockID(pos.x, pos.y, pos.z) == 0) {world.setBlockIDAndMetadata(pos.x, pos.y, pos.z, 171, 14);} pos.z += 1;
	}
}

if (Math.round(posChk.x) != Math.round(pos.x) || Math.round(posChk.y) != Math.round(pos.y) 
|| Math.round(posChk.z) != Math.round(pos.z)) {posChk = player.getPosition(); torchLight();}
// THROW METER //
if (throwingValue > 0) {
	if (throwingLabel.alpha < 1)
		{throwingItem.alpha = throwingLabelHP.alpha = throwingLabel.alpha = Math.min(throwingLabel.alpha + 0.1, 1);}
	throwingLabelHP.width = throwingValue*112 + 18;
	throwingItem.u = 16*prices[throwingID] [0] [3];
	throwingItem.v = 16*prices[throwingID] [0] [4];
} else if (throwingLabel.alpha > 0)
	{throwingItem.alpha = throwingLabelHP.alpha = throwingLabel.alpha = Math.max(throwingLabel.alpha - 0.1, 0);}
// CUSTOM HAND //
if (handfull == 1) {
	itemSearch = player.getEntitiesWithinRange(0.5); 
	for (var ii = 0; ii < itemSearch.length; ii++) {
		var ent1 = itemSearch[ii];
		if (ent1.getClassType() == "Item" && pinv.getCurrentItem() == null && itemize2 == 1) {ent1.setDead(); itemize2 = 0;}
		if (itemize == 1 && pinv.getCursorItem() == null) {itemize = 0; ent1.setDead();}
	}
	if (pinv.getSlotContainingItem(459) != -1) {pinv.consumeItem(459);}
	if (pinv.getCurrentItem() == null) {
		while (pinv.getSlotContainingItem(468) != -1) {pinv.consumeItemAmount(468, 0, 1);}
		for (i = 0; pinv.getCurrentItem() == null; i++) {pinv.addItem(Item(468, 64));}
		for (i = i - 1; i > 0; i--) {pinv.consumeItemAmount(468, 0, 64);} pinv.getCurrentItem().quantity = 1;
	}
	if (pinv.getCurrentItem() != null && pinv.getCurrentItem().itemID == 468) 
		{itemize2 = Math.min(itemize2 + 1, 1);} else {itemize2 = -3;}
	if (pinv.getCursorItem() != null && pinv.getCursorItem().itemID == 468) 
		{pinv.setCursorItem(Item(459)); itemize = 1;} else {itemize = 0;}
}
// ITEM CONSUME //
if (itemUsed == true) {j = lastItemUsed.itemID; k = (lastItemUsed.maxDamage != 0) ? 0 : lastItemUsed.damage;
	if (hitBlock != null && lastItemUsed.maxDamage == 0)
		for (i = 0; i < 8; i++) if (prices [j] [k] [i+7] != 0) {repairConsume(lastItemUsed, false); break;}

	if (prices [j] [k] [6] != undefined && prices [j] [k] [6] != 0) {
		energy -= energyGenerate * (prices [j] [k] [6] * power * 1.8 + 4)/Math.sqrt(mainSkill + skillVar [mS] [1]/4);
		if (energy < 0.5 && Math.random()*2 > 1.5) {
			j = pinv.getSlotContainingItemDamage(lastItemUsed.itemID, lastItemUsed.damage); 
			k = (j != -1) ? pinv.getItemInSlot(j) : Item(0); time.sleep(0.05);
			j = pinv.getSlotContainingItemDamage(lastItemUsed.itemID, lastItemUsed.damage); 
			ii = (j != -1) ? pinv.getItemInSlot(j) : Item(0); 
			if (k.quantity == ii.quantity) {
				if (Math.random()*2 > 1) {chat.print("I am so tired, I can't even hold it in my hands");} 
				else {chat.print("Press and hold 'T' to rest");}
				j = lastItemUsed.itemID; k = lastItemUsed.damage; player.dropItem(Item(j, 1, k)); pinv.consumeItemAmount(j, k, 1);
				itemSearch = player.getEntitiesWithinRange(0.5); vec = player.getLookVec();
				for (i = 0; i < itemSearch.length; i++) {
					ent1 = itemSearch[i]; 
					if (ent1.getClassType() == "Item") {
						ent1.setVelocity(vec.x/3 + (Math.random()*0.6 - 0.3), 
						vec.y/3 + (Math.random()*0.6 - 0.3), vec.z/3 + (Math.random()*0.6 - 0.3));
					}
				}
			}
		}
	}
	itemUsed = false;
}
// LEVELUP SELECTION //
if (LVLup == true) {
	player.setStunned(1); lvlLabel[0].alpha = lvlLabel[1].alpha = lvlLabel[2].alpha = 1;
	if (wasKeyPressed(57)) {LVLup = false;
		switch (lvlLabelActive) {
			case 0: maxEnergy += Math.floor(maxEnergy/10); break;
			case 1: maxBurden += Math.floor(maxBurden/10); break;
			case 2: player.maxHealth += Math.floor(player.maxHealth/10); break;
		}
	}
	if (isKeyActive(32, 8)) {lvlLabelActive += 1; lvlLabelDirection = +2;} 
	if (isKeyActive(30, 8)) {lvlLabelActive -= 1; lvlLabelDirection = -2;} 
	if (lvlLabelActive < 0) {lvlLabelActive = 2;}
	if (lvlLabelActive > 2) {lvlLabelActive = 0;}
	
	for (i = 0; i < lvlLabel.length; i++) {lvlLabel[i].width = 22.5; lvlLabel[i].height = 22.5; lvlLabel[i].v = 0*22.5;}
	if (Math.round(lvlLabelActive*10) != Math.round(lvlLabelRotate*10)) {lvlLabelRotate += lvlLabelDirection/10;}
	else {
		switch (lvlLabelActive) {
			case 0: lvlLabel[1].width = 45; lvlLabel[1].height = 45; lvlLabel[1].v = 1*22.5; break;
			case 1: lvlLabel[2].width = 45; lvlLabel[2].height = 45; lvlLabel[2].v = 1*22.5; break;
			case 2: lvlLabel[0].width = 45; lvlLabel[0].height = 45; lvlLabel[0].v = 1*22.5; break;
		}
	}
	if (Math.ceil(lvlLabelRotate) == -1) {lvlLabelRotate = 2;}
	if (Math.floor(lvlLabelRotate) == 3) {lvlLabelRotate = 0;}

	for (i = 0; i < lvlLabel.length; i++) {
		lvlLabel[i].x = width/2 - lvlLabel[i].width/2 + Math.sin((300 - 120*i + lvlLabelRotate*120)/180*Math.PI)*30; 
		lvlLabel[i].y = height/2 - lvlLabel[i].height/2 + Math.cos((300 - 120*i + lvlLabelRotate*120)/180*Math.PI)*30;
	}
} else {lvlLabel[0].alpha = lvlLabel[1].alpha = lvlLabel[2].alpha = 0;}
	
// BURDEN //
burden = 0;
for (i = 0; i < 40; i++) {
	if (pinv.getItemInSlot(i) != null) {
		ii = pinv.getItemInSlot(i);
		j = ii.itemID; k = ii.damage; if (ii.maxDamage != 0) {k = 0;}
		if (prices [j] != undefined && prices [j] [k] == undefined && prices [j] [0] != undefined) {k = 0;}
		if (prices [j] != undefined && prices [j] [k] != undefined 
			&& prices [j] [k] [6] != undefined && ii.quantity > 0) {
			burden += prices [j] [k] [6]*ii.quantity;
		}
	}
}
// ENTITY HIT CHECK //
//for (i = 0; entityHits [i] != undefined && ent != entityHits [i] [0]; i++) {}
//if (entityHits [i] != undefined && ent == entityHits [i] [0] && entityHits [i] [1] != ent.health)
//	{chat.print("hit"); entityHits [i] [1] = ent.health;}
// CUSTOM MESSAGING //
script.runScript("u_message.js"); keyIDCheck = [];
for (i = 0; i < 84; i++) {
	if (keyboard.isKeyDown(i)) {keyIDCheck[keyIDCheck.length] = i;} 
	if (i == 83) {keyIDCheck[keyIDCheck.length] = 0;}
}