//----Fire, Ice, Light Arrows v1.1 - Renounce4----//

FireArrows = new Array()
IceArrows = new Array()
LightArrows = new Array()
FrozenEntities = new Array()

Arrowsupdate = function() {
	for(e = 0;e < FireArrows.length;e++) {
		for(a = 0;a < 4;a++) {
			effect.spawnParticle("reddust",FireArrows[e].position.x+(Math.random()-.5)/3,FireArrows[e].position.y+(Math.random()-.5)/3,FireArrows[e].position.z+(Math.random()-.5)/3,1,Math.random()-.3,-1)
		}
		if(FireArrows[e].inBlockID != 0) {
			ArrowImpact(FireArrows[e],1,e)
		}
		else if(player.rayTrace(FireArrows[e].position.x,FireArrows[e].position.y,FireArrows[e].position.z,FireArrows[e].position.x+FireArrows[e].velocity.x,FireArrows[e].position.y+FireArrows[e].velocity.y,FireArrows[e].position.z+FireArrows[e].velocity.z)[2] != null) {
			ArrowImpact(FireArrows[e],1,e)
		}
		else if(!FireArrows[e].isAlive()) {
			ArrowImpact(FireArrows[e],1,e)
		}
	}
	for(e = 0;e < IceArrows.length;e++) {
		for(a = 0;a < 4;a++) {
			effect.spawnParticle("reddust",IceArrows[e].position.x+(Math.random()-.5)/3,IceArrows[e].position.y+(Math.random()-.5)/3,IceArrows[e].position.z+(Math.random()-.5)/3,-1,Math.random()+.1,1)
		}
		if(IceArrows[e].inBlockID != 0) {
			ArrowImpact(IceArrows[e],2,e)
		}
		else if(player.rayTrace(IceArrows[e].position.x,IceArrows[e].position.y,IceArrows[e].position.z,IceArrows[e].position.x+IceArrows[e].velocity.x,IceArrows[e].position.y+IceArrows[e].velocity.y,IceArrows[e].position.z+IceArrows[e].velocity.z)[2] != null) {
			ArrowImpact(IceArrows[e],2,e)
		}
		else if(!IceArrows[e].isAlive()) {
			ArrowImpact(IceArrows[e],2,e)
		}
	}
	for(e = 0;e < LightArrows.length;e++) {
		for(a = 0;a < 4;a++) {
			effect.spawnParticle("reddust",LightArrows[e].position.x+(Math.random()-.5)/3,LightArrows[e].position.y+(Math.random()-.5)/3,LightArrows[e].position.z+(Math.random()-.5)/3,1,1,0)
		}
		if(LightArrows[e].inBlockID != 0) {
			ArrowImpact(LightArrows[e],3,e)
		}
		else if(player.rayTrace(LightArrows[e].position.x,LightArrows[e].position.y,LightArrows[e].position.z,LightArrows[e].position.x+LightArrows[e].velocity.x,LightArrows[e].position.y+LightArrows[e].velocity.y,LightArrows[e].position.z+LightArrows[e].velocity.z)[2] != null) {
			ArrowImpact(LightArrows[e],3,e)
		}
		else if(!LightArrows[e].isAlive()) {
			ArrowImpact(LightArrows[e],3,e)
		}
	}
}
ArrowImpact = function(arrow,type,a) {
	if(type == 1) {
		sound.playSound3D("sound.FireArrow_Hit",arrow.position.x,arrow.position.y,arrow.position.z)
		for(e = 0;e < 100*FireArrow_Range;e++) {
			effect.spawnParticle("reddust",arrow.position.x+(Math.random()-.5)*FireArrow_Range,arrow.position.y+(Math.random()-.5)*FireArrow_Range,arrow.position.z+(Math.random()-.5)*FireArrow_Range,1,Math.random()-.3,-1)
		}
		var Fents = arrow.getEntitiesWithinRange(FireArrow_Range)
		for(e = 0;e < Fents.length;e++) {
			if(Fents[e].getClassType() != "NPC" && Fents[e].getClassType() != "Player" && Fents[e].getClassType() != "Arrow" && Fents[e].getClassType() != "Painting" && Fents[e].getClassType() != "FallingSand" && Fents[e].getClassType() != "Minecart" && Fents[e].getClassType() != "Boat" && Fents[e].getClassType() != "Item") {
				Fents[e].attackEntityFrom(arrow,FireArrow_Damage)
				Fents[e].setFireLevel(FireArrow_BurnTime)
			}
		}
		if(FireArrow_MeltIce) {
			MeltIce(Math.floor(arrow.position.x),Math.floor(arrow.position.y),Math.floor(arrow.position.z),FireArrow_Range)
		}
		for(i = -Math.floor(FireArrow_Range/2);i <= Math.floor(FireArrow_Range/2);i++) {
			for(j = -Math.floor(FireArrow_Range/2);j <= Math.floor(FireArrow_Range/2);j++) {
				for(k = -Math.floor(FireArrow_Range/2);k <= Math.floor(FireArrow_Range/2);k++) {
					if(FireArrow_LightTorches && world.getBlockID(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 75) {
						world.setBlockID(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k,50)
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 1) {
							world.triggerBlock(Math.floor(arrow.position.x)+i-4,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 2) {
							world.triggerBlock(Math.floor(arrow.position.x)+i+4,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 3) {
							world.triggerBlock(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k-4)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 4) {
							world.triggerBlock(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k+4)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 5) {
							world.triggerBlock(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j-3,Math.floor(arrow.position.z)+k)
						}
					}
				}
			}
		}
		FireArrows.splice(a,1)
	}
	if(type == 2) {
		sound.playSound3D("sound.IceArrow_Hit",arrow.position.x,arrow.position.y,arrow.position.z)
		for(e = 0;e < 100*IceArrow_Range;e++) {
			effect.spawnParticle("reddust",arrow.position.x+(Math.random()-.5)*IceArrow_Range,arrow.position.y+(Math.random()-.5)*IceArrow_Range,arrow.position.z+(Math.random()-.5)*IceArrow_Range,-1,Math.random()+.1,1)
		}
		var Ients = arrow.getEntitiesWithinRange(IceArrow_Range)
		for(e = 0;e < Ients.length;e++) {
			if(Ients[e].getClassType() != "NPC" && Ients[e].getClassType() != "Player" && Ients[e].getClassType() != "Arrow" && Ients[e].getClassType() != "Painting" && Ients[e].getClassType() != "FallingSand" && Ients[e].getClassType() != "Minecart" && Ients[e].getClassType() != "Boat" && Ients[e].getClassType() != "Item") {
				Ients[e].attackEntityFrom(arrow,IceArrow_Damage)
				Ients[e].setStunned(IceArrow_FreezeTime)
				FrozenEntities.splice(FrozenEntities.length-1,0,Ients[e])
			}
		}
		if(IceArrow_MakeIce) {
			MakeIce(Math.floor(arrow.position.x),Math.floor(arrow.position.y),Math.floor(arrow.position.z),IceArrow_Range)
		}
		for(i = -Math.floor(IceArrow_Range/2);i <= Math.floor(IceArrow_Range/2);i++) {
			for(j = -Math.floor(IceArrow_Range/2);j <= Math.floor(IceArrow_Range/2);j++) {
				for(k = -Math.floor(IceArrow_Range/2);k <= Math.floor(IceArrow_Range/2);k++) {
					if(IceArrow_BlowoutTorches && world.getBlockID(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 50) {
						world.setBlockID(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k,75)
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 1) {
							world.triggerBlock(Math.floor(arrow.position.x)+i-5,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 2) {
							world.triggerBlock(Math.floor(arrow.position.x)+i+5,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 3) {
							world.triggerBlock(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k-5)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 4) {
							world.triggerBlock(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k+5)
						}
						if(world.getMetadata(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j,Math.floor(arrow.position.z)+k) == 5) {
							world.triggerBlock(Math.floor(arrow.position.x)+i,Math.floor(arrow.position.y)+j-4,Math.floor(arrow.position.z)+k)
						}
					}
				}
			}
		}
		IceArrows.splice(a,1)
	}
	if(type == 3) {
		sound.playSound3D("sound.LightArrow_Hit",arrow.position.x,arrow.position.y,arrow.position.z)
		for(e = 0;e < 100*LightArrow_Range;e++) {
			effect.spawnParticle("reddust",arrow.position.x+(Math.random()-.5)*LightArrow_Range,arrow.position.y+(Math.random()-.5)*LightArrow_Range,arrow.position.z+(Math.random()-.5)*LightArrow_Range,1,1,0)
		}
		var Lents = arrow.getEntitiesWithinRange(LightArrow_Range)
		for(e = 0;e < Lents.length;e++) {
			if(Lents[e].getClassType() != "NPC" && Lents[e].getClassType() != "Player" && Lents[e].getClassType() != "Arrow" && Lents[e].getClassType() != "Painting" && Lents[e].getClassType() != "FallingSand" && Lents[e].getClassType() != "Minecart" && Lents[e].getClassType() != "Boat" && Lents[e].getClassType() != "Item") {
				Lents[e].attackEntityFrom(arrow,LightArrow_Damage)
			}
		}
		LightArrows.splice(a,1)
	}
}
FrozenEntitiesupdate = function() {
	for(e = 0;e < FrozenEntities.length;e++) {
		if(FrozenEntities[e].getHurtTime() > 0) {
			FrozenEntities[e].setHurtTime(0)
		}
		if(Math.random() <= .5) {
			var px = FrozenEntities[e].getPosition().x+((Math.random()*.5)-.25)
			var py = FrozenEntities[e].getPosition().y+((Math.random()*.5)-.25)
			var pz = FrozenEntities[e].getPosition().z+((Math.random()*.5)-.25)
			for(i = 0;i < 10;i++) {
				effect.spawnParticle("snowballpoof",px,py,pz,0,0,0)
			}
		}
		if(FrozenEntities[e].getStunned() == 0) {
			FrozenEntities.splice(e,1)
		}
	}
}
MakeIce = function(x,y,z,range) {
	range--
	if(world.getBlockID(x,y,z) == 8 || world.getBlockID(x,y,z) == 9) {
		if(world.getMetadata(x,y,z) == 0) {
			world.setBlockIDAndMetadata(x,y,z,79,1)
		}
	}
	if(range > 0) {
		MakeIce(x+1,y,z,range)
		MakeIce(x-1,y,z,range)
		MakeIce(x,y+1,z,range)
		MakeIce(x,y-1,z,range)
		MakeIce(x,y,z+1,range)
		MakeIce(x,y,z-1,range)
	}
}
MeltIce = function(x,y,z,range) {
	range--
	if(world.getBlockID(x,y,z) == 79) {
		if(world.getMetadata(x,y,z) == 1) {
			world.setBlockID(x,y,z,8)
		}
		else {
			world.setBlockID(x,y,z,0)
		}
	}
	if(range > 0) {
		MeltIce(x+1,y,z,range)
		MeltIce(x-1,y,z,range)
		MeltIce(x,y+1,z,range)
		MeltIce(x,y-1,z,range)
		MeltIce(x,y,z+1,range)
		MeltIce(x,y,z-1,range)
	}
}