void ZVoxelExtension_MiningRobot_xr1::Robot_Move( ZVector3L * Pos, ZGame * GameEnv )
{
  ZVoxelWorld * World = GameEnv->World;
  UShort VoxelType, VoxelType2;
  ULong LoopCount, Loop;
  ZVector3L NewPos;
  bool Redo;


  if (State != 5)
  {
    if ( SkipCounter < CycleSkip ) { SkipCounter++; return; }
    SkipCounter = 0;
  }

  LoopCount = 1;
  if (CycleSkip<0) LoopCount = - CycleSkip;
  for (Loop = 0; Loop<LoopCount; Loop++)
  do
  {
    Redo = false;
    switch (State)
    {
      case 0: break;

      case 1: // Going Down
              if (Mine_Count.y <1) {State = 4; Mine_Count.y = Mine_InitialCount.y; Redo = true;  break; }
              NewPos = *Pos; NewPos.y -= 1;
              VoxelType = World->GetVoxel(NewPos.x, NewPos.y , NewPos.z );
              if (VoxelType == 655535) break;
              if (VoxelType!=0)
              {
                if (GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->BvProp_XrRobotPickMinLevel > RobotLevel) break;
                if (!StoreBlocks(VoxelType, 1)) break;
              }
              World->MoveVoxel_Sm( Pos->x , Pos->y, Pos->z , NewPos.x, NewPos.y, NewPos.z, 0, ZVoxelSector::CHANGE_UNIMPORTANT);
              *Pos = NewPos;
              Mine_Count.x = Mine_InitialCount.x;
              Mine_Count.z = Mine_InitialCount.z;
              Mine_Count.y --;
              State = 2;
              break;
      case 2: // Going x+
              if (Mine_Count.x <= 1) {State = 3; Dir.x = -Dir.x; Redo = true; break;}
              NewPos = *Pos; NewPos.x += Dir.x;
              VoxelType = World->GetVoxel(NewPos.x, NewPos.y , NewPos.z );
              if (VoxelType == 655535) break;
              if (VoxelType!=0)
              {
                if (GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->BvProp_XrRobotPickMinLevel > RobotLevel) break;
                if (!StoreBlocks(VoxelType, 1)) break;
              }
              World->MoveVoxel_Sm( Pos->x , Pos->y, Pos->z , NewPos.x, NewPos.y, NewPos.z, 0, ZVoxelSector::CHANGE_UNIMPORTANT);
              *Pos = NewPos;
              Mine_Count.x--;
              break;
      case 3: // Going z+
              if (Mine_Count.z <= 1) {State = 1; Dir.z = -Dir.z; Redo = true; break;}
              NewPos = *Pos; NewPos.z += Dir.z;
              VoxelType = World->GetVoxel(NewPos.x, NewPos.y , NewPos.z );
              if (VoxelType == 655535) break;
              if (VoxelType!=0)
              {
                if (GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->BvProp_XrRobotPickMinLevel > RobotLevel) break;
                if (!StoreBlocks(VoxelType, 1)) break;
              }
              World->MoveVoxel_Sm( Pos->x , Pos->y, Pos->z , NewPos.x, NewPos.y, NewPos.z, 0, ZVoxelSector::CHANGE_UNIMPORTANT);
              *Pos = NewPos;
              Mine_Count.z--;
              Mine_Count.x = Mine_InitialCount.x;
              State = 2;
              break;
      case 4: // Going UP to the storage.
              if (Mine_Count.y < 1)
              {
                VoxelLocation Loc;
                World->GetVoxelLocation( &Loc, Pos->x, Pos->y,Pos->z);
                Loc.Sector->Data[Loc.Offset] = 159;
                Loc.Sector->Flag_Render_Dirty = true;
                //Loc.Sector->Flag_Void_Regular = false;
                //Loc.Sector->Flag_Void_Transparent = false;
                State = 5; break;
              }
              NewPos = *Pos; NewPos.y += 1;
              VoxelType = World->GetVoxel(NewPos.x, NewPos.y , NewPos.z );
              if (VoxelType == 655535) break;
              if (VoxelType!=0)
              {
                if (GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->BvProp_XrRobotPickMinLevel > RobotLevel) break;
                if (!StoreBlocks(VoxelType, 1)) break;
              }
              World->MoveVoxel_Sm( Pos->x , Pos->y, Pos->z , NewPos.x, NewPos.y, NewPos.z, 0, ZVoxelSector::CHANGE_UNIMPORTANT);
              *Pos = NewPos;
              Mine_Count.y--;
              break;
      case 5: // World->SetVoxel_WithCullingUpdate(Pos->x, Pos->y,Pos->z, 0, true, true, 0); break;
              // Putting data into storage.
              {
                VoxelLocation Loc;
                ULong Slot;
                if (!World->GetVoxelLocation(&Loc, StorageLocation.x, StorageLocation.y, StorageLocation.z)) break;
                VoxelType = Loc.Sector->Data[Loc.Offset];
                if (!GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->Is_Interface_PushBlock) { State = 6; break; }
                if ( ((ULong)-1) != (Slot = FindFirstUsedBlock()))
                {
                  if (!GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->Interface_PushBlock_Push(&Loc, this->VoxelType[Slot], 1)) break;
                  VoxelQuantity[Slot] --;
                  if ( ! VoxelQuantity[Slot] ) this->VoxelType[Slot]=0;
                }
                else
                {
                  switch (RobotLevel)
                  {
                    default:
                    case 0:
                    case 1: VoxelType2 = 153; break;
                    case 2: VoxelType2 = 154; break;
                    case 3: VoxelType2 = 155; break;
                    case 4: VoxelType2 = 156; break;
                    case 5: VoxelType2 = 157; break;
                    case 6: VoxelType2 = 158; break;
                  }
                  if (!GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->Interface_PushBlock_Push(&Loc, VoxelType2, 1)) break;
                  World->SetVoxel_WithCullingUpdate(Pos->x, Pos->y,Pos->z, 0, ZVoxelSector::CHANGE_UNIMPORTANT, true, 0);
                  // § State = 32;
                  return;
                }
              }
              break;
      case 6:
              {
                ULong i, Slot;
                ZVector3L NewLocation;

                for (i=0;i<6;i++)
                {
                  NewLocation.x = Pos->x + ZVoxelReactor::xbp6_nc[i].x; NewLocation.y = Pos->y + ZVoxelReactor::xbp6_nc[i].y; NewLocation.z = Pos->z + ZVoxelReactor::xbp6_nc[i].z;

                  VoxelType = World->GetVoxel(&NewLocation);
                  if (GameEnv->VoxelTypeManager.VoxelTable[VoxelType]->Is_Interface_PushBlock)
                  {
                    // Found a new location to push our stuff
                    StorageLocation = NewLocation;
                    State = 5;
                    break;
                  }
                }
                // Nobody want our blocks ? So, wait someone to empty it then transform to the original state.
                if ( ((ULong)-1) == (Slot = FindFirstUsedBlock()))
                {
                  switch (RobotLevel)
                  {
                    default:
                    case 0:
                    case 1: VoxelType = 153; break;
                    case 2: VoxelType = 154; break;
                    case 3: VoxelType = 155; break;
                    case 4: VoxelType = 156; break;
                    case 5: VoxelType = 157; break;
                    case 6: VoxelType = 158; break;
                  }
                  World->SetVoxel_WithCullingUpdate(Pos->x, Pos->y,Pos->z, VoxelType, true, true, 0);
                }

              }
              break;

      default: break;
    }
  } while (Redo);

}
ULong ZVoxelType_WirelessTransmitter::Interface_PushBlock_Push( ZVoxelLocation * DestLocation, UShort VoxelType, ULong Count )
{
  ZVoxelExtension_WirelessTransmitter * Ext;
  ZVoxelExtension_WirelessTransmitter::DestPoint Dp;
  ULong PlacedCount;
  ZVoxelLocation Loc;
  ZVoxelWorld * World;
  UShort Voxel;
  ZVector3L NewLocation;

  // Get Extension

  Ext = (ZVoxelExtension_WirelessTransmitter *)DestLocation->Sector->OtherInfos[DestLocation->Offset];
  if (!Ext) return (0);

  // Get
  ZMemSize PntCount = Ext->GetConsummerCount();
  if (Ext->NextUsed>=PntCount) Ext->NextUsed = 0;
  PlacedCount = 0;

  World = GameEnv->World;
  for (ZMemSize i = 0; i<PntCount && Count; i++)
  {
    // Get Next Endpoint coordinates

    if (!Ext->GetConsummerInfo(Ext->NextUsed++, Dp)) return(PlacedCount);
    if (Ext->NextUsed>=PntCount) Ext->NextUsed = 0;

    // Get Voxel for EndPoint
    if (World->GetVoxelLocation(&Loc,&Dp.Location))
    {
      Voxel = Loc.Sector->Data[Loc.Offset];

      // If it isn't an endpoint voxel, remove it from list and abort.

      if (Voxel!=255 && Voxel!=65535) { Ext->RemoveConsummer(&Dp.Location); return(PlacedCount); }

      // Look voxels around endpoint in order to find input interface or a materializer.

      for (ULong Dir=0; Dir<6;Dir++)
      {
         NewLocation = Dp.Location + ZVoxelWorld::ProxLoc[Dir];

         // Look at these locations around

         if (World->GetVoxelLocation(&Loc, &NewLocation))
         {
           Voxel = Loc.Sector->Data[Loc.Offset];

           // If it's a bloc with an input interface.

           if (VoxelTypeManager->VoxelTable[Voxel]->Is_Interface_PushBlock)
           {
             ULong Cnt = VoxelTypeManager->VoxelTable[Voxel]->Interface_PushBlock_Push(&Loc, VoxelType, Count);
             PlacedCount += Cnt;
             Count -= Cnt;
             if (!Count) return(PlacedCount);
           }
           // Or a Materializer directly at output...
           else if (Voxel==248 || Voxel == 98)
           {
             NewLocation+= ZVoxelWorld::ProxLoc[Dir];
             if (World->GetVoxelLocation(&Loc, &NewLocation))
               if (Loc.Sector->Data[Loc.Offset]==0)
                 if (GameEnv->World->SetVoxel_WithCullingUpdate(NewLocation.x, NewLocation.y,NewLocation.z, VoxelType, ZVoxelSector::CHANGE_CRITICAL ,true))
                 {
                   PlacedCount++;
                   Count--;
                 }
             if (!Count) return(PlacedCount);
           }

         }

      }


    }

  }

  return(0);
}