@name PotDrop
@inputs AMT
@outputs Eject
@persist Ent:entity DropPos:vector Return:vector ReturnAng:angle
@persist CurSpin CurDrop CurStage
if (first()) {
    DropPos=gTable("drop")["Pos",vector]
    Ent=entity():isWeldedTo()
    entity():createWire(Ent,"AMT","StoredAmount")
    Ent:createWire(entity(),"SpawnAmount","Eject")
    entity():setAlpha(0)
    Return=Ent:pos()
    ReturnAng=Ent:angles()
}
if (changed(AMT)) {
    if (AMT) {
        Ent:setPos(DropPos)
        Ent:setAng(ang(0,0,180))
        Eject=AMT
        timer("na",10)
    } elseif (!first()) {
        Ent:setPos(Return)
        Ent:setAng(ReturnAng)
    }
}
runOnTick(1)
CurSpin++
if (CurStage) {
    CurDrop+=(5-CurDrop)/60
    if (CurDrop>4.5) {CurStage=0}
} else {
    CurDrop-=(CurDrop)/120
    if (CurDrop<2.5) {CurStage=1}
}
    
if (AMT<1) {
    Ent:setAng(ReturnAng+ang(0,CurSpin,0))
    Ent:setPos(Return+vec(0,0,CurDrop))
}
if (clk("na")) {Eject=0}
