@name Minecraft
@inputs 
@outputs 
@persist Aim:vector Pos:vector Grid [Crate Crate2]:entity Holding:entity Hold A B C On Speed Water_level Di Spawn_grid  X Y Ready D Materials:array Block_set Cycle 
@persist Brick:array Ents:array Ents2:array ARRAY:array TABLE:table T
@trigger 
runOnTick(1)
findByModel("models/hunter/blocks/cube075x075x075.mdl")
if (first()) {
    Cycle = 1

    holoCreate(1,entity():pos())
    hint("Press E to cycle Down",100000)
hint("Press R to cycle UP",100000)
hint("Left to break, right to place",100000)

    holoModel(1,"square")
    holoAlpha(1,75)


    Grid = 35
    Aim = entity():pos()
    Pos = (round(Aim/Grid)*Grid+vec(0,0,Grid/2))

    A=0
    B=0
    C=0
    Water_level=0.2
    Di=150
    Hold=1
    It=owner()
    #0.001 easy
    #0.0025 normal
    #0.01 hard
    Speed=0.001    
    Ready=0
    O = owner()
    Spawn_grid=10
    X=0
    Y=0
    
    ARRAY = array("phoenix_storms/ps_grass","models/props/CS_militia/roofbeams02","sprops/textures/sprops_metal3","phoenix_storms/pack2/glass","models/props/de_inferno/infflrd","brick/brick_model","models/gibs/metalgibs/metal_gibs")
    TABLE = table(vec(1,255,1),vec(255,255,255),vec(255,255,255),vec(255,255,255),vec(255,255,255),vec(255,255,255),vec(255,255,255))
    holoPos(1,Pos)
    Crate=propSpawn("models/hunter/blocks/cube075x075x075.mdl",holoEntity(1):pos()+vec(0,0,20),1)
    Crate:setMaterial("phoenix_storms/cube")
    Crate2:setMaterial("models/props_wasteland/wood_fence01a")
    timer("spawn",300)
} #SINB*1*1 Should be 4 and 5
if(clk("spawn")&Y<Spawn_grid){
    Crate2=propSpawn("models/hunter/blocks/cube075x075x075.mdl",holoEntity(1):pos()+vec(X*Grid,Y*Grid,sin(B*0)*0),ang(90*randint(1,4),90*randint(1,4),90*randint(1,4)),1)  
   Crate2:setMaterial("phoenix_storms/ps_grass")

#models/vortigaunt/pupil
   Crate2:setColor(vec(1,255,1))
    B+=1
    X+=1

   if(X>Spawn_grid){X=0 Y+=1}
    if(Y<Spawn_grid){
        timer("spawn",30)
    }else{
    Ready=1
    holoAlpha(2,255)

    A1=findToArray()
    holoEntity(2):soundPlay(4,0,"/offspringfling.mp3")
    B=0

    }    
}

if(owner():aimEntity()&A<1&owner():aimEntity():model()=="models/hunter/blocks/cube075x075x075.mdl"&owner():aimPos():distance(owner():pos())<Di&owner():keyAttack1()){
    owner():soundPlay(1,1,"/items/ammopickup.wav")
    A=10

    owner():aimEntity():propDelete()   
}
if(A<1&Hold==1&owner()){
if(A<1&owner():aimEntity()&owner():aimPos():distance(owner():pos())<Di&owner():keyAttack2()){
    owner():soundPlay(1,1,"/items/ammocrate_open.wav")
    A=10
#HOLD SHOULD BE ZERO, CHANGED FOR FREEBUILD 
   Hold=1
    Crate2=propSpawn("models/hunter/blocks/cube075x075x075.mdl",holoEntity(1):pos()+vec(0,0,0),ang(90*randint(1,4),90*randint(1,4),90*randint(1,4)),1) 
      Crate2:setMaterial(ARRAY[T,string]) 
    Crate2:setColor(TABLE[T,vector])
}}

if(Ready){
Aim = owner():aimPos()
Pos = (round(Aim/Grid)*Grid+vec(0,0,Grid/2))
holoPos(1,Pos)
holoAng(1,(holoEntity(1):pos()-(owner():pos()+vec(0,0,70))):toAngle()+ang(-90,0,0))
if(A>0){A-=1}



if(Cycle == 0){
    T = 1
    }
if(Cycle == 1){
    T = 2
    }
    if(Cycle == 2){
    T = 3
    }
        if(Cycle == 3){
    T = 4
    }
            if(Cycle == 4){
    T = 5
    }
             if(Cycle == 5){
    T = 6
    }
                 if(Cycle == 6){
    T = 7
    }




if(owner():aimEntity()&owner():aimPos():distance(owner():pos())<Di){
      holoColor(1,vec(1,255,1))    
}else{
    holoColor(1,vec(255,1,1))
}
}


if(changed(owner():keyUse()) & owner():keyUse()){Cycle=Cycle-1}
if(changed(owner():keyReload()) & owner():keyReload()){Cycle=Cycle+1}
    

if(T==1){
    print(_HUD_PRINTCENTER,"Grass")
}
if(T==2){
    print(_HUD_PRINTCENTER,"Wood")
}
if(T==3){
    print(_HUD_PRINTCENTER,"Stone")
}
if(T==4){
    print(_HUD_PRINTCENTER,"Glass")
}
if(T==5){
    print(_HUD_PRINTCENTER,"Cobblestone")
}
if(T==5){
    print(_HUD_PRINTCENTER,"Cobblestone")
}
if(T==6){
    print(_HUD_PRINTCENTER,"Brick")
}
if(T==7){
    print(_HUD_PRINTCENTER,"Metal")
}
if(T==0){
    print(_HUD_PRINTCENTER,"THIS IS A NON EXISTANT BLOCK")
}

if(T>7){
    print(_HUD_PRINTCENTER,"This Block Does not exist yet, Please go back down.")
}


Ents[73,entity] = Crate2
Ents2[73,entity] = Crate


