onEvent('block.right_click', e => {
  const NORTH = Facing.north
  const WEST = Facing.west
  const SOUTH = Facing.south
  const EAST = Facing.east
  const placedBlock = e.getBlock()

  //check full ultimate energy cube
  function checkUEC(targetBlock) {
    if (targetBlock.getId().equals('mekanism:ultimate_energy_cube')) {
      if (targetBlock.getEntityData().EnergyContainers[0].stored == 4096000000) {
        return true
      }
    }
    return false
  }

  function blockPosition(block) {
    return `${block.getX()} ${block.getY()} ${block.getZ()} ${block.getX()} ${block.getY()} ${block.getZ()}`
  }

  if (e.entity.isPlayer() && e.entity.isCrouching()) {
    let heldItem = e.entity.getHeldItem(MAIN_HAND).getId()
    if (placedBlock.getId().equals('mekanism:creative_energy_cube')) {
      if (heldItem.equals('kubejs:atm_star')) {
        if (
          placedBlock.offset(SOUTH, 1).getId().equals('mekanism:ultimate_induction_provider') &&
          placedBlock.offset(NORTH, 1).getId().equals('mekanism:ultimate_induction_provider') &&
          checkUEC(placedBlock.offset(NORTH, 2)) &&
          checkUEC(placedBlock.offset(SOUTH, 2))
        ) {
          e.entity.getMainHandItem().count--
          let creativeCubeData = placedBlock.getEntityData()
          creativeCubeData.EnergyContainers.push({ Container: 0, stored: "18446744073709551615.9999" })
          placedBlock.getEntityData().putAll(creativeCubeData)
          placedBlock.offset(SOUTH, 2).set(`mekanism:ultimate_energy_cube{mekData:{}}`)
          placedBlock.offset(NORTH, 2).set(`mekanism:ultimate_energy_cube{mekData:{}}`)

          e.server.runCommand('/title @a title {"text":"Cube filled!","color":"green"}')

        } else if (
          placedBlock.offset(EAST, 1).getId().equals('mekanism:ultimate_induction_provider') &&
          placedBlock.offset(WEST, 1).getId().equals('mekanism:ultimate_induction_provider') &&
          checkUEC(placedBlock.offset(EAST, 2)) &&
          checkUEC(placedBlock.offset(WEST, 2))
        ) {
          e.entity.getMainHandItem().count--
          let creativeCubeData = placedBlock.getEntityData()
          creativeCubeData.EnergyContainers.push({ Container: 0, stored: "18446744073709551615.9999" })
          placedBlock.getEntityData().putAll(creativeCubeData)
          placedBlock.offset(WEST, 2).set(`mekanism:ultimate_energy_cube{mekData:{}}`)
          placedBlock.offset(EAST, 2).set(`mekanism:ultimate_energy_cube{mekData:{}}`)

          e.server.runCommand('/title @a title {"text":"Cube filled!","color":"green"}')
        } else {
          e.server.runCommand('/title @a title {"text":"Block formation is incorrect!","color":"dark_red"}')
        }
      }
    }
  }
})