@name ai_artefactum
@model models/hunter/blocks/cube025x025x025.mdl
@persist [E]:entity
@persist [DoPos Pos VEC Col_]:vector
@persist Spd_ Scl_ Byt_ Ele_
@persist Move
@persist I Mode 

if(first())
{
    runOnTick(1)

    hint("Designed by [AI]Ubi",5)
    hint("Please save copyright <:3",4)
    
    E = entity()
    
    E:setAlpha(0)
    E:setMass(100)
    
    Spd_  = 25    #Speed divider
    Scl_  = 0.334 #Scale factor 0.1 min 0.334 max
    Byt_  = 255/3 #Dont touch :D
    
    function vector r_color()
    {
        R = randint(2)
        Color = vec(randint(0,1),randint(0,1),randint(0,1))
        
        if(!R){Color = shiftL(Color)}
        elseif(R == 1){Color = shiftR(Color)}
        
        if(!Color || Color == vec(1)){r_color() return vec()}       
        else{return Color}
    }
    
    function number r_elemt()
    {
        Elem_ = randint(1,27)
        
        if(Elem_ == 14){r_elemt()}
        else{return Elem_}
    }    

    Col_ = r_color()
    Ele_ = r_elemt()
    
    function create_cube()
    {
        local Add = 0
        
        for(X = 1,3)   
        {            
            for(Y = 1,3)
            {
                for(Z = 1,3)
                {       
                    I++  
                    if(I != Elem_ && I != 14)
                    {        
                        Add++      
                              
                        VEC = round(vec(X,Y,Z)*4-vec(8))
                        holoCreate(Add,E:toWorld(VEC),vec(clamp(Scl_,0.1,0.334)))
                        holoColor(Add,vec(X,Y,Z)*Col_*Byt_)
                        holoParent(Add,E)
                    }
                    if(I == Elem_){Pos = round(vec(X,Y,Z)*5-vec(10))/5}
                }
            }            
        }
    }
        
    function swap_holo()
    {        
        if(!Move)
        {            
            I = (I%26)+1
            
            Position = round(E:toLocal(holoEntity(I):pos())/4)
            Math = positive(Position-Pos)
            
            if(Math:x() != 2 && Math:y() != 2 && Math:z() != 2)
            {        
                TZ = (Position:x() == Pos:x()) && (Position:y() == Pos:y())
                TY = (Position:x() == Pos:x()) && (Position:z() == Pos:z()) 
                TX = (Position:z() == Pos:z()) && (Position:y() == Pos:y()) 
                
                if(TX || TY || TZ)
                {                       
                    DoPos = Pos
                    Pos = Position
                    VEC = Pos
                    Move = 1                              
                }    
            }            
        }
        else
        {      
            VEC += round(DoPos-Pos)/clamp(Spd_,2,32)
            holoPos(I,E:toWorld(VEC*4))
            if(DoPos == VEC){Move = 0}
        }              
    }
    
    create_cube()
}
swap_holo()
