# By OmicroN

@name DeadMau5
@outputs Idx Hue Head
@persist [O E]:entity

if( dupefinished() ){ reset() }

if(first())
{    
    runOnTick(1)
    runOnLast(1)
    runOnChat(1)
    E = entity():isWeldedTo() ?: entity()
    O = owner()
    
    function number getID(N)
    {
        Idx+=N
        return Idx
    }
    
    Angle = ang(135-10.75,0,0)
    
    # Outter Outline
    holoCreate(getID(1),E:toWorld(vec(0,0,20)),vec()-22.5/12,E:toWorld(ang()),vec())
    holoModel(getID(0),"hq_sphere")
    Head = getID(0)
    
    # Inner Mouth
    holoCreate(getID(1),E:toWorld(vec(0,0,20)),vec()+20/12,E:toWorld(ang()),vec()+255)
    holoModel(getID(0),"hq_sphere")
    holoParent(getID(0),Head)
    
    # Top Head
    holoCreate(getID(1),E:toWorld(vec(0,0,20)),vec()+22/12,E:toWorld(ang(-11.25,0,0)),vec(255,0,0))
    holoModel(getID(0),"dome2")
    holoParent(getID(0),Head)
    
    # Bottom Head
    holoCreate(getID(1),E:toWorld(vec(0,0,20)),vec()+22/12,E:toWorld(ang(-135,0,0)),vec(255,0,0))
    holoModel(getID(0),"dome2")
    holoClipEnabled(getID(0),1)
    holoClip(getID(0),vec(),vec(0,0,-1):rotate(Angle),0)
    holoParent(getID(0),Head)
    
    # Left Eye
    holoCreate(getID(1),E:toWorld(vec(6,6,25)),vec()+7/12,E:toWorld(ang()),vec()+255)
    holoModel(getID(0),"hq_sphere")
    holoParent(getID(0),Head)
    
    # Right Eye
    holoCreate(getID(1),E:toWorld(vec(6,-6,25)),vec()+7/12,E:toWorld(ang()),vec()+255)
    holoModel(getID(0),"hq_sphere")
    holoParent(getID(0),Head)
    
    # Left Ear Outline
    holoCreate(getID(1),E:toWorld(vec(0,13,33)),-(vec(22,22,12)+1/2)/12,toWorldAng(vec(),ang(180,0,0),vec(),E:toWorld(ang(-90+11.25/2,0,0))),vec())
    holoModel(getID(0),"dome")
    holoParent(getID(0),Head)
    
    # Left Ear
    holoCreate(getID(1),E:toWorld(vec(0,13,33)),vec(22,22,12)/12,E:toWorld(ang(-90+11.25/2,0,0)),vec(255,0,0))
    holoModel(getID(0),"dome")
    holoParent(getID(0),Head)
    
    # Right Ear Outline
    holoCreate(getID(1),E:toWorld(vec(0,-13,33)),-(vec(22,22,12)+1/2)/12,toWorldAng(vec(),ang(180,0,0),vec(),E:toWorld(ang(-90+11.25/2,0,0))),vec())
    holoModel(getID(0),"dome")
    holoParent(getID(0),Head)
    
    # Right Ear
    holoCreate(getID(1),E:toWorld(vec(0,-13,33)),vec(22,22,12)/12,E:toWorld(ang(-90+11.25/2,0,0)),vec(255,0,0))
    holoModel(getID(0),"dome")
    holoParent(getID(0),Head)
    
    Pos = O:attachmentPos("eyes")
    Ang = O:attachmentAng("eyes")
    holoPos(Head,Pos+Ang:up()*4-Ang:forward()*5)
    holoAng(Head,Ang)
    holoParentAttachment(Head,O,"eyes")
    
    for(I=1,Idx)
    {
        holoDisableShading(I,1)
        holoVisible(I,players(),1)
        holoVisible(I,O,0)
    }
}

Hue = Hue%360+2

for(I=1,Idx)
{
    H = holoEntity(I)
    if( H:getColor()!=vec() & H:getColor()!=vec()+255 )
    {
        holoColor(I,hsv2rgb(Hue,1,1))
    }
}
