################
# > Minecraft Player: A Minecraft player that will follow the nearest person.
# > How to use: Spawn it and let the Minecraft player run after people.
################

@name Minecraft Player
@persist Scale Speed Body:entity
@persist Ranger:ranger Floor Clip Gravity
@persist I A Players:array NearestPly:entity

interval(10)

if (first()|duped()){
    TorsoColour=vec(120,120,255) # 120,120,255
    LegsColour=vec(50,50,255) # 50,50,255
    HairColour=vec(25,25,25) # 25,25,25
    EyesColour=vec(0,0,255) # 0,0,255
    SkinColour=vec(179,148,147) # 179,148,147
    FeetColour=vec(75,54,33) # 75,54,33
    Scale=1
    Speed=Scale
    
    #Body
    holoCreate(1)
    holoScale(1,vec(0.6,1.5,1.8)*Scale)
    holoPos(1,entity():pos()+vec(0,0,36)*Scale)
    holoAng(1,ang(0,-90,0))
    holoColor(1,TorsoColour)
    Body=holoEntity(1)
    
    #Legs
    holoCreate(2)
    holoScale(2,vec(0.75,0.6,1.75)*Scale)
    holoPos(2,entity():pos()+vec(4.5,0,15)*Scale)
    holoColor(2,LegsColour)
    holoCreate(3)
    holoScale(3,vec(0.75,0.6,1.75)*Scale)
    holoPos(3,entity():pos()+vec(-4.5,0,15)*Scale)
    holoColor(3,LegsColour)
    
    #Leg Hinges
    holoCreate(20)
    holoScale(20,vec(0.75,0.6,0.1)*Scale)
    holoPos(20,entity():pos()+vec(4.5,0,25)*Scale)
    holoAlpha(20,0)
    holoCreate(21)
    holoScale(21,vec(0.75,0.6,0.1)*Scale)
    holoPos(21,entity():pos()+vec(-4.5,0,25)*Scale)
    holoAlpha(21,0)
    
    #Arms
    holoCreate(4)
    holoScale(4,vec(0.55,0.55,1.8)*Scale)
    holoPos(4,entity():pos()+vec(12.5,0,35)*Scale)
    holoColor(4,SkinColour)
    holoCreate(5)
    holoScale(5,vec(0.55,0.55,1.8)*Scale)
    holoPos(5,entity():pos()+vec(-12.5,0,35)*Scale)
    holoColor(5,SkinColour)
    
    #Sleeve
    holoCreate(6)
    holoScale(6,vec(0.6,0.6,0.8)*Scale)
    holoPos(6,entity():pos()+vec(12.5,0,42)*Scale)
    holoColor(6,TorsoColour)
    holoCreate(7)
    holoScale(7,vec(0.6,0.6,0.8)*Scale)
    holoPos(7,entity():pos()+vec(-12.5,0,42)*Scale)
    holoColor(7,TorsoColour)
    
    #Feet
    holoCreate(8)
    holoScale(8,vec(0.75,0.6,0.5)*Scale)
    holoPos(8,entity():pos()+vec(4.5,0,2)*Scale)
    holoColor(8,FeetColour)
    holoCreate(9)
    holoScale(9,vec(0.75,0.6,0.5)*Scale)
    holoPos(9,entity():pos()+vec(-4.5,0,2)*Scale)
    holoColor(9,FeetColour)
    
    #Head
    holoCreate(10)
    holoScale(10,vec(1.2,1.2,1.2)*Scale)
    holoPos(10,entity():pos()+vec(0,0,53.5)*Scale)
    holoColor(10,vec(179,148,147))
    
    #Hair
    holoCreate(11)
    holoScale(11,vec(1.25,1.25,0.5)*Scale)
    holoPos(11,entity():pos()+vec(0,0,58.5)*Scale)
    holoColor(11,HairColour)
    holoCreate(12)
    holoScale(12,vec(1.25,0.4,1)*Scale)
    holoPos(12,entity():pos()+vec(0,5.2,55.5)*Scale)
    holoColor(12,HairColour)
    holoCreate(13)
    holoScale(13,vec(0.2,0.2,0.2)*Scale)
    holoPos(13,entity():pos()+vec(6.1,-6.2,54.4)*Scale)
    holoColor(13,HairColour)
    holoCreate(14)
    holoScale(14,vec(0.2,0.2,0.2)*Scale)
    holoPos(14,entity():pos()+vec(-6.1,-6.2,54.4)*Scale)
    holoColor(14,HairColour)
    
    #Eyes
    holoCreate(15)
    holoScale(15,vec(0.15,0.15,0.15)*Scale)
    holoPos(15,entity():pos()+vec(2,-6.5,52.4)*Scale)
    holoColor(15,EyesColour)
    holoCreate(16)
    holoScale(16,vec(0.15,0.15,0.15)*Scale)
    holoPos(16,entity():pos()+vec(-2,-6.5,52.4)*Scale)
    holoColor(16,EyesColour)
    holoCreate(17)
    holoScale(17,vec(0.15,0.15,0.15)*Scale)
    holoPos(17,entity():pos()+vec(3.6,-6.5,52.4)*Scale)
    holoColor(17,vec(170,170,170))
    holoCreate(18)
    holoScale(18,vec(0.15,0.15,0.15)*Scale)
    holoPos(18,entity():pos()+vec(-3.6,-6.5,52.4)*Scale)
    holoColor(18,vec(170,170,170))
    
    #Mouth
    holoCreate(19)
    holoScale(19,vec(0.6,0.15,0.15)*Scale)
    holoPos(19,entity():pos()+vec(0,-6.5,48.4)*Scale)
    holoColor(19,vec(25,25,25))
    
    holoParent(2,holoEntity(20))
    holoParent(3,holoEntity(21))
    holoParent(20,Body)
    holoParent(21,Body)
    holoParent(4,holoEntity(6))
    holoParent(5,holoEntity(7))
    holoParent(6,Body)
    holoParent(7,Body)
    holoParent(8,holoEntity(2))
    holoParent(9,holoEntity(3))
    holoParent(10,Body)
    for (I=11,19) {
        holoParent(I,holoEntity(10))
    }
}

findByClass("player*")
Players = findToArray()
NearestPly = findClosest(Body:pos())

if (Body:pos():distance(NearestPly:pos())>(Scale*100)){
    holoPos(1,Body:pos()+Body:forward()*Speed)
    holoAng(1,((NearestPly:pos()+vec(0,0,15*Scale)+vec(0,0,-(4*Scale)))-Body:pos()):toAngle())
    holoAng(1,ang(0,Body:angles():yaw(),0))
    holoPos(1,Body:pos()+Body:forward()*Speed)
    A+=6
}
else{
    A=90
}

holoAng(6,Body:angles()+ang(0,90,cos(A)*90))
holoAng(7,Body:angles()+ang(0,90,-cos(A)*90))
holoAng(20,Body:angles()+ang(0,90,-cos(A)*110))
holoAng(21,Body:angles()+ang(0,90,cos(A)*110))

Ranger = Body:ranger(-999999)
Floor = Ranger:distance()
Clip = (Scale*36)
Gravity = Scale*2

if (Floor>Clip&Floor<500000){
    if ((Floor-Clip)<Gravity) {
        holoPos(1,Body:pos()-(Floor-Clip))
    }
    else {
        holoPos(1,Body:pos()-vec(0,0,Gravity))
    }
}
elseif (Floor<Clip|Floor>=500000) {
    holoPos(1,Body:pos()+vec(0,0,Gravity))
}
